【HDOJ6319】Ascending Rating(单调队列)

题意:

思路:

倒着来是因为这样可以维护每一个当过最大值的数,而正着不行

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<string>
 4 #include<cmath>
 5 #include<iostream>
 6 #include<algorithm>
 7 #include<map>
 8 #include<set>
 9 #include<queue>
10 #include<vector>
11 using namespace std;
12 typedef long long ll;
13 typedef unsigned int uint;
14 typedef unsigned long long ull;
15 typedef pair<int,int> PII;
16 typedef vector<int> VI;
17 #define fi first
18 #define se second 
19 #define MP make_pair
20 #define N   11000000
21 
22 
23  
24 ll a[N];
25 int q[N];
26 
27 int read()
28 { 
29    int v=0,f=1;
30    char c=getchar();
31    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
32    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
33    return v*f;
34 }
35 
36  
37 int main()
38 {
39     
40     int cas;
41     scanf("%d",&cas);
42     while(cas--)
43     {
44         int n,m,k;
45         ll P,Q,R,MOD;
46         scanf("%d%d%d%lld%lld%lld%lld",&n,&m,&k,&P,&Q,&R,&MOD);
47         for(int i=1;i<=k;i++) scanf("%lld",&a[i]);
48         for(int i=k+1;i<=n;i++) a[i]=(a[i-1]*P+Q*i+R)%MOD;
49         int head=1,tail=0;
50         ll ans1=0,ans2=0; 
51         for(int i=n;i>=1;i--)
52         {
53             while((head<=tail)&&(a[q[tail]]<=a[i])) tail--;
54             q[++tail]=i;
55             if(i+m-1<=n)
56             {
57                 while(q[head]>=i+m) head++;
58                 ans1+=i^a[q[head]];
59                 ans2+=i^(tail-head+1);
60             }
61         }
62         printf("%lld %lld\n",ans1,ans2);
63     }
64 }

 

posted on 2018-08-04 21:44  myx12345  阅读(156)  评论(0编辑  收藏  举报

导航