zoukankan      html  css  js  c++  java
  • Gym

    Judge Bahosain was bored at ACM AmrahCPC 2016 as the winner of the contest had the first rank from the second hour until the end of the contest.

    Bahosain is studying the results of the past contests to improve the problem sets he writes and make sure this won’t happen again.

    Bahosain will provide you with the log file of each contest, your task is to find the first moment after which the winner of the contest doesn’t change.

    The winner of the contest is the team with the highest points. If there’s more than one team with the same points, then the winner is the team with smallest team ID number.

    Input

    The first line of input contains a single integer T, the number of test cases.

    The first line of each test case contains two space-separated integers N and Q (1 ≤ N, Q ≤ 105), the number of teams and the number of events in the log file. Teams are numbered from 1 to N.

    Each of the following Q lines represents an event in the form: X P, which means team number X (1 ≤ X ≤ N) got P ( - 100 ≤ P ≤ 100, P ≠ 0) points. Note that P can be negative, in this case it represents an unsuccessful hacking attempt.

    Log events are given in the chronological order.

    Initially, the score of each team is zero.

    Output

    For each test case, if the winner of the contest never changes during the contest, print 0. Otherwise, print the number of the first event after which the winner of the contest didn’t change. Log events are numbered from 1 to Q in the given order.

    Example

    Input
    1
    5 7
    4 5
    3 4
    2 1
    1 10
    4 8
    3 -5
    4 2
    Output
    5
    题意:计分,每个队刚开始为0,找最后一直分最大的那一个事件
    题解:线段树维护,区间更新,最上层的id就是最大的那一个,不相同就更换。
    #include<map>
    #include<set>
    #include<cmath>
    #include<queue>
    #include<stack>
    #include<vector>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define pi acos(-1)
    #define ll long long
    #define mod 1000000007
    #define ls l,m,rt<<1
    #define rs m+1,r,rt<<1|1
    
    using namespace std;
    
    const double eps=1e-8;
    const int N=100000+5,maxn=305,inf=0x3f3f3f3f;
    
    struct {
       int v;
       int id;
    }e[N<<2];
    
    void pushup(int rt)
    {
        e[rt].v=max(e[rt<<1].v,e[rt<<1|1].v);
        if(e[rt<<1].v>=e[rt<<1|1].v)e[rt].id=e[rt<<1].id;
        else e[rt].id=e[rt<<1|1].id;
    }
    void btree(int l,int r,int rt)
    {
        if(l==r)
        {
            e[rt].id=l;
            e[rt].v=0;
            return ;
        }
        int m=(l+r)>>1;
        btree(ls);
        btree(rs);
        pushup(rt);
    }
    void update(int x,int u,int l,int r,int rt)
    {
        if(l==r)
        {
            e[rt].v+=u;
            return ;
        }
        int m=(l+r)>>1;
        if(x<=m)update(x,u,ls);
        else update(x,u,rs);
        pushup(rt);
    }
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int t,n,k;
        cin>>t;
        while(t--){
            cin>>n>>k;
            btree(1,n,1);
            int ans=0;
            int now=e[1].id;
            for(int i=1;i<=k;i++)
            {
                int a,b;
                cin>>a>>b;
                update(a,b,1,n,1);
                if(now!=e[1].id)ans=i,now=e[1].id;
            }
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    MySQL集群搭建(4)-MMM+LVS+Keepalived
    MySQL集群搭建(3)-MMM高可用架构
    MySQL集群搭建(2)-主主从模式
    MySQL集群搭建(1)-主备搭建
    MySQL 安装(二进制版)
    Nginx缓存了DNS解析造成后端不通--代理
    开启tcp_timestamps和tcp_tw_recycle造成NAT转发连接不上
    tcp_tw_recycle参数引发的故障
    记一次TIME_WAIT网络故障
    TCP服务端收到syn但是不回复syn ack问题分析
  • 原文地址:https://www.cnblogs.com/acjiumeng/p/6736331.html
Copyright © 2011-2022 走看看