Gym 101102C---Bored Judge(区间最大值)
题目链接
http://codeforces.com/gym/101102/problem/C
problem description
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.
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.
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.
1
5 7
4 5
3 4
2 1
1 10
4 8
3 -5
4 2
5 题意:有n个人参加活动,现在有Q次事件,标号从1~Q,每个事件为x p 表示第x个人加上p分(-100=<p<=100&&p!=0) 求到第几个事件之后冠军不再变化,冠军为得分最多的那个人,如果多个人得分相同,冠军为序号最小的那个人。 思路:先遍历一遍事件,找到冠军tmp,然后再从第一个事件开始遍历,判断当前的冠军是否是tmp,如果不是则ans=i+1 第二次遍历时就是修改a[x[i]]的值,然后判断最大是是否还是tmp,故可以用RMQ或平衡二叉树(set集合也是平衡二叉树,需要自定义排序); 代码如下:
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <set>
const int MAXN = 1e5+;
using namespace std;
const int INF = 1e9;
int a[MAXN], x[MAXN], p[MAXN]; struct compare
{
bool operator() (const int s1, const int s2) const
{
if(a[s1]==a[s2]) return s1<s2;
return a[s1]>a[s2];
}
};
set<int,compare>s;
set<int,compare>:: iterator it; int main()
{
int T;
cin>>T;
while(T--)
{
s.clear();
int n, q;
memset(a, , sizeof(a));
scanf("%d%d",&n,&q);
for(int i=; i<=q; i++)
{
scanf("%d%d",&x[i],&p[i]);
a[x[i]] += p[i];
}
int Max = -INF, tmp = -;
for(int i=; i<=n; i++)
{
if(a[i] > Max)
{
Max = a[i];
tmp = i;
}
}
memset(a, , sizeof(a));
for(int i=;i<=n;i++)
s.insert(i);
//cout<<"++: "<<*s.begin()<<endl;
int pos = ;
if(*s.begin()!=tmp) pos=;
for(int i=; i<=q; i++)
{
s.erase(x[i]);
a[x[i]] += p[i];
s.insert(x[i]);
if(*s.begin()!=tmp) pos=i+;
}
printf("%d\n",pos);
}
return ;
}
Gym 101102C---Bored Judge(区间最大值)的更多相关文章
- Gym 101102C Bored Judge(set--结构体集合)
这个故事告诉我们,WA了一定要找自己的原因... ... 当我开始用set去做的时候,发现一直过不去,一开始忘了把初始排名加进去,后来忘了第0秒,第0秒第一的id = 1 这个题目的做法也不只这一种, ...
- POJ3264 Balanced Lineup 线段树区间最大值 最小值
Q个数 问区间最大值-区间最小值 // #pragma comment(linker, "/STACK:1024000000,1024000000") #include <i ...
- hdoj 2795 Billboard【线段树区间最大值】
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdoj1754 I Hate It【线段树区间最大值维护+单点更新】
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 2795 Billboard 线段树,区间最大值,单点更新
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...
- 2018中国大学生程序设计竞赛 - 网络选拔赛 1010 YJJ's Salesman 【离散化+树状数组维护区间最大值】
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6447 YJJ's Salesman Time Limit: 4000/2000 MS (Java/O ...
- HDU - 1754 I Hate It (线段树单点修改,求区间最大值)
很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老师有 ...
- Codeforces Round #321 (Div. 2)-B. Kefa and Company,区间最大值!
->链接在此<- B. Kefa and Company time limit per test 2 seconds memory limit per test 256 megabytes ...
- hdoj 2795 Billboard 【线段树 单点更新 + 维护区间最大值】
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- js常用函数
日期时间函数(需要用变量调用): var c=new Date; c.getDate(); document.write(c) //获取当前时间 var c=new Date(); c.getTime ...
- Atitit 深入了解UUID含义是通用唯一识别码 (Universally Unique Identifier),
Atitit 深入了解UUID含义是通用唯一识别码 (Universally Unique Identifier), UUID1 作用1 组成1 全球唯一标识符(GUID)2 UUID 编辑 UUID ...
- iOS----Asset Catalog的用法
文/余书懿(简书作者)原文链接:http://www.jianshu.com/p/7aa06ce22a7b著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 引言 Asset Catalo ...
- YaHoo 前端优化军规
1.Minimize HTTP Requests 减少HTTP请求 图片.css.script.flash等等这些都会增加http请求数,减少这些元素的数量就能减少响应时间.把多个JS.CSS在可能的 ...
- javascript_core_09之继承、属性、对象
1.OOP之修改继承: ①child._proto_=father:=>Object.setPrototypeOf(child,father):每次只能修改一个对象的父对象: ②构造函数.pro ...
- AntV 数据可视化解决方案发布
今天蚂蚁金服发布了一套数据可视化规范AntV. AntV 是一套专业的数据可视化规范,这套规范的目的是为了让可视化的使用者更懂数据可视化.这套规范是蚂蚁金服在可视化建设过程中的理论沉淀,它可以很好得指 ...
- SQLServer清空数据库中所有的表并且ID自动归0
exec sp_MSforeachtable 'Truncate Table ?'
- 编译原理(简单自动词法分析器LEX)
编译原理(简单自动词法分析器LEX)源程序下载地址: http://files.cnblogs.com/files/hujunzheng/%E6%B1%87%E7%BC%96%E5%8E%9F%E7 ...
- 重读 code complete 说说代码质量
重读code complete 说说代码质量 2014年的第一篇文章本来计划写些过去一年的总结和新年展望,但是因为还有一些事情要过一阵才能完成,所以姑且不谈这个,说说最近重读code complete ...
- 一:验证微信的Token
前言:申请到微信公众号的同学,可能会挺感兴趣的,毕竟微信公众号,确实是一个好东西,它提供了一个很好的平台,而且它自带有一套管理模板,对于微信公众号可以很好的管理. 但是也仅仅是很好的管理,因为作为开发 ...