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

oyjpArt ACM/ICPC算法程序設(shè)計(jì)空間

// 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多,能過。

賽后學(xué)習(xí)了下,也不算太難。
本來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];
  }
}


大家注意看,內(nèi)循環(huán)其實(shí)是一個(gè)區(qū)間求和。那么對于這種求和,線段樹只可以做到NlogN的。
記得以前寫過一道題的解題報(bào)告,是類似的。
pku1769 點(diǎn)樹解決塊查詢點(diǎn)操作

下面是代碼:(solve2函數(shù)是一個(gè)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>
            欧美精品一区二区三区蜜桃 | 一区二区三区在线免费视频| 欧美日韩另类综合| 欧美日韩另类丝袜其他| 欧美另类极品videosbest最新版本| 久久久久久一区二区| 久久伊人免费视频| 美女主播精品视频一二三四| 欧美成人午夜免费视在线看片| 裸体一区二区| 欧美一进一出视频| 欧美一区三区二区在线观看| 亚洲精品乱码久久久久久按摩观 | 国产综合av| 亚洲国产精品嫩草影院| 亚洲黄一区二区| 亚洲午夜国产一区99re久久 | 中文久久精品| 久久精品最新地址| 亚洲第一精品影视| 亚洲精品日韩精品| 午夜精品久久一牛影视| 老色鬼久久亚洲一区二区| 欧美久久视频| 国产一区二区三区在线观看免费 | 亚洲欧美日韩一区| 免费观看国产成人| 亚洲视频碰碰| 免费不卡亚洲欧美| 国产精品一区二区欧美| 亚洲国产一区在线| 欧美一区国产一区| 亚洲激情欧美激情| 欧美一区二区观看视频| 欧美夫妇交换俱乐部在线观看| 国产精品xxxxx| 亚洲欧洲另类| 久久影音先锋| 亚洲一区二区视频在线观看| 猛男gaygay欧美视频| 国产日韩在线看片| 亚洲综合首页| 亚洲黄一区二区三区| 久久久精品一品道一区| 国产精品丝袜白浆摸在线| av成人免费| 亚洲国产婷婷| 久久婷婷国产麻豆91天堂| 国产精自产拍久久久久久| 正在播放亚洲| 亚洲欧洲一区二区三区| 久久夜色精品国产欧美乱极品| 国产精品日韩精品| 亚洲欧美国产三级| 日韩一级黄色av| 欧美精品18+| 亚洲人体大胆视频| 亚洲第一视频网站| 免费成人av在线| 欧美专区在线播放| 一二三四社区欧美黄| 你懂的视频一区二区| 亚洲欧美在线观看| 国产精品永久免费视频| 亚洲自拍偷拍视频| 亚洲午夜激情在线| 国产精品国产三级国产aⅴ无密码| 日韩亚洲视频在线| 亚洲日本久久| 欧美日韩专区| 香蕉乱码成人久久天堂爱免费| 日韩亚洲国产欧美| 国产精品久久久久久影视| 亚洲欧美日本另类| 性做久久久久久| 国产免费成人av| 久久乐国产精品| 老司机免费视频一区二区| 91久久久在线| 日韩午夜av电影| 国产精品毛片在线| 久久国产精品毛片| 久久男人av资源网站| 亚洲精品久久| 亚洲影视在线播放| 国精品一区二区| 欧美韩日高清| 欧美视频在线观看| 久久亚洲影音av资源网| 欧美国产日韩a欧美在线观看| 一本色道久久综合亚洲精品高清| 亚洲视频在线观看网站| 好吊一区二区三区| 亚洲大片精品永久免费| 国产精品vip| 欧美aⅴ一区二区三区视频| 欧美韩日一区二区三区| 欧美在线观看www| 另类专区欧美制服同性| 亚洲视频在线免费观看| 久久精品日韩一区二区三区| 亚洲美女黄色| 欧美在线免费视屏| 亚洲私人影院在线观看| 欧美在线免费播放| 亚洲视频一区二区在线观看| 久久精品国产免费观看| 99视频精品全国免费| 欧美在线免费观看亚洲| 亚洲天堂成人| 欧美高清自拍一区| 久久久久久久高潮| 国产精品久久91| 欧美激情中文字幕一区二区| 国产精品久久久久久户外露出| 欧美成人第一页| 国产色产综合产在线视频| 日韩视频在线观看免费| 一区视频在线| 欧美一区成人| 亚洲欧美激情精品一区二区| 女人香蕉久久**毛片精品| 久久国产视频网| 亚洲视频在线看| 欧美高清不卡| 久久免费偷拍视频| 国产精品激情电影| 亚洲精品在线观看视频| 亚洲国产成人一区| 久久精品30| 久久精品欧洲| 国产日韩一区二区三区在线| 中文国产亚洲喷潮| 亚洲一级二级在线| 欧美高清在线精品一区| 欧美激情一区二区三级高清视频| 国产日韩精品一区二区浪潮av| 这里只有精品丝袜| 亚洲综合三区| 国产精品裸体一区二区三区| 日韩一级黄色av| 亚洲永久精品大片| 国产精品久久久久久久久借妻| 亚洲精品一区二区网址| 一区二区三区成人| 国产精品大片免费观看| 亚洲视频在线观看| 久久久精品视频成人| 国内精品久久久久久久果冻传媒 | 欧美主播一区二区三区美女 久久精品人 | 国产婷婷成人久久av免费高清| 亚洲无吗在线| 久久精品一二三区| 亚洲国产精品毛片| 欧美精品自拍| 亚洲视频一二| 久久久久久穴| 亚洲欧洲中文日韩久久av乱码| 欧美大尺度在线| 夜夜嗨av一区二区三区中文字幕 | 久久综合激情| 亚洲欧洲日本一区二区三区| 欧美剧在线观看| 亚洲午夜久久久久久尤物 | 午夜精品福利视频| 免费成人性网站| 中日韩美女免费视频网站在线观看 | 一本色道久久88亚洲综合88| 亚洲一区二区三区欧美| 国产欧美日韩免费| 老司机精品福利视频| 日韩视频精品在线观看| 欧美在线在线| 日韩一级在线| 国产午夜久久| 欧美日本一区二区视频在线观看| 一区二区成人精品| 欧美大香线蕉线伊人久久国产精品| 99日韩精品| 欧美与欧洲交xxxx免费观看 | 国产伪娘ts一区| 蜜臀av性久久久久蜜臀aⅴ四虎| 亚洲国产裸拍裸体视频在线观看乱了中文 | 亚洲一区在线免费| 免费看的黄色欧美网站| 亚洲香蕉成视频在线观看| 国产一区二区三区久久久| 欧美日本二区| 久久伊人免费视频| 亚洲欧美视频一区| 一本久道久久综合婷婷鲸鱼| 裸体素人女欧美日韩| 午夜精品国产| 在线综合+亚洲+欧美中文字幕| 国产在线拍偷自揄拍精品| 欧美午夜寂寞影院| 欧美精品日韩| 久久五月激情| 久久精品人人做人人爽| 亚洲欧美日韩精品在线|