zoukankan      html  css  js  c++  java
  • G

    One hundred years from now, in21172117, the International Collegiate Programming Contest (of which the NCPC is a part) has expanded significantly and it is now the Galactic Collegiate Programming Contest (GCPC).

    This year there are nn teams in the contest. The teams are numbered 1,2,,n1,2,…,n, and your favorite team has number 11.

    Like today, the score of a team is a pair of integers (a,b)(a,b) where aais the number of solved problems and bb is the total penalty of that team. When a team solves a problem there is some associated penalty (not necessarily calculated in the same way as in the NCPC – the precise details are not important in this problem). The total penalty of a team is the sum of the penalties for the solved problems of the team.

    Consider two teams t1t1 and t2t2 whose scores are (a1,b1)(a1,b1) and (a2,b2)(a2,b2). The score of team t1t1 is better than that of t2t2 if either a1>a2a1>a2, or if a1=a2a1=a2 and b1<b2b1<b2. The rank of a team is k+1k+1 where kk is the number of teams whose score is better.

    You would like to follow the performance of your favorite team. Unfortunately, the organizers of GCPC do not provide a scoreboard. Instead, they send a message immediately whenever a team solves a problem.

    Input

    The first line of input contains two integers nn and mm, where 1n1051≤n≤105 is the number of teams, and 1m1051≤m≤105 is the number of events.

    Then follow mm lines that describe the events. Each line contains two integers tt and pp (1tn1≤t≤n and 1p10001≤p≤1000), meaning that team tt has solved a problem with penalty pp. The events are ordered by the time when they happen.

    Output

    Output mm lines. On the ii’th line, output the rank of your favorite team after the first ii events have happened.

    Sample Input 1Sample Output 1
    3 4
    2 7
    3 5
    1 6
    1 9
    
    2
    3
    2
    1
    








    题目大意: n个队,m次操作

    每次操作读入两个数,l和r   l队多a了一道题并且罚时加r

    每次操作后输出1号队的排名

    这题开始想到了是set,但是对set掌握的十分不熟练

    因为我开的set,所以要避免出现一样的数据,所以看了ljf的博客发现

    给每个数弄一个标号就行了qwq

    并且重载之后可以二分查找

    然后就是  我找到的1号队的迭代器,但是set的迭代器不让减啊,真是醉了,不知道怎处理了

    又看了ljf 的博客,发现set只维护得分比1多的一部分就行了qwq

    qwq  orz ljf






     1 #include "bits/stdc++.h"
     2 
     3 using namespace std;
     4 
     5 int n,m;
     6 
     7 struct aa
     8 {
     9    int id=0;
    10    int slove=0;
    11    int pen;
    12    aa(){id=0;slove=0;pen=0;};
    13    bool operator<(const aa &b)const
    14    {
    15     if(slove==b.slove&&pen==b.pen)return id<b.id;
    16      if(slove!=b.slove)return slove>b.slove;
    17      return pen<b.pen;
    18    }
    19 }a[200000];
    20 
    21 set<aa>s;
    22 
    23 int main()
    24 {
    25   cin>>n>>m;
    26   
    27   for (int i=1;i<=n;i++)a[i].id=i;
    28   
    29   for (int i=1;i<=m;i++)
    30   {
    31     int l,r;scanf("%d%d",&l,&r);
    32     s.erase(a[l]);
    33     a[l].slove++; a[l].pen+=r;
    34   
    35    if(l==1)
    36    {
    37         while (!s.empty()&& (a[1] < (*(--s.end())   )) )s.erase(--s.end());
    38        
    39    }
    40    else 
    41    {
    42          if(a[l]<a[1])s.insert(a[l]);      
    43     }
    44 cout<<s.size()+1<<endl;
    45   }
    46 }
  • 相关阅读:
    html的输出&,空格,大小于号
    html如何修改hr水平直线的粗细
    LODOP指定window默认打印机和临时默认打印机
    微软面试题: 找出二叉树上任意两个结点的最近共同父结点。
    说说自己对hibernate一级、二级、查询、缓存的理解。
    MySql中添加用户,新建数据库,用户授权,删除用户,修改密码
    修改MySQL的默认密码的四种小方法
    java中Scanner的nextLine()和next()的区别
    JAVA中String字符串比较equals()和equalsIgnoreCase()的区别
    HashMap与HashTable的区别
  • 原文地址:https://www.cnblogs.com/zhangbuang/p/10646183.html
Copyright © 2011-2022 走看看