线段树_FZU_1921
2015-07-28 20:13
519 查看
#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; }
相关文章推荐
- 数据结构实验:连通分量个数
- Java(07-28)学习总结
- Java画陆龟
- 【试水CAS-4.0.3】第09节_CAS服务端RememberMe
- CloudStack 4.5 安装笔记
- HDU 5323 SOLVE THIS INTERESTING PROBLEM 爆搜
- 获取进程CPU占用率 -- NtQuerySystemInformation
- AndroidManifest.xml
- Search for a Range
- [hdu5323]复杂度计算,dfs
- eclipse下安装tomcat以及可能遇到的404问题
- hdu杭电4006 The kth great number【优先队列】
- linux中的权限对于文件和目录的重要性
- (BC 一周年)hdu 5310 Souvenir
- 每天一个小知识点16(Angularjs总结四)
- Python的面向对象、Class 概念与使用
- OC内存管理
- [Android] ImageView.ScaleType设置图解
- 暴力求解——Equivalent Strings
- 软件测试方法和测试流程