Vijos P1988 自行车比赛(treap)
来源:互联网 发布:app软件用什么编程 编辑:程序博客网 时间:2024/04/28 21:05
题目链接:点击打开链接
思路:
如果我们判断第i个人是否能第一, 只需要把尽量小的分值给分数最大的人, 如果有人超过了他, 就不能得第一。
我们可以把n个人排序, 让2~n个人分别加上n-1~1, 用treap维护最大值。 转移到下一个人的时候, 只需要把下一个人的加分加到当前这个人上就行了。
PS:用treap的原因是set被卡了。 吐槽:set太慢了。
细节参见代码:
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <string>#include <vector>#include <stack>#include <ctime>#include <bitset>#include <cstdlib>#include <cmath>#include <set>#include <list>#include <deque>#include <map>#include <queue>#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a)<(b)?(a):(b))using namespace std;typedef long long ll;typedef long double ld;const double eps = 1e-6;const double PI = acos(-1);const int mod = 1000000000 + 7;const int INF = 0x3f3f3f3f;const int seed = 131;const ll INF64 = ll(1e18);const int maxn = 300000 + 10;int T,n,m,a[maxn];struct node { node *ch[2]; int r, v, maxv; node(int v=0):v(v) { r = rand(); ch[0] = ch[1] = NULL; maxv = v; } int cmp(int x) const { if(x == v) return -1; return x < v ? 0 : 1; } void maintain() { maxv = v; if(ch[1] != NULL) maxv = max(maxv, ch[1]->maxv); }} *g;void rotate(node* &o, int d) { node* k = o->ch[d^1]; o->ch[d^1] = k->ch[d]; k->ch[d] = o; o->maintain(); k->maintain(); o = k;}void insert(node* &o, int x) { if(o == NULL) o = new node(x); else { int d = (x < o->v ? 0 : 1); insert(o->ch[d], x); if(o->ch[d]->r > o->r) rotate(o, d^1); } o->maintain();}void remove(node* &o, int x) { int d = o->cmp(x); if(d == -1) { node* u = o; if(o->ch[0] != NULL && o->ch[1] != NULL) { int d2 = (o->ch[0]->r > o->ch[1]->r ? 1 : 0); rotate(o, d2); remove(o->ch[d2], x); } else { if(o->ch[0] == NULL) o = o->ch[1]; else o = o->ch[0]; delete u; } } else remove(o->ch[d], x); if(o != NULL) o->maintain();}void removetree(node* &x) { if(x->ch[0] != NULL) removetree(x->ch[0]); if(x->ch[1] != NULL) removetree(x->ch[1]); delete x; x = NULL;}int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); } int ans = 0; sort(a+1, a+n+1); for(int i = 2; i <= n; i++) { insert(g, a[i]+n-i+1); } for(int i = 1; i <= n; i++) { int cur = g->maxv; if(cur <= a[i]+n) ++ans; if(i == n) continue; remove(g, a[i+1]+n-i); insert(g, a[i]+n-i); } printf("%d\n", ans); return 0;}
0 0
- Vijos P1988 自行车比赛(treap)
- Vijos P1988 自行车比赛
- 自行车比赛
- 自行车比赛(AHOI2016初中组T1)
- Vijos 1647 treap
- vijos 1459 treap
- [Vijos P1507][NOI 2004]郁闷的出纳员(Treap)
- 洛谷 P2777 [AHOI2016初中组] 自行车比赛
- 洛谷 P2777 [AHOI2016初中组]自行车比赛
- 洛谷 P2777 [AHOI2016初中组]自行车比赛
- AHOI 2016初中组 自行车比赛
- 自行车
- 自行车
- 自行车
- 自行车
- 自行车自行车自行车自行车
- 自行车
- 可持久化Treap(范浩强Treap)
- HTTP协议详解
- eclipse优化
- 随记
- 函数指针
- 对于C++11中lambda函数的一点理解(下篇)
- Vijos P1988 自行车比赛(treap)
- Linux c==汇编语言程序(9)
- #pragma指令的使用
- Android产品研发(十四)-->App升级与更新
- Atitit 异常机制与异常处理的原理与概论
- node.js中函数的两种封装方式
- Pcl配置
- android wear那些事--打包穿戴式应用
- 异常处理