青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

oyjpArt ACM/ICPC算法程序設計空間

// I am new in programming, welcome to my blog
I am oyjpart(alpc12, 四城)
posts - 224, comments - 694, trackbacks - 0, articles - 6

Increasing Speed Limits

Problem

You were driving along a highway when you got caught by the road police for speeding. It turns out that they've been following you, and they were amazed by the fact that you were accelerating the whole time without using the brakes! And now you desperately need an excuse to explain that.

You've decided that it would be reasonable to say "all the speed limit signs I saw were in increasing order, that's why I've been accelerating". The police officer laughs in reply, and tells you all the signs that are placed along the segment of highway you drove, and says that's unlikely that you were so lucky just to see some part of these signs that were in increasing order.

Now you need to estimate that likelihood, or, in other words, find out how many different subsequences of the given sequence are strictly increasing. The empty subsequence does not count since that would imply you didn't look at any speed limits signs at all!

For example, (1, 2, 5) is an increasing subsequence of (1, 4, 2, 3, 5, 5), and we count it twice because there are two ways to select (1, 2, 5) from the list.

Input

The first line of input gives the number of cases, N. N test cases follow. The first line of each case contains n, m, X, Y and Z each separated by a space. n will be the length of the sequence of speed limits. m will be the length of the generating array A. The next m lines will contain the m elements of A, one integer per line (from A[0] to A[m-1]).

Using A, X, Y and Z, the following pseudocode will print the speed limit sequence in order. mod indicates the remainder operation.

for i = 0 to n-1
print A[i mod m]
A[i mod m] = (X * A[i mod m] + Y * (i + 1)) mod Z

Note: The way that the input is generated has nothing to do with the intended solution and exists solely to keep the size of the input files low.

Output

For each test case you should output one line containing "Case #T: S" (quotes for clarity) where T is the number of the test case and S is the number of non-empty increasing subsequences mod 1 000 000 007.

Limits

1 ≤ N ≤ 20
1 ≤ m ≤ 100
0 ≤ X ≤ 109
0 ≤ Y ≤ 109
1 ≤ Z ≤ 109
0 ≤ A[i] < Z

Small dataset

1 ≤ mn ≤ 1000

Large dataset

1 ≤ mn ≤ 500 000

Sample


Input
 

Output
 
2
5 5 0 0 5
1
2
1
2
3
6 2 2 1000000000 6
1
2

Case #1: 15
Case #2: 13

The sequence of speed limit signs for case 2 should be 1, 2, 0, 0, 0, 4.

沒趕上Round1A 郁悶。
Round1C Solve1和2,3的large不會做,菜。Rank好像是60多,能過。

賽后學習了下,也不算太難。
本來DP方程是這樣的
for(i = 0; i < n; ++i) {
 for(j = 0; j < i; ++j) {
  if(A[j] < A[i]) {
    dp[i] += dp[j];
  }
 }
}
如果對A排序并且離散化,則變成了
for(i=0; i < n; ++i) {
  for(j = 0; j < A[i]; ++j) {
   dp[A[i]] += dp[j];
  }
}


大家注意看,內循環其實是一個區間求和。那么對于這種求和,線段樹只可以做到NlogN的。
記得以前寫過一道題的解題報告,是類似的。
pku1769 點樹解決塊查詢點操作

下面是代碼:(solve2函數是一個n^2的DP,偶水small input用的)
// Solution by alpc12  
#include 
<stdio.h>
#include 
<cassert>
#include 
<map>
#include 
<algorithm>
using namespace std;

const int M = 100;
const int N = 500010;
const int MOD = 1000000007;

typedef 
long long LL;

int n, m, X, Y, Z;
int A[N], S[N];
int st[1048576];
int upperbound = 524288;
int dp[N];

void generate() {
    
int i;
    
for(i = 0; i < n; ++i) {
        S[i] 
= A[i%m];
        A[i
%m] = ((LL)X*A[i%m]+(LL)Y*(i+1))%Z;
    }
    
for(i = 0; i < n; ++i) {
        A[i] 
= S[i];  
    }
}

int get(int x, int y) { // 左閉右開
    x += upperbound, y += upperbound;
    
int ans = 0;
    
while(x + 1 < y) {
        
if(x&1) { // x是右子樹 
            ans = (ans + st[x]) % MOD;
            x
++;
        }
        
if(y&1) { // y是右子樹
            y--;
            ans 
= (ans + st[y]) % MOD;
        }
        x 
>>= 1;
        y 
>>= 1;
    }
    
if(x < y) 
        ans 
= (ans + st[x]) % MOD;
    
return ans;
}

