线段树_FZU_1921
来源:互联网 发布:网站源码小偷程序 编辑:程序博客网 时间:2024/06/18 18:42
#include<iostream>#include<cstdio>#include<cstring>const int maxn = 10010;using namespace std;struct node{ int num, score;};node tree[maxn<<2];void work(int rt){ tree[rt] = tree[rt<<1].score <= tree[rt<<1|1].score?tree[rt<<1]:tree[rt<<1|1];}void build(int l, int r, int rt){ if(l == r) { tree[rt].num = l; scanf("%d",&tree[rt].score); return; } int mid = (l+r)>>1; build(l,mid,rt<<1); build(mid+1,r,rt<<1|1); work(rt);}void updata(int w,int val, int l,int r, int rt){ if(l == r) { tree[rt].score += val; return; } int mid= (l+r)>>1; if(w<=mid) updata(w,val,l,mid,rt<<1); else updata(w,val,mid+1,r,rt<<1|1); work(rt);}int main(){ //freopen("in.txt","r",stdin); int t,n,a,b,m; scanf("%d",&t); for(int i = 1; i <= t; i++) { scanf("%d",&n); build(1,n,1); scanf("%d",&m); while(m--) { scanf("%d%d",&a,&b); if(a ==0) a = tree[1].num; updata(a,b,1,n,1); } printf("Case %d: %d %d\n",i,tree[1].num,tree[1].score); } return 0;}
0 0
- 线段树_FZU_1921
- 线段树?线段树!
- 线段树?线段树!
- 线段_线段树
- 线段_线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- POJ 3258Cross The Rive
- java基础之方法的多态
- Block
- HDU 2546 饭卡
- DirectFB常用接口
- 线段树_FZU_1921
- Java对象序列化和反序列化
- ASCⅡ码转换
- HDOJ 1896 Stones(优先队列)
- zoj3886.Nico Number
- 15/7/28/class类和Field类的一般应用
- linux上部署Tomcat服务器。
- Android用shareUserID实现多个Activity显示在同一界面
- 屏幕适配