lightoj1080 线段树
2024-10-10 05:13:20
//Accepted 6628 KB 520 ms //I a b 把a到b区间的二进制位去反,转化成a到b区间的数全部加1 //Q a 判断第a位的奇偶 #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <cmath> #include <algorithm> using namespace std; /** * This is a documentation comment block * 如果有一天你坚持不下去了,就想想你为什么走到这儿! * @authr songt */ ; struct node { int l,r; int add; int t; }f[imax_n*]; string s; void build(int t,int l,int r) { f[t].l=l; f[t].r=r; f[t].add=; if (l==r) { f[t].t=s[l-]-'; return ; } ; build(*t,l,mid); build(*t+,mid+,r); f[t].t=f[*t].t+f[*t+].t; } void update(int t,int l,int r,int c) { if (f[t].l==l && f[t].r==r) { f[t].add+=c; return ; } f[t].t+=(r-l+)*c; ; *t,l,r,c); else { *t+,l,r,c); else { update(*t,l,mid,c); update(*t+,mid+,r,c); } } } int query(int t,int l,int r) { if (f[t].l==l && f[t].r==r) { ); } ; f[t].t+=(r-l+)*f[t].add; f[*t].add+=f[t].add; f[*t+].add+=f[t].add; f[t].add=; *t,l,r); else { *t+,l,r); else { *t,l,mid)+query(*t+,mid+,r); } } } ]; int Q; int x,y; void slove() { int len=s.length(); build(,,len); scanf("%d",&Q); while (Q--) { scanf("%s",sq); ]=='I') { scanf("%d%d",&x,&y); update(,x,y,); } else { scanf("%d",&x); ,x,x); printf(); } } } int main() { int T; scanf("%d",&T); ; while (T--) { cin>>s; printf("Case %d:\n",++t); slove(); } ; }
最新文章
- winform中dataGridView隔行显示不同的背景色,鼠标移动上显示不同颜色,离开后变回原色
- Git学习笔记(6)——Bug和Feature分支
- [No00002C]人的寿命应该能达到100至175岁-北大齐教授健康讲座笔录
- System.exit(0)和System.exit(1)区别
- 从输入url到页面加载完成都发生了什么?
- poj 1696 Space Ant (极角排序)
- Android沉浸式(侵入式)标题栏(状态栏)Status(三)
- [原]在Fedora 20环境下安装系统内核源代码
- URAL1355. Bald Spot Revisited
- 与IO相关的等待事件troubleshooting-系列5
- SD卡中FAT32文件格式高速入门(图文具体介绍)
- XML的序列化和反序列化 详细介绍
- Git的安装
- JavaScript———从setTimeout与setInterval到AJAX异步
- 裁剪Ubuntu内核和模块管理2
- 你必须知道的.net读书笔记之第二回深入浅出关键字---对抽象编程:接口和抽象类
- UNICODE与ASCII
- [转]Virtio balloon
- 菜鸟Vue学习笔记(二)
- 利用python制作在Linux服务器后台定时运行的任务-邮件提醒