您的位置:首页 > 其它

线段树_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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: