【Codeforces837G】Functions On The Segments
来源:互联网 发布:2016黑马java百度网盘 编辑:程序博客网 时间:2024/06/05 12:03
这题只要读懂了题意,开大了范围,看清了如何强制在线,就能很快AC(雾)
#include <bits/stdc++.h>#define gc getchar()#define mid (l+r>>1)#define ll long long#define mod 1000000000#define M 30000009#define N 200009using namespace std;ll n,tr[M][2],root[N],cnt,lson[M],rson[M];ll read(){ ll x=1; char ch; while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1; ll s=ch-'0'; while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-'0'; return s*x;}void ins(ll &cur,ll l,ll r,ll x,ll y,ll k,ll last){ cur=++cnt; lson[cur]=lson[last],rson[cur]=rson[last]; tr[cur][k]=tr[last][k]+y; tr[cur][k^1]=tr[last][k^1]; if (l==r) return; if (x<=mid) ins(lson[cur],l,mid,x,y,k,lson[last]); else ins(rson[cur],mid+1,r,x,y,k,rson[last]);}ll qry(ll cur,ll l,ll r,ll L,ll R,ll k){ if (!cur) return 0; if (L<=l&&R>=r) return tr[cur][k]; ll ret=0; if (L<=mid) ret+=qry(lson[cur],l,mid,L,R,k); if (R>mid) ret+=qry(rson[cur],mid+1,r,L,R,k); return ret;}int main(){ n=read(); for (ll i=1;i<=n;i++) { ll x1=read(),x2=read(),y1=read(),a=read(),b=read(),y2=read(); ins(root[i],0,mod,0,y1,0,root[i-1]); ins(root[i],0,mod,x1+1,b-y1,0,root[i]); ins(root[i],0,mod,x2+1,y2-b,0,root[i]); ins(root[i],0,mod,x1+1,a,1,root[i]); ins(root[i],0,mod,x2+1,-a,1,root[i]); } ll Ans=0; ll q=read(); for (int i=1;i<=q;i++) { ll l=read(),r=read(),x=(read()+Ans)%mod; ll Ans1=qry(root[r],0,mod,0,x,0)-qry(root[l-1],0,mod,0,x,0); ll Ans2=qry(root[r],0,mod,0,x,1)-qry(root[l-1],0,mod,0,x,1); //if (i==4999) x=200001; printf("%lld\n",Ans=(Ans1+x*Ans2)); } return 0;}
阅读全文
0 0
- 【Codeforces837G】Functions On The Segments
- Educational Codeforces Round 26 G. Functions On The Segments 主席树
- 模拟 Codeforces620F Xors on Segments
- The virtual functions table
- The use of functions
- The virtual functions table
- The use of functions
- Codeforces 620F Xors on Segments DP
- Segments
- Segments
- Segments
- Segments
- Segments
- The OCI Functions for C
- The File Functions in C
- Using Functions after the Pipeline
- In all of the functions
- A. Polo the Penguin and Segments
- RecycleView实现多条目
- web 视频播放插件兼容ie
- scrapy处理个中文本格式HTML,XML,CSV
- MUI H5+常见控件的使用之单选按钮
- 第9周项目2 二叉树遍历的递归算法
- 【Codeforces837G】Functions On The Segments
- STM32外设结构体定义和时钟初始化语句顺序导致编译
- 遇见Lost connection to MySQL server at 'reading initial communication packet',system error:0的解决办法
- mybatis oracle获取插入的主键
- 数据结构第九周项目一-二叉树算法库
- css字符编码
- 关于二进制算法和运算符++,-- 的理解
- 定时任务
- Java项目问题集锦