ne hundred years from now, in 21172117, 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 aa is 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 t2t2if 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 1≤n≤1051≤n≤105 is the number of teams, and 1≤m≤1051≤m≤105 is the number of events.

Then follow mm lines that describe the events. Each line contains two integers tt and pp (1≤t≤n1≤t≤n and 1≤p≤10001≤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 1
3 4
2 7
3 5
1 6
1 9 Sample Output 1
2
3
2
1
题意:好多队伍比赛,按照事件发生顺序给你队伍AC题目的信息,x队AC一道题,罚时为y,每有一个队过题输出编号为1的队伍的排名
我们每当每个队A题的时候把他原来状态删除,把新状态加入到treap.由于可能有好几个队A题数罚时都一样,这样按照队伍编号升序
我们每个节点上我们设置有多个队伍就行了
 #include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
const ll mod=;
ll powmod(ll a,ll b) {ll res=;a%=mod; assert(b>=); for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
const int maxn=1e5+;
struct Node
{
Node *ch[];//0 左儿子(名次靠前) 1右儿子(名次靠后)
int r;//随机优先级,数值越大优先级越高
int v;//值
int s;//以他为根的子树上队伍数的个数
int num;//当前节点上队伍数目(有队伍会题数罚时都相同)一个节点可以右多个队伍
int tim;//罚时
Node(int v,int tim):v(v),tim(tim){ch[]=ch[]=NULL;r=((rand()<<)|rand());s=;num=; }
inline int cmp(int x,int xtim) const {//比较函数 相等-1 名次靠前0(左子树) 名次靠后 1(右子树)
if(x==v&&tim==xtim) return -;//相等
if(x==v) return xtim<tim?:;//题数相同罚时少的优先
return x>v?:;
}
inline void maintain() {
s=num;//当前节点子树个数
if(ch[]!=NULL) s+=ch[]->s;//加上自己左子树
if(ch[]!=NULL) s+=ch[]->s;//加上自己右子树
}
};
void rotate(Node* &o,int d) {//旋转
Node* k=o->ch[d^];o->ch[d^]=k->ch[d];k->ch[d]=o;
o->maintain();
k->maintain();
o=k;
}
void insert(Node* &o,int x,int tim) {//将 过了x题罚时tim的队伍插入到treap
if(o==NULL) {
o=new Node(x,tim);
}
else {
int d;
if(x>o->v) {//题数多 查到左子树
d=;
}
else if(x==o->v) {//题数一样
if(tim<o->tim) d=;//罚时少 左子树
else d=;//罚时多 右子树
}
else d=;//题数少 右子树
if(x==o->v&&tim==o->tim) {//找到当前自己题数罚时都一样的节点
(o->s)++;//当前节点子树的节点上的队伍数++
(o->num)++;//在该节点的队伍数++
}
else {
insert(o->ch[d],x,tim);if(o->ch[d]->r > o->r) rotate(o,d^);
}
}
o->maintain();
}
void remove(Node* &o,int x,int tim) {
int d=o->cmp(x,tim);
if(d==-) {
if(o->num==) {//如果处于当前题数罚时的队伍就一个队
Node* u=o;
if(o->ch[]!=NULL&&o->ch[]!=NULL) {
int d2=(o->ch[]->r>o->ch[]->r?:);
rotate(o,d2);
remove(o->ch[d2],x,tim);
}
else {
if(o->ch[]==NULL) o=o->ch[];
else o=o->ch[];
delete u;
}
}
else {//否则直接当前节点队伍数--
(o->num)--;
}
}
else {
remove(o->ch[d],x,tim);
}
if(o!=NULL) o->maintain();
}
int Rank(Node* o,int x,int tim) {
if(o==NULL) return ;
int s=(o->ch[]==NULL?:o->ch[]->s);//s是o的左子树上队伍的个数
if(o->v==x&&o->tim==tim) {//找到当前队伍状态的节点
return s+;//返回左子树队伍数+1
}
else if(o->v<x||(o->v==x&&o->tim>tim)) {//排名在当前节点之前,往左子树找
return Rank(o->ch[],x,tim);
}
else {//排名在当前节点之后,排名为当前节点左子树队伍数+当前节点队伍数+往右子树找
return Rank(o->ch[],x,tim)+s+(o->num);
}
}
int nownum[maxn],nowtim[maxn];
int main()
{
Node *root=NULL;//初始化
int n,m;
scanf("%d%d",&n,&m);
int u,v;
rep(i,,n) insert(root,,);//大家一开始都没过题
rep(i,,m) {
scanf("%d%d",&u,&v);
remove(root,nownum[u],nowtim[u]);//移除当前队伍之前的状态
nownum[u]++;//题数加1
nowtim[u]+=v;//加罚时
insert(root,nownum[u],nowtim[u]);//插入当前状态
printf("%d\n",Rank(root,nownum[],nowtim[]));//查询队伍编号为1的名次
}
return ;
}
/**
3 10
2 1
2 1
3 1
1 1
3 5
3 5
1 1
1 2
3 1 */
												

Kattis - gcpc (treap模板)的更多相关文章

  1. BZOJ 1588: Treap 模板

    1588: [HNOI2002]营业额统计 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 12171  Solved: 4352 Description ...

  2. G - Galactic Collegiate Programming Contest Kattis - gcpc (set使用)

    题目链接: G - Galactic Collegiate Programming Contest Kattis - gcpc 题目大意:当前有n个人,一共有m次提交记录,每一次的提交包括两个数,st ...

  3. [luogu3369]普通平衡树(treap模板)

    解题关键:treap模板保存. #include<cstdio> #include<cstring> #include<algorithm> #include< ...

  4. Treap 模板 poj1442&hdu4557

    原理可以看hihocoder上面的讲解,很清楚,不多说了. 模板抄lrj训练指南上面的. /** Treap 实现 名次树 功能: 1.找到排名为k的元素 2.值为x的元素的名次 初始化:Node* ...

  5. 平衡树Treap模板与原理

    这次我们来讲一讲Treap(splay以后再更) 平衡树是一种排序二叉树(或二叉搜索树),所以排序二叉树可以迅速地判断两个值的大小,当然操作肯定不止那么多(不然我们还学什么). 而平衡树在排序二叉树的 ...

  6. POJ1442-查询第K大-Treap模板题

    模板题,以后要学splay,大概看一下treap就好了. #include <cstdio> #include <algorithm> #include <cstring ...

  7. Treap 模板

    感觉平衡树也没有以前想的那么玄乎,(其实set超好用的),非旋式Treap挺好理解,和可并堆,二叉搜索树有很大联系 推荐博客:http://memphis.is-programmer.com/post ...

  8. 【Treap模板详细注释】BZOJ3224-普通平衡树

    模板题:D错因见注释 #include<iostream> #include<cstdio> #include<cstring> #include<algor ...

  9. 非旋treap模板

    bzoj3580 非旋转treap 在大神教导下发现split一段区间时先split右边再split左边比较好写 #include <cstdio> #include <cstdli ...

随机推荐

  1. Skyline(6.x)-Web二次开发-多窗口对比

    GitHub 上获取源码 1. 打开个 3D 窗口 一个页面加载多个 TerraExplorer3DWindow 和 SGWorld 等只有第一个能用(即使用 iframe 也是一样) 所以我决定打开 ...

  2. 测开之路六十六:UI测试平台之处理逻辑和蓝图添加到程序入口

    from selenium import webdriverfrom common import get_case_idfrom common.mongo import Mongo class Log ...

  3. DELPHI 全局变量和局部变量的区别

    全局变量: 如果我们在应用程序一个单元中的interface关键字和implementation关键字之间的区域,定义一个全局变量,假如这个单元在别的地方被引用,那么这个单元的全 局变量能够在别的地方 ...

  4. Vue.js的列表数据的同步更新方法

    这次给大家带来Vue.js的列表数据的同步更新方法,Vue.js列表数据同步更新方法的注意事项有哪些,下面就是实战案例,一起来看一下. 数组的 push(),pop(),shift(),unshift ...

  5. 用SPSS做时间序列

    用SPSS做时间序列 关于时间序列,有好多软件可以支持分析,大家比较熟悉的可能是EVIEWS.SPSS.还有STATA,具体用啥软件,结果都是一样的,但是SPSS作为一款学习简单,使用容易的软件还是值 ...

  6. Nginx 实现全站 HTTPS(基于 Let's Encrypt 的免费通配符证书)

    单域名证书的生成可以 参考这里. acme.sh 项目中文文档 Let's Encrypt 在 18 年 1 月份推出了 ACME v2,支持通配符域名证书,对小网站.个人站长的友好度进一步增加. 常 ...

  7. LCT题单(自己的做题情况反馈)(转自Flash)

    LCT题单(自己的做题情况反馈)(转自Flash) 随时进Flash Hu的LCT看一发 也可以看一下我自己的风格的板子 开始 维护链信息(LCT上的平衡树操作) [X] 洛谷P3690 [模板]Li ...

  8. python学习三十五天函数递归的用法

    python函数递归就是自己调用自己,无限循环,但是python限制了调用的次数1000次,就会终止,递归用在栏目分类,采集程序比较多,下面简单说函数递归用法和实例 1,函数递归用法 def func ...

  9. 同一客户端多个git账号的配置

    同一客户端多个git账号的配置 同一客户端多个git账号的配置 步骤一:用ssh-keygen命令生成一组新的id_rsa_new和id_rsa_new.pub. 1 ssh-keygen -t rs ...

  10. MySQL的数据类型:文本、数字、日期/时间

    在MySQL中,有三种主要的类型:文本.数字和日期/时间类型. 文本类型(text):数据类型                                 描述 CHAR(size) 保存固定长度 ...