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

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>
            久热精品视频在线免费观看| 亚洲宅男天堂在线观看无病毒| 免费观看久久久4p| 激情久久五月天| 牛夜精品久久久久久久99黑人| 久久女同精品一区二区| 亚洲国产婷婷香蕉久久久久久99| 亚洲高清av| 欧美母乳在线| 久久av在线看| 猛男gaygay欧美视频| 一区二区av在线| 午夜精品久久久久久久99樱桃 | 欧美日韩一区二区三区免费看| 亚洲午夜在线观看| 久久精品欧美日韩| 99国产精品久久久久老师| 亚洲午夜精品网| 永久免费视频成人| 99日韩精品| 黄色在线成人| 99精品国产热久久91蜜凸| 国产一区av在线| 国产午夜精品美女毛片视频| 欧美18av| 国产精品网站在线播放| 欧美黄色影院| 国产精品一区二区三区久久| 欧美韩国一区| 国产视频在线观看一区| 亚洲日本成人网| 国产一区美女| 中文欧美字幕免费| 亚洲靠逼com| 久久久噜噜噜| 久久福利影视| 国产精品成人在线| 91久久在线观看| 国内精品免费午夜毛片| 一区二区福利| 日韩一级欧洲| 女同性一区二区三区人了人一| 欧美一区日韩一区| 欧美视频国产精品| 亚洲精品欧美日韩| 亚洲乱码精品一二三四区日韩在线| 午夜亚洲福利在线老司机| 一区二区久久| 欧美激情1区| 亚洲第一级黄色片| 亚洲第一中文字幕在线观看| 午夜精品视频在线观看| 午夜精品久久久久久久99黑人| 欧美日韩不卡在线| 亚洲精品欧洲| 99亚洲精品| 欧美日本精品在线| 亚洲区一区二| av成人国产| 欧美精品大片| 亚洲精品一区中文| 一区二区三区回区在观看免费视频| 欧美高清不卡在线| 亚洲人成小说网站色在线| 日韩视频三区| 欧美日韩综合久久| 亚洲一区日韩在线| 久久se精品一区精品二区| 国产日韩欧美一二三区| 欧美在线你懂的| 久久视频一区| 亚洲日本va在线观看| 欧美暴力喷水在线| 亚洲免费av观看| 亚洲欧美日韩精品综合在线观看 | 亚洲视频欧美在线| 性欧美1819性猛交| 精品福利免费观看| 老司机免费视频一区二区| 亚洲韩国一区二区三区| 中文精品视频一区二区在线观看| 欧美日在线观看| 欧美在线播放高清精品| 欧美成人有码| 亚洲午夜av电影| 黄色欧美日韩| 亚洲自拍16p| 久久久久久久成人| 91久久国产精品91久久性色| 欧美美女bbbb| 香蕉成人久久| 亚洲国产精品久久久久秋霞不卡 | 亚洲国产精品t66y| 亚洲女女女同性video| 国产在线拍揄自揄视频不卡99| 老司机免费视频一区二区| 一本一本大道香蕉久在线精品| 久久精品日产第一区二区| 亚洲激情在线观看| 国产精品一区二区在线观看不卡| 久久经典综合| 一区二区三区视频在线播放| 久久久久久久久一区二区| 亚洲最新中文字幕| 好吊色欧美一区二区三区视频| 欧美理论片在线观看| 亚洲欧美日韩国产成人精品影院| 欧美日韩国产综合新一区| 宅男噜噜噜66国产日韩在线观看| 欧美一区国产在线| 99re成人精品视频| 精品1区2区3区4区| 欧美丝袜一区二区三区| 免费高清在线一区| 欧美一区二区三区的| 日韩性生活视频| 亚洲国产成人av| 久久久久亚洲综合| 先锋影音久久| 亚洲自拍16p| 一本色道久久88亚洲综合88| 伊人成人在线视频| 国产日本亚洲高清| 国产精品第一区| 欧美精品福利在线| 免费观看30秒视频久久| 久久精品国产一区二区三区免费看 | 国产精品vip| 亚洲欧美国产日韩中文字幕| 又紧又大又爽精品一区二区| 欧美午夜影院| 欧美精品一区二区三区蜜桃| 久久久蜜桃精品| 久久国产精品99国产精| 久久国产加勒比精品无码| 欧美一区二区三区视频免费播放| 在线午夜精品自拍| 一区二区三区av| 亚洲视频导航| 亚洲一区二区高清视频| 亚洲视频综合在线| 亚洲午夜一二三区视频| 中日韩男男gay无套| 一区二区三区欧美在线| 亚洲小视频在线| 亚洲欧美日韩另类精品一区二区三区| 一区二区三欧美| 亚洲综合国产精品| 欧美在线黄色| 久久久久国产精品人| 久久亚洲高清| 欧美精品一区二区在线观看| 久久国产精品电影| 欧美高清视频| 欧美成人午夜影院| 亚洲欧洲日本在线| 一区二区三区高清在线| 亚洲影院免费观看| 久久精品人人做人人爽电影蜜月| 久久激情综合网| 欧美va亚洲va香蕉在线| 欧美久色视频| 国产精品在线看| 在线免费高清一区二区三区| 亚洲精品久久久久久一区二区 | 欧美大片免费久久精品三p | 午夜宅男久久久| 久久免费视频网站| 欧美日韩国产经典色站一区二区三区 | 久久久噜噜噜久久| 性娇小13――14欧美| 午夜在线精品偷拍| 欧美风情在线观看| 国产精品久久久免费| 在线精品亚洲| 亚洲欧美日韩一区二区三区在线观看 | 国产精品第三页| 伊人精品在线| 亚洲综合精品四区| 欧美激情一区二区三区在线视频观看| 亚洲精品综合久久中文字幕| 羞羞答答国产精品www一本| 欧美ed2k| 国产亚洲精品久久久久婷婷瑜伽| 午夜激情久久久| 欧美国产日韩一二三区| 国产欧美日韩综合| 亚洲视频免费| 欧美激情影音先锋| 免费视频一区| 一区二区av| 亚洲高清成人| 日韩一级免费| 久久综合中文色婷婷| 亚洲午夜视频在线观看| 米奇777在线欧美播放| 国产欧美在线| 亚洲一区影音先锋| 亚洲人成久久| 免费亚洲电影|