线段树_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
原创粉丝点击