BZOJ1012: [JSOI2008]最大数maxnumber

给定n<=200000个操作:单点插入,查最后若干个数的Max,强制在线。

在线个鬼啊至少我空间还是可以先分配的,把序列倒过来,分配好空间,每个查询就是一个前缀Max了。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 #include<stdlib.h>
 5 //#include<queue>
 6 //#include<math.h>
 7 //#include<time.h>
 8 //#include<iostream>
 9 using namespace std;
10 
11 int n,mod;
12 #define maxn 200011
13 struct BIT
14 {
15     int a[maxn],n;
16     void clear(int m) {n=m; for (int i=1;i<=n;i++) a[i]=-0x7fffffff;}
17     void add(int x,int v) {for (;x<=n;x+=x&-x) a[x]=max(a[x],v);}
18     int query(int x) {int ans=0; for (;x;x-=x&-x) ans=max(ans,a[x]); return ans;}
19 }t;
20 
21 struct Point{int x; bool w;}a[maxn];
22 int main()
23 {
24     scanf("%d%d",&n,&mod);
25     char id[5];
26     int tot=0;
27     for (int i=1;i<=n;i++)
28     {
29         scanf("%s%d",id,&a[i].x);
30         a[i].w=(id[0]=='A');
31         tot+=(id[0]=='A');
32     }
33     t.clear(tot);
34     int last=0;
35     for (int i=1;i<=n;i++)
36     {
37         if (a[i].w) t.add(tot--,(a[i].x+0ll+last)%mod);
38         else printf("%d\n",(last=t.query(tot+a[i].x)));
39     }
40     return 0;
41 }
View Code

 

转载于:https://www.cnblogs.com/Blue233333/p/8082652.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值