void ins(int x, int a) {
    x 
+= upperbound;
    
while(x > 0) {
        st[x] 
= (st[x] + a) % MOD;
        x 
>>= 1;
    }
}

void solve() {
    memset(st, 
0sizeof(st));
    sort(S, S 
+ n);
    map
<intint> mm;
    
int i, j = 0, ans = 0;
    
for(i = 0; i < n; ++i) {
        
if(!mm.count(S[i])) {
            mm[S[i]] 
= ++j;
        }
    }
    ins(
01);
    
for(i = 0; i < n; ++i) {
        A[i] 
= mm[A[i]];
        
int sum = get(0, A[i]);
        ans 
= (ans + sum) % MOD;
        ins(A[i], sum);
    }
    printf(
"%d\n", ans);
}

void solve2() {
    
int i, j, k;
    
for(i = 0; i < n; ++i) dp[i] = 1;
    
for(i = 1; i < n; ++i) {
        
for(j = 0; j < i; ++j) {
            
if(S[j] < S[i]) {
                dp[i] 
+= dp[j];
                dp[i] 
%= MOD;
            }
        }
    }
    LL sum 
= 0;
    
for(i = 0; i < n; ++i) {
        sum 
+= dp[i];
        sum 
%= MOD;
    }
    printf(
"%I64d\n", sum);
}

