Gym 101572G Galactic Collegiate Programming Contest(离线 树状数组)
来源:互联网 发布:系统数据流程图 编辑:程序博客网 时间:2024/05/17 21:47
题意:ACM比赛每个队伍的分数由(a, b)组成, a是做出题数, b是总罚时, 出题多的排名前, 相同题量罚时少排名前, 如果题量罚时都相同, 排名一样, 例如, (1, 1), (1, 1), (0, 0)三支队伍排名为1, 1, 2 现在有n支队伍, m个事件, 每个事件由(t, p)组成, 代表队伍t以罚时p做出了一题让你输出每个事件后, 队伍1的排名
思路:先预处理出所有可能的(a, b), 离散化后就能利用树状数组维护了。分数(a, b)可以看作是一维的。
代码:
#include<bits/stdc++.h>using namespace std;const int maxn = 1e5+5;int n, m;struct node{ int num, pea; node() {} node(int nn, int pp): num(nn), pea(pp) {} bool operator < (const node &a)const { if(num == a.num) return pea < a.pea; else return num > a.num; }}Hash[maxn], a[maxn];int t[maxn], p[maxn], tree[maxn];int lowbit(int x){ return x&(-x);}void update(int pos, int val){ while(pos < maxn) { tree[pos] += val; pos += lowbit(pos); }}int query(int pos){ int res = 0; while(pos) { res += tree[pos]; pos -= lowbit(pos); } return res;}int main(void){ while(cin >> n >> m) { memset(tree, 0, sizeof(tree)); memset(a, 0, sizeof(a)); int cnt = 0; for(int i = 1; i <= m; i++) { scanf("%d%d", &t[i], &p[i]); a[t[i]].num++, a[t[i]].pea += p[i]; Hash[cnt++] = node(a[t[i]].num, a[t[i]].pea); } sort(Hash, Hash+m); update(m+1, n); memset(a, 0, sizeof(a)); for(int i = 1; i <= m; i++) { int tmp = lower_bound(Hash, Hash+m, a[t[i]])-Hash+1; update(tmp, -1); a[t[i]].num++; a[t[i]].pea += p[i]; tmp = lower_bound(Hash, Hash+m, a[t[i]])-Hash+1; update(tmp, 1); int pos = lower_bound(Hash, Hash+m, a[1])-Hash+1; printf("%d\n", query(pos-1)+1); } } return 0;}
阅读全文
1 0
- Gym 101572G Galactic Collegiate Programming Contest(离线 树状数组)
- 2017-2018 ACM-ICPC, NEERC Problem G Galactic Collegiate Programming Contest(树状数组)
- Galactic Collegiate Programming Contest
- GYM 2015 ACM Syrian Collegiate Programming Contest
- GYM 2017 ACM Amman Collegiate Programming Contest
- Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest(二月十日训练赛)
- Codeforces Gym 2015 ACM Amman Collegiate Programming Contest
- Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest
- GYM 101147 G.The Galactic Olympics(dp)
- The 12th Zhejiang Provincial Collegiate Programming Contest - G
- 2017 ACM Arabella Collegiate Programming Contest G. Snake Rana GYM101350G
- Gym 100114H Milestones(离线树状数组)
- Gym 101147G - The Galactic Olympics
- Codeforces gym 2014 Nordic Collegiate Programming Contest(最初版,有过题再更新)
- CodeFroces GYM 2016-2017 ACM-ICPC, Egyptian Collegiate Programming Contest (ECPC 16) B.street(最短路)
- 2015 China Collegiate Programming Contest
- The 7th Zhejiang Provincial Collegiate Programming Contest->Problem G:G - Wu Xing
- The 11th Zhejiang Provincial Collegiate Programming Contest->Problem G:G - Ternary Calculation
- Mysql日志解析
- Python 3)面向对象的基本概念(理解)
- opencv stitch拼接
- 第八天总结 韦荣益
- 新疆大学(新大)OJ xju 1009: 一带一路 prim求最短路径+O(n)素数筛选
- Gym 101572G Galactic Collegiate Programming Contest(离线 树状数组)
- 用Arduino剖析PWM脉宽调制
- <leetcode>496. Next Greater Element I
- 逻辑斯蒂回归与梯度下降算法
- DP 添加正负号求余数POJ1745
- 扫雷游戏
- [BZOJ2721]樱花 阶乘标准分解式
- C#你必须知道的25个基础概念
- 初来