最基本的敌兵布阵C++实现杭电1166
来源:互联网 发布:linux vi强制退出命令 编辑:程序博客网 时间:2024/05/29 17:39
#include<iostream>#include<string>using namespace std;#define MAXN 50000int tree[MAXN*2+1];void build(int node, int l, int r, int *s){if(l == r){tree[node] = s[l];return;}else{int m = (l+r)>>1;build(node<<1, l, m, s);build(node<<1|1, m+1, r, s);tree[node] = tree[node<<1] + tree[node<<1|1]; }}void update(int node, int l, int r, int idx, int rt){if( l == r){tree[node] += rt;return;}int m = (l+r)>>1;if(idx <= m)update(node<<1,l,m,idx,rt);else{update(node<<1|1,m+1,r,idx,rt);}tree[node] = tree[node<<1]+tree[node<<1|1];}int Query(int node, int begin, int end, int l, int r){if(l<=begin && r>=end){return tree[node];}int p1=0,p2=0;int m = (begin+end)>>1;if(l<=m)p1 = Query(node<<1,begin,m,l,r);if(r>=m+1)p2 = Query(node<<1|1,m+1,end,l,r);return p1+p2;}int main(){int T,N,i,j,TEMP;int s[MAXN];string order;cin >> T;TEMP = T;while(T--){cout << "Case " << TEMP - T<<":"<<endl;cin >> N;for(int i=1;i<N+1;i++){cin >> s[i];} build(1,1,N,s);while(cin >> order){if(order == "Add"){cin >> i;cin >> j;update(1,1,N,i,j);}else if(order == "Sub"){cin >> i;cin >> j;update(1,1,N,i,-j);}else if(order == "Query"){cin >> i;cin >> j;cout << Query(1,1,N,i,j) << endl;}else if (order == "End"){break;}}}}
阅读全文
0 0
- 最基本的敌兵布阵C++实现杭电1166
- 杭电1166敌兵布阵
- 杭电1166敌兵布阵
- 杭电 1166 敌兵布阵
- 杭电1166敌兵布阵
- 【杭电】[1166]敌兵布阵
- 【杭电1166】敌兵布阵
- 杭电1166敌兵布阵 (用的树状数组)
- 杭电ACM--敌兵布阵(1166)
- 杭电 1166敌兵布阵(线段树)
- 杭电oj-1166-敌兵布阵
- 【杭电oj1166】敌兵布阵
- 【树状数组 + 简单题】杭电 hdu 1166 敌兵布阵
- 【线段树 + 简单题】杭电 hdu 1166 敌兵布阵
- 杭电hdu 1166 敌兵布阵 线段树
- 杭电1166 敌兵布阵 线段树and树状数组
- 杭电 1166 敌兵布阵(线段树求和)
- 敌兵布阵(杭电1166)(树状数组)
- C++的变量
- C语言再学习 -- 段错误(核心已转储)
- struts2的工作原理
- android中getLocationInWindow和getLocationOnScreen的区别
- Codeforces875B-Sorting the Coins
- 最基本的敌兵布阵C++实现杭电1166
- PullToRefreshListView不请求网络
- [ZJOI2006]物流运输 luogu.P1772
- 出现GC overhead limit exceeded 的解决方案
- 如何让项目的start变成自己添加的character
- 数据结构实验之链表六:有序链表的建立
- Struts 2中<s:iterator>标签的用法
- MongoDB从小白开始使用到……
- Mybatis