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

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

// 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)其實是一個區(qū)間求和。那么對于這種求和,線段樹只可以做到NlogN的。
記得以前寫過一道題的解題報告,是類似的。
pku1769 點樹解決塊查詢點操作

下面是代碼:(solve2函數(shù)是一個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在线热播精品免费99热| 亚洲第一精品夜夜躁人人躁| 国产日韩欧美成人| 国产日产欧美a一级在线| 国产精品亚洲аv天堂网| 国产日韩精品一区二区三区| 国产小视频国产精品| 国产一区激情| 亚洲精品乱码久久久久久| 妖精视频成人观看www| 亚洲综合精品| 巨乳诱惑日韩免费av| 亚洲国产综合在线看不卡| 欧美成人69av| 一本色道久久88综合亚洲精品ⅰ| 午夜精品短视频| 免费欧美电影| 国产精品乱码| 亚洲丰满在线| 欧美一级在线播放| 亚洲国产一区二区在线| 午夜国产精品视频免费体验区| 久久一区视频| 国产精品亚洲片夜色在线| 亚洲经典三级| 久久精品夜夜夜夜久久| 亚洲免费观看视频| 久久久久久久综合狠狠综合| 欧美午夜精品理论片a级大开眼界 欧美午夜精品理论片a级按摩 | 国产一区二区av| 亚洲精品国产品国语在线app| 亚洲综合日本| 欧美激情性爽国产精品17p| 亚洲女同在线| 欧美日韩国产色视频| 91久久精品国产91性色| 久久九九热免费视频| 一本色道婷婷久久欧美| 女同性一区二区三区人了人一| 欧美午夜电影在线| 亚洲精品小视频在线观看| 欧美一区二区三区在| 亚洲人成网在线播放| 久久狠狠亚洲综合| 国产精品毛片va一区二区三区| 亚洲精品在线一区二区| 欧美成人午夜77777| 久久精品亚洲| 国语精品一区| 久久久99爱| 欧美在线一区二区| 国产午夜一区二区三区| 久久av在线看| 午夜一区不卡| 国内免费精品永久在线视频| 久久久久久亚洲精品杨幂换脸 | 欧美激情一区二区三区全黄| 久久久999精品免费| 国产一区二区观看| 久久久综合网| 久久久蜜臀国产一区二区| 国产午夜精品麻豆| 久久伊人精品天天| 久久综合给合久久狠狠色| 亚洲高清一区二| 亚洲国产人成综合网站| 欧美伦理影院| 亚洲午夜激情在线| 亚洲视频在线观看视频| 国产精品三上| 久久久国产91| 欧美 日韩 国产 一区| 日韩午夜在线播放| 正在播放欧美一区| 国产日韩高清一区二区三区在线| 久久久欧美精品| 男人的天堂成人在线| 亚洲最新视频在线| 亚洲欧美不卡| 亚洲国产日韩在线一区模特| 最新成人av在线| 国产免费成人| 欧美激情一区二区三区在线 | 在线日韩欧美视频| 亚洲与欧洲av电影| 国产美女诱惑一区二区| 久久久噜噜噜久久久| 裸体丰满少妇做受久久99精品| 亚洲毛片在线观看| 午夜精品剧场| 亚洲美女视频在线观看| 亚洲自拍电影| 亚洲美女视频在线免费观看| 亚洲视频免费在线观看| 亚久久调教视频| 国产欧美精品一区aⅴ影院| 久久久久久97三级| 欧美激情精品久久久久久| 亚洲欧美日韩国产综合| 久久综合久久美利坚合众国| 夜夜嗨av色综合久久久综合网| 亚洲欧美日韩系列| 99视频一区二区三区| 欧美亚洲综合网| 中日韩美女免费视频网址在线观看 | 欧美刺激性大交免费视频| 亚洲欧美日韩系列| 欧美岛国在线观看| 久久久久久久网站| 国产精品久久久久久久第一福利| 女女同性精品视频| 国产精品社区| 亚洲精品日韩在线观看| 伊人伊人伊人久久| 亚洲一级电影| 一区二区三区国产| 欧美激情二区三区| 亚洲第一网站免费视频| 国产欧美精品在线| 99在线热播精品免费| 亚洲六月丁香色婷婷综合久久| 久久se精品一区精品二区| 欧美伊人久久| 国产精品久久福利| 日韩视频―中文字幕| 99热这里只有精品8| 免费中文日韩| 欧美国产大片| 亚洲二区视频| 男人的天堂成人在线| 欧美激情国产日韩精品一区18| 国产午夜精品久久久久久久| 中文一区字幕| 午夜电影亚洲| 国产亚洲激情| 久久精品理论片| 久久影视精品| 亚洲电影成人| 欧美成人精品| 亚洲国产欧美一区二区三区同亚洲| 亚洲国产精品嫩草影院| 欧美激情综合五月色丁香小说| 亚洲黄页一区| 亚洲午夜在线视频| 国产精品亚洲精品| 久久激情五月激情| 欧美成人午夜激情在线| 亚洲精品国精品久久99热| 欧美激情 亚洲a∨综合| 日韩视频免费观看高清在线视频 | 亚洲欧美日韩一区二区| 国产嫩草一区二区三区在线观看| 亚洲欧美成人一区二区在线电影| 亚洲欧美综合一区| 国产一区二区欧美日韩| 在线观看不卡av| 欧美自拍偷拍| 欧美成熟视频| 亚洲天堂av高清| 国产精品乱子乱xxxx| 性8sex亚洲区入口| 欧美国产视频日韩| 亚洲色在线视频| 国模一区二区三区| 欧美精品日韩综合在线| 亚洲影院高清在线| 欧美成人精品h版在线观看| 亚洲日韩欧美视频一区| 国产精品丝袜久久久久久app| 久久久久se| 91久久精品国产91久久性色tv| 香蕉久久久久久久av网站| 亚洲电影毛片| 国产精品v欧美精品v日本精品动漫| 亚洲欧美激情精品一区二区| 欧美国产一区二区在线观看| 亚洲小视频在线| 亚洲第一精品在线| 国产精品久久久999| 欧美大尺度在线观看| 欧美在线观看视频在线| 亚洲精品久久| 女同一区二区| 欧美一区二区在线播放| 一区二区三区免费看| 亚洲国产婷婷| 国产一区二区三区四区三区四| 欧美日韩国产探花| 欧美mv日韩mv国产网站app| 亚洲欧美在线一区| 夜夜嗨av一区二区三区中文字幕| 久久尤物视频| 欧美中文在线视频| 亚洲一区二区3| 亚洲美女网站| 日韩视频中文字幕| 91久久久在线| 亚洲国产欧洲综合997久久| 激情久久一区|