题目链接

#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. 【jQuery】scroll 滚动到顶部

    Jquery 实现页面滚动到顶端 $(document).ready(function () { // 滚动窗口来判断按钮显示或隐藏 $(window).scroll(function () { // ...

  2. java 装饰者模式与继承的区别

    装饰者模式目标 把许多要实现的功能,加载在子类上,类的继承,显得很臃肿,装饰着模式是在不改变原有类文件和使用继承的情况下,通过创建一个包装对象动态地扩展一个对象的功能,相比生成子类更为灵活 装饰者模式 ...

  3. ES6新特性:使用新方法定义javascript的Class

    ES6中定义类的方式, 就是ES3和ES5中定义类的语法糖,虽然也有些区别,但是整体定义类的方式更加简洁,类的继承更加方便, 如果想对ES6中的继承更加熟悉, 最好了解ES5中原型继承的方式, 博客园 ...

  4. WebService学习总结(四)——调用第三方提供的webService服务

    http://www.cnblogs.com/xdp-gacl/p/4260627.html 互联网上面有很多的免费webService服务,我们可以调用这些免费的WebService服务,将一些其他 ...

  5. 为何JAVA虚函数(虚方法)会造成父类可以"访问"子类的假象?

      首先,来看一个简单的JAVA类,Base. 1 public class Base { 2 String str = "Base string"; 3 protected vo ...

  6. java源码分析:Arrays.sort

    仔细分析java的Arrays.sort(version 1.71, 04/21/06)后发现,java对primitive(int,float等原型数据)数组采用快速排序,对Object对象数组采用 ...

  7. yii2 伪静态配置

    原文地址: http://gblz.net/2015/242.html https://segmentfault.com/q/1010000003804408

  8. Json字符串和Json对象的简单总结

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.JSON成为理想的数据交换语言. 易于人阅读和编写,同时也易于机器解析和生成(一般用于提升网络传输速率). ...

  9. 短信接口API

    /** * Created by bingone on 15/12/16. */ import org.apache.http.HttpEntity; import org.apache.http.N ...

  10. [译] 你该知道的javascript作用域 (javascript scope)(转)

    javascript有一些对于初学者甚至是有经验的开发者都难以理解的概念. 这个部分是针对那些听到 : 作用域, 闭包, this, 命名空间, 函数作用域, 函数作用域, 全局作用域, 变量作用域( ...