【Codeforces717F】Heroes of Making Magic III
来源:互联网 发布:rar解压 for mac 编辑:程序博客网 时间:2024/05/22 05:18
以下根据网上大佬们的博客。
消除完一个区间肯定有一大堆方法,不妨考虑其中一种:
先前两个之间反复横跳,消除光第一个,然后再消除第二个,直到消除完。
然后我们可以根据这个列出不等式和方程:
然后我们令
#include <bits/stdc++.h>#define gc getchar()#define ll long long#define inf 1e9#define N 200009#define mid (l+r>>1)#define root 1,1,n#define lc cur<<1#define rc lc|1#define lson lc,l,mid#define rson rc,mid+1,r#define now cur,l,rusing namespace std;int n,m,a[N],bit[N],b[N],tg[N<<2][2],Min[N<<2][2];int read(){ int x=1; char ch; while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1; int s=ch-'0'; while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-'0'; return s*x;}void up(int cur,int l,int r){ Min[cur][0]=min(Min[lc][0],Min[rc][0]); Min[cur][1]=min(Min[lc][1],Min[rc][1]);}void down(int cur,int l,int r){ for (int k=0;k<2;k++) if (tg[cur][k]) { tg[lc][k]+=tg[cur][k],tg[rc][k]+=tg[cur][k]; Min[lc][k]+=tg[cur][k],Min[rc][k]+=tg[cur][k]; tg[cur][k]=0; }}void build(int cur,int l,int r){ if (l==r) { Min[cur][l&1]=b[l]; Min[cur][l&1^1]=inf; tg[cur][0]=tg[cur][1]=0; return; } build(lson); build(rson); up(now);}void ins(int cur,int l,int r,int L,int R,int y,int k){ if (L>R) return; if (L<=l&&R>=r) { tg[cur][k]+=y; Min[cur][k]+=y; return; } down(now); if (L<=mid) ins(lson,L,R,y,k); if (R>mid) ins(rson,L,R,y,k); up(now);}int qry(int cur,int l,int r,int L,int R,int k){ if (L<=l&&R>=r) return Min[cur][k]; down(now); int ret=inf; if (L<=mid) ret=min(ret,qry(lson,L,R,k)); if (R>mid) ret=min(ret,qry(rson,L,R,k)); return ret;}int qry(int cur,int l,int r,int x,int k){ if (x==0) return 0; if (l==r) return Min[cur][k]; down(now); if (x<=mid) return qry(lson,x,k); else return qry(rson,x,k);}int main(){ n=read(); for (int i=1;i<=n;i++) a[i]=read(); m=read(); for (int i=1;i<=n;i++) b[i]=a[i]-b[i-1]; build(root); while (m--) { int op=read(); if (op==1) { int l=read()+1,r=read()+1,k=read(); ins(root,l,r,k,l&1); if ((r-l+1)&1) ins(root,r+1,n,k,l&1),ins(root,r+1,n,-k,l&1^1); } else { int l=read()+1,r=read()+1; if ((r-l+1)&1) { int ret=qry(root,l-1,(l-1)&1); int ret1=qry(root,l,r,r&1)+ret; int ret2=qry(root,l,r,r&1^1)-ret; int ret3=qry(root,r,r&1)+ret; if (ret3==1&&ret1>=1&&ret2>=0) puts("1"); else puts("0"); } else { int ret=qry(root,l-1,(l-1)&1); int ret1=qry(root,l,r,r&1)-ret; int ret2=qry(root,l,r,r&1^1)+ret; int ret3=qry(root,r,r&1)-ret; if (ret3==0&&ret1>=0&&ret2>=1) puts("1"); else puts("0"); } } } return 0;}
阅读全文
0 0
- 【Codeforces717F】Heroes of Making Magic III
- 【线段树】[CodeForces - 717F]Heroes of Making Magic III
- hdu 3619 Heroes of Might and Magic 二维最短路
- The Making of God of War III
- Making Startup Magic
- Hackers - Heroes Of The Computer Revolution
- 【Angular2】Tour of Heroes 之 e2e测试
- Making Use of JavaScript
- making sense of multitouch
- Making Sense of Multitouch
- Making Sense of Multitouch
- Making sense of LayoutInflater
- Making sense of word2vec
- Iconified TextList - The making of
- The Making of Crysis 2
- DotA 逆袭:Heroes of Newerth 公测开始
- Angular 4入门教程系列:7:Tour Of Heroes之路由
- The magic of method pointers
- 线程安全(一)
- Vim基本命令
- break-word;
- 线上集群服务器性能参数查看命令
- Eclipse快捷键
- 【Codeforces717F】Heroes of Making Magic III
- 机器学习-神经网络之激活函数(Activation Function)
- Apache Flink:详细入门
- 润乾报表 填报表如何实现电话号码的校验
- swagger
- _attribute_(weak)的用法
- Java形参和实参的区别
- HDU 1050 Moving Tables(贪心)
- C和C++的const