Gym - 101102C
#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的更多相关文章
- Gym 101102C Bored Judge(set--结构体集合)
这个故事告诉我们,WA了一定要找自己的原因... ... 当我开始用set去做的时候,发现一直过不去,一开始忘了把初始排名加进去,后来忘了第0秒,第0秒第一的id = 1 这个题目的做法也不只这一种, ...
- Gym - 101102C线段树
Judge Bahosain was bored at ACM AmrahCPC 2016 as the winner of the contest had the first rank from t ...
- 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 ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
随机推荐
- JavaScript模板引擎artTemplate.js——两种方法实现性别的判定
template.helper(name, callback) name:必传,辅助事件的名称. callback:必传,辅助事件的回调函数. return:undefined 所谓的辅助事件,主要用 ...
- Uncaught Error: Bootstrap tooltips require Tether (http://github.hubspot.com/tether/)
引用bootstrap之后报这个错误,错误出在bootstrap.js文件中,原语句是: if(void 0===window.Tether) throw new Error("Bootst ...
- php以pdo方式连接sqlserver,无法开启sqlsrv扩展
首先,PHP连接sqlserver代码如下: $host="aaaaa"; $dbname="aaaaa"; $user="aaaaa"; ...
- js下载浏览器中的图片
jquery function download(src) { var $a = $("<a></a>").attr("href", s ...
- lua 例子
//顶 - - - //顶 #include <stdio.h> #include <string.h> extern "C"{ #include < ...
- 搭建haproxy
1:下载haproxy wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.20.tar.gz2:解压,编译,安装 tar zxf hapr ...
- Google Maps API V3 之 路线服务
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
- c++11 中成员变量初始化的顺序
参考C++11FAQ https://www.chenlq.net/cpp11-faq-chs 11以后可以直接在类里面初始化成员变量,类似这样 class A { int a=1; const in ...
- safari浏览器在window下 打开控制台
有时候需要在window下测试safari浏览器的兼容性 然后需要打开错误控制台 以下是完整打开的图文教程 1.显示菜单栏 2.打开偏好设置 3.然后切换到高级标签 勾选 在菜单栏显示开发菜单 4.打 ...
- Android ViewPager sharedpreferences
http://www.cnblogs.com/dwinter/archive/2012/02/27/AndroidViewPager%E5%A4%9A%E9%A1%B5%E9%9D%A2%E6%BB% ...