int main()
{
//    freopen("C-large.in", "r", stdin);
//    freopen("C-large.txt", "w", stdout);

    
int ntc, i, j, k, tc=0;
    scanf(
"%d"&ntc);
    
while(ntc--) {
        printf(
"Case #%d: "++tc);
        scanf(
"%d%d%d%d%d"&n, &m, &X, &Y, &Z);
        
for(i = 0; i < m; ++i) scanf("%d", A+i);
        generate();
//        solve2();
        solve();
    }
    
return 0;
}

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产一区二区三区日韩欧美| 国产一区二区三区不卡在线观看 | 国产精品99久久久久久久女警| 欧美成ee人免费视频| 亚洲二区免费| 亚洲国产午夜| 欧美肥婆在线| 亚洲另类一区二区| 一区二区三区不卡视频在线观看| 欧美三级网址| 久久爱www久久做| 久久亚洲精品一区二区| 亚洲乱码国产乱码精品精可以看| 亚洲美女色禁图| 国产目拍亚洲精品99久久精品| 久久久久久尹人网香蕉| 欧美成人免费小视频| 亚洲在线观看免费| 欧美中文字幕不卡| 99在线精品视频| 亚洲欧美区自拍先锋| 亚洲第一精品福利| 中文日韩在线视频| 激情欧美一区二区三区在线观看| 亚洲国产成人久久综合| 国产精品久久久久久久久果冻传媒| 久久久久9999亚洲精品| 欧美国产欧美综合| 久久精品论坛| 欧美日韩在线一二三| 免费不卡中文字幕视频| 国产精品99一区| 亚洲第一伊人| 国产一区二区丝袜高跟鞋图片| 亚洲国产综合91精品麻豆| 国产欧美一区二区精品忘忧草| 欧美激情中文不卡| 国产主播一区二区三区| 亚洲精品专区| 亚洲国产高清一区二区三区| 亚洲一区二区三区中文字幕在线 | 91久久视频| 午夜精品久久久久久久99黑人| 亚洲日本中文字幕| 久久av在线看| 性做久久久久久免费观看欧美| 免费在线成人| 久久综合网络一区二区| 国产精品乱码一区二三区小蝌蚪| 亚洲电影免费观看高清完整版在线观看 | 欧美日韩一区二区在线观看 | 午夜精品久久99蜜桃的功能介绍| 蜜臀av在线播放一区二区三区| 欧美在线免费视屏| 国产精品成人免费视频 | 欧美激情aaaa| 一区视频在线| 久久久噜噜噜久久中文字免| 欧美亚洲网站| 国产精品视频久久| 亚洲无玛一区| 亚洲欧美日韩国产一区| 欧美系列亚洲系列| 99热精品在线观看| 亚洲资源在线观看| 欧美日韩在线不卡| 一本久久综合亚洲鲁鲁五月天| 一二三四社区欧美黄| 欧美精品久久一区二区| 亚洲黄色免费| 一区二区三区**美女毛片| 欧美久久久久久久久| 亚洲激情第一页| 亚洲美女在线看| 欧美日韩精品在线播放| 日韩午夜在线视频| 亚洲欧美日韩综合| 国产精品午夜春色av| 午夜一区二区三区在线观看| 久久疯狂做爰流白浆xx| 国外成人在线视频| 免费欧美在线| 亚洲精品一区二区三区不| 亚洲一区二区三区视频播放| 欧美天堂在线观看| 亚洲欧美激情一区| 蜜桃视频一区| 91久久线看在观草草青青| 欧美精品九九| 亚洲午夜在线| 麻豆精品传媒视频| 一本色道久久88综合日韩精品| 欧美日韩亚洲91| 性欧美18~19sex高清播放| 久久天天躁狠狠躁夜夜av| 亚洲国产精品成人va在线观看| 欧美日本免费| 欧美一级一区| 亚洲精品乱码久久久久久| 性久久久久久久久久久久| 黄色成人在线网站| 欧美日韩免费| 欧美制服第一页| 亚洲麻豆一区| 久久久久高清| 在线视频亚洲欧美| 影音先锋久久| 国产精品久久二区| 久久婷婷麻豆| 亚洲在线电影| 亚洲人屁股眼子交8| 久久福利电影| 亚洲一区二区黄| 亚洲成人资源| 国产精品一区二区在线观看网站 | 欧美大胆a视频| 欧美亚洲免费电影| 日韩一级在线观看| 欧美国产综合视频| 久久久久久一区二区| 制服丝袜亚洲播放| 亚洲国产视频一区| 国产亚洲欧洲997久久综合| 欧美精品一区二区三区久久久竹菊| 欧美一级精品大片| 亚洲视频一区二区| 亚洲人被黑人高潮完整版| 欧美va天堂va视频va在线| 欧美制服丝袜| 欧美亚洲尤物久久| 亚洲一级一区| 亚洲午夜久久久久久尤物| 日韩亚洲一区在线播放| 亚洲福利国产| 亚洲第一黄色网| 黄色影院成人| 国产主播一区二区三区| 国产精品免费久久久久久| 欧美视频一区二区三区| 欧美日韩播放| 欧美日韩免费高清| 欧美乱大交xxxxx| 欧美日韩国产123区| 欧美激情免费在线| 欧美黄色免费网站| 欧美精品在线观看91| 欧美日本中文字幕| 欧美视频1区| 国产精品久久久久久av下载红粉| 欧美日韩直播| 国产精品成人免费精品自在线观看| 欧美三级午夜理伦三级中文幕 | 女人香蕉久久**毛片精品| 美女成人午夜| 欧美激情欧美狂野欧美精品| 欧美激情中文字幕一区二区| 欧美精品在线一区二区三区| 欧美日韩国产综合视频在线观看| 欧美视频在线视频| 国产精品日韩在线观看| 国产亚洲精品久久久久动| 禁久久精品乱码| 91久久精品美女| 亚洲视屏一区| 久久国产精品72免费观看| 欧美a级片网| 亚洲精品美女免费| 亚洲一区激情| 久久青青草综合| 欧美日韩亚洲一区二区三区四区 | 欧美大尺度在线| 欧美日精品一区视频| 国产区精品视频| 亚洲人成网站色ww在线| 亚洲综合久久久久| 久久久久久久尹人综合网亚洲| 欧美激情第3页| 亚洲视频第一页| 久久青草福利网站| 欧美三级日本三级少妇99| 国产一区视频网站| 日韩一区二区久久| 久久精品一区蜜桃臀影院| 欧美激情精品久久久久久免费印度 | 免费不卡在线视频| 99av国产精品欲麻豆| 久久成人羞羞网站| 欧美视频在线观看一区| 尤物精品在线| 欧美亚洲免费电影| 亚洲精品小视频在线观看| 欧美在线关看| 国产精品爱久久久久久久| 亚洲国产成人精品女人久久久| 午夜精品av| 亚洲欧洲日本专区| 久久婷婷国产综合国色天香| 国产精品久久久免费| 亚洲乱亚洲高清| 蜜臀久久99精品久久久久久9|