NEFU470三国之战区间更新
来源:互联网 发布:淘宝客服招聘平台 编辑:程序博客网 时间:2024/04/27 20:31
题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=470
操作 attract (l,r,x) 区间的和乘X;
query(l,r), 查询区间的和
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#define N 100030using namespace std;struct node{ int l,r; int lazy,sum; bool flag;}root[N<<2];int shu[N];void build(int t,int l,int r){ root[t].l=l; root[t].r=r;root[t].lazy=1; root[t].flag=0; if(root[t].l==root[t].r) { root[t].sum=shu[l]; return; } build(t<<1,l,(l+r)/2);build(t<<1|1,(l+r)/2+1,r); root[t].sum=root[t<<1].sum+root[t<<1|1].sum;}void up(int t){ if(root[t<<1].flag&&root[t<<1].l!=root[t<<1].r)up(t<<1); if(root[t<<1|1].flag&&root[t<<1|1].l!=root[t<<1|1].r)up(t<<1|1); root[t<<1].lazy*=root[t].lazy;root[t<<1|1].lazy*=root[t].lazy; root[t<<1].flag=1;root[t<<1|1].flag=1; root[t<<1].sum*=root[t].lazy; root[t<<1|1].sum*=root[t].lazy; root[t].lazy=1; root[t].flag=0;}void update(int t,int l,int r,int date){ if(root[t].l==l&&root[t].r==r) { if(root[t].flag&&root[t].l!=root[t].r)//就是这调了N久才知道要补上 up(t); root[t].sum*=date;root[t].lazy=date;root[t].flag=1; return;} else { if(root[t].flag&&root[t].l!=root[t].r) { up(t); } if(root[t<<1].r>=r)update(t<<1,l,r,date); else if(root[t<<1|1].l<=l)update(t<<1|1,l,r,date); else {update(t<<1,l,root[t<<1].r,date);update(t<<1|1,root[t<<1|1].l,r,date);} root[t].sum=root[t<<1].sum+root[t<<1|1].sum; }}int query(int t,int l,int r){ int s; if(root[t].l==l&&root[t].r==r) return root[t].sum; else { if(root[t].flag&&root[t].l!=root[t].r) up(t); if(root[t<<1].r>=r)s=query(t<<1,l,r); else if(root[t<<1|1].l<=l) s=query(t<<1|1,l,r); else s=query(t<<1,l,root[t<<1].r)+query(t<<1|1,root[t<<1|1].l,r); root[t].sum=root[t<<1].sum+root[t<<1|1].sum; } return s;}int main(){ int n,q; char s[33]; int a,b,c; int cas=0; while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;i++) cin>>shu[i]; build(1,1,n); scanf("%d",&q); printf("Case %d:\n",++cas); for(int j=1;j<=q;j++) { scanf("%s%d%d",s,&a,&b); if(strcmp(s,"attack")==0) { scanf("%d",&c); update(1,a,b,c); } else { printf("%d\n",query(1,a,b)); } } } return 0;}
0 0
- NEFU470三国之战区间更新
- 三国将帅之分
- 搞笑之 三国歇后语
- 三国之典故
- 手机操作系统之三国
- nefu 三国之战
- 三国之甄宓
- XMind之乱世三国
- 三国风云之猛将传
- “三国人物”之管理十戒
- 三国杀之内奸兵法
- 三国之刃一区QQ群?
- 三国名将之高顺
- 三国
- 三国
- 三国
- 战区漫步Gouraud渲染
- 三国之见龙卸甲-电影之感
- 解决RedrawWindow()刷新界面出现闪烁的问题, VC对话框界面使用InvalidateRect刷新局部
- OpenCV编程->cvCvtColor函数
- codechef Chef and The Right Triangles 题解
- LINUX环境中部署JAVA项目步骤
- 类型之间的转换
- NEFU470三国之战区间更新
- hdu 1011 Starship Troopers(树形DP)
- Android编译源码 其中含有jar和so库文件的
- or1200中加载存储类指令说明
- What is satellite information in data structures?
- Android 上百个项目的源代码
- [Asp.Net]Understanding Built-In User and Group Accounts in IIS
- 用友nc 用户长时间没有任何操作,如何设置会话的失效时间?
- 疑问~