1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cctype> #include<cmath> using namespace std; inline int read(){ int x=0,w=0;char c=getchar(); while(!isdigit(c)) w|=c=='-',c=getchar(); while(isdigit(c)) x=x*10+(c^48),c=getchar(); return w?-x:x; } namespace star { const int maxn=4e6+10; int n,b[maxn],cnt,sumfire; struct BIT{ int c[maxn]; inline void update(int x,int k){for(;x<=cnt;x+=x&-x)c[x]+=k;} }S1,S2; inline int query(int x){ if(x<1 or x>cnt) return 0; int ans1=0,ans2=sumfire; for(;x;x-=x&-x) ans1+=S1.c[x],ans2+=S2.c[x]; return min(ans1,ans2); } struct query{ bool type; int t,v,op; }e[maxn]; inline void work(){ n=read(); for(int i=1;i<=n;i++) if((e[i].op=read())==1) e[i].type=read(),e[i].t=b[++cnt]=read(),e[i].v=read(); else e[i]=e[read()],e[i].op=2,e[i].v=-e[i].v; sort(b+1,b+1+cnt); cnt=unique(b+1,b+1+cnt)-b-1; for(int i=1;i<=n;i++) e[i].t=lower_bound(b+1,b+1+cnt,e[i].t)-b; for(int i=1;i<=n;i++){ if(e[i].type==0) S1.update(e[i].t,e[i].v); else S2.update(e[i].t+1,-e[i].v),sumfire+=e[i].v; int x1=0,sum=-sumfire; for(int j=21;~j;j--){ int to=x1|(1<<j),zp; if(to<=cnt and (zp=sum+S1.c[to]-S2.c[to])<=0) sum=zp,x1=to; } int ans1=query(x1),x2=x1+1,ans2=query(x2); if(ans1<=0 and ans2<=0)puts("Peace"); else if(ans1>ans2) printf("%d %d\n",b[x1],ans1<<1); else { int p=0,sum=sumfire; for(int j=21;~j;j--){ int to=p|(1<<j),zp; if(to<=cnt and (zp=sum+S2.c[to])>=ans2) sum=zp,p=to; } printf("%d %d\n",b[p],sum<<1); } } } } signed main(){ star::work(); return 0; }
|