码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj 1012

时间:2015-08-21 00:07:48      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

一般碰到插入删除就要用平衡树了,今天终于碰到个反例啦

技术分享
 1 #include<bits/stdc++.h>
 2 #define inc(i,l,r) for(i=l;i<=r;i++)
 3 #define dec(i,l,r) for(i=l;i>=r;i--)
 4 #define inf 1e9
 5 #define mem(a) memset(a,0,sizeof(a))
 6 #define ll long long
 7 #define NM 200000+5
 8 using namespace std;
 9 int read(){
10     int x=0,f=1;char ch=getchar();
11     while(!isdigit(ch)){if(ch===)f=-1;ch=getchar();}
12     while(isdigit(ch))x=x*10+ch-0,ch=getchar();
13     return x*f;
14 }
15 struct info{
16     int s;
17     info(int x=0):s(x){}
18 }T[3*NM];
19 info operator+(const info&x,const info&y){
20     info f;
21     f.s=max(x.s,y.s);
22     return f;
23 }
24 int n,m,p,i,x,t;
25 void ins(int i,int x,int y,int a,int b){
26     int t=(x+y)>>1;
27     if(x==y){
28         T[i]=info(b);
29         return;
30     }
31     if(a<=t)ins(i<<1,x,t,a,b);
32     else ins(i<<1|1,t+1,y,a,b);
33     T[i]=T[i<<1]+T[i<<1|1];
34 }
35 int ask(int i,int x,int y,int a,int b){
36     int t=(x+y)>>1;
37     if(b<x||y<a)return 0;
38     if(a<=x&&y<=b)return T[i].s;
39     return max(ask(i<<1,x,t,a,b),ask(i<<1|1,t+1,y,a,b));
40 }
41 int main(){
42     m=read();p=read();
43     inc(i,1,m){
44         char ch=getchar();
45         while(ch!=A&&ch!=Q)ch=getchar();
46         x=read();
47         if(ch==A)ins(1,1,m,++n,(x+t)%p);
48         else t=ask(1,1,m,n-x+1,n),printf("%d\n",t);
49     }
50     return 0;
51 }
View Code

 

bzoj 1012

标签:

原文地址:http://www.cnblogs.com/onlyRP/p/4746497.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!