BZOJ1012——[JSOI2008]最大数maxnumber

一个超水单调队列,也可以用线段树做,这里就贴单调队列的代码。


 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <cmath>
 5 #include <algorithm>
 6 using namespace std;
 7 const int maxn=2e5+5;
 8 int n,mod,x;
 9 int q[maxn],a[maxn],l,r,t,ct,cur;
10 char c;
11 
12 int main(){
13     ios::sync_with_stdio(false);
14     cin>>n>>mod;
15     for(int i=1;i<=n;++i){
16         cin>>c>>x;
17         if(c=='Q'){
18             cur=l;
19             while(cur<=r&&q[cur]<ct-x+1)cur++;
20             t=a[q[cur]];
21             printf("%d\n",t);
22         }
23         else{
24             int tmp=(t+x)%mod;
25             a[++ct]=tmp;
26             while(l<=r&&tmp>a[q[r]])r--;
27             q[++r]=ct;
28         }
29     }
30     
31     return 0;
32 } 

 

转载于:https://www.cnblogs.com/AT-HENS/p/7756269.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值