题目链接

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+;
int data[maxn],last[maxn],ans;
struct D {
int id;
int sc;
int time;
D(int id0=,int sc0=,int time0=){
id=id0;
sc=sc0;
time=time0;
}
};
bool operator < (D a,D b) {
if(a.sc!=b.sc) return a.sc<b.sc;
if(a.id!=b.id) return a.id>b.id;
return a.time<b.time;
}
int main()
{
int t,n,q,x,p;
scanf("%d",&t);
while(t--)
{
priority_queue<D> que;
int ansid=,anssum=,ans=;
scanf("%d%d",&n,&q);
for(int i=;i<=n;i++) que.push(D(i,,));
//printf("%d\n",que.top().id);
memset(data,,sizeof(data));
memset(last,,sizeof(last));
ans=;
int ansT=;
for(int i=;i<=q;i++)
{
scanf("%d%d",&x,&p);
data[x]+=p;
last[x]=i;
while(!que.empty() && que.top().time != last[que.top().id]) que.pop();
if(x==ans&&p<) {
//printf("%d %d---\n",ans,que.top().id);
//D tmp = que.top();
//que.pop();
while(!que.empty() && que.top().time != last[que.top().id]) que.pop();
//printf("%d %d---\n",ans,que.top().id);
if(!que.empty()&&(data[ans]<que.top().sc||(data[ans]==que.top().sc && que.top().id<ans))) {
ansT = i;
ans = que.top().id;
}
//que.push(tmp);
}
else if(p>=&&x!=ans&&(data[x]>data[ans]||(data[x]==data[ans]&&x<ans))) {
ans = x;
ansT = i;
}
que.push(D(x,data[x],i));
}
printf("%d\n",ansT);
}
return ;
}

Gym - 101102C的更多相关文章

  1. Gym 101102C Bored Judge(set--结构体集合)

    这个故事告诉我们,WA了一定要找自己的原因... ... 当我开始用set去做的时候,发现一直过不去,一开始忘了把初始排名加进去,后来忘了第0秒,第0秒第一的id = 1 这个题目的做法也不只这一种, ...

  2. Gym - 101102C线段树

    Judge Bahosain was bored at ACM AmrahCPC 2016 as the winner of the contest had the first rank from t ...

  3. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  4. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  5. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  6. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  7. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  8. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  9. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

随机推荐

  1. 通过sqlserver发送邮件

    配置过程请参考:http://www.2cto.com/database/201403/289114.html 实际中应用的扩展: 1.编写一个触发器(相当于一个多线程的发邮件的服务). 2.在应用程 ...

  2. C语言初级进阶2

    运算符 逻辑运算符: && || ! 位运算符:& | ~ ^ 三目运算符: ? : 结构体元素访问: . -> 命令行参数argc与argv C语言中判断式 各种数据类 ...

  3. Thinking in java学习笔记之持有对象总结

  4. 正则表达式 match 和 exec 比较

    match 和 exec 主要有两点不同: 1.exec是正则表达式的方法,而不是字符串的方法,它的参数才是字符串,如下所示: var re=new RegExp(/\d/); re.exec( &q ...

  5. sublime text 3 3114 注册码

    -– BEGIN LICENSE -– Michael Barnes Single User License EA7E-821385 8A353C41 872A0D5C DF9B2950 AFF6F6 ...

  6. js 获取据当前时间n天前的时间

    <script type="text/javascript"> function getLastDate() { var date = new Date(); ; va ...

  7. 我们为什么要学习Java

    有人说Java已死,学Java还有前途吗? 这怎么可能呢? “Java已死”的论断从12年开始就反复有人提,但是直到今天,Java仍然活着,2015年还荣登TIOBE指数的编程语言奖,成为年度冠军.如 ...

  8. QT中使用函数指针

    想仿命令行,所以定义了一个类,让一个String 对应一个 function,将两者输入list容器. 类中定义了 QString commandStr; void (MainWindow::*com ...

  9. [NHibernate]缓存(NHibernate.Caches)

    系列文章 [Nhibernate]体系结构 [NHibernate]ISessionFactory配置 [NHibernate]持久化类(Persistent Classes) [NHibernate ...

  10. Spring 入门知识

    ------------------------------------------------------------------------------------- Spring是什么? Spr ...