[Codeforces #388D Leaving Auction] 线段树+二分
来源:互联网 发布:软件测试 质量方法 编辑:程序博客网 时间:2024/06/13 17:44
[Codeforces #388D Leaving Auction] 线段树+二分
1. 题目链接
[Codeforces #388D Leaving Auction]
2. 题意描述
有
然后,有
数据范围:
3. 解题思路
每次询问中,除去缺席的几个人,肯定是剩下的人中,出价最高的人拍卖成功。他出的价格也应该是刚好比出价第二高的人高。
所以一个线段树求最大值和次大值。然后再在拍卖成功的那个人出的价格来一次二分。That’s all…
4. 实现代码
#include <bits/stdc++.h>using namespace std;typedef __int64 LL;typedef pair<int, int> PII;const int MAXN = 2e5 + 5;int n, q, k;vector<int> v[MAXN];PII seg[MAXN << 2];int buf[MAXN];inline PII getMax(const PII& a, const PII& b) { return a.second >= b.second ? a : b; }void pushUp(int rt) { seg[rt] = getMax(seg[rt << 1], seg[rt << 1 | 1]);}void update(int pos, int val, int l, int r, int rt) { if(l == r) { seg[rt] = PII(l, val); return; } int mid = (l + r) >> 1; if(pos <= mid) update(pos, val, l, mid, rt << 1); else update(pos, val, mid + 1, r, rt << 1 | 1); pushUp(rt);}PII query(int L, int R, int l, int r, int rt) { if(L <= l && r <= R) { return seg[rt]; } int mid = (l + r) >> 1; PII ret = PII(0, 0); if(L <= mid) ret = getMax(ret, query(L, R, l, mid, rt << 1)); if(R > mid) ret = getMax(ret, query(L, R, mid + 1, r, rt << 1 | 1)); return ret;}void init() { for(int i = 0; i < MAXN; i++) v[i].clear(); memset(seg, 0, sizeof(seg));}int main() {#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin);#endif // ONLINE_JUDGE init(); scanf("%d", &n); for(int i = 0; i < n; i++) { int a, b; scanf("%d %d", &a, &b); v[a].push_back(b); } for(int i = 1; i <= n; i++) { int sz = v[i].size(); if(!sz) continue; update(i, v[i][sz - 1], 1, n, 1); } scanf("%d", &q); while(q --) { scanf("%d", &k); for(int i = 0; i < k; i++) { scanf("%d", &buf[i]); int sz = v[buf[i]].size(); if(!sz) continue; update(buf[i], 0, 1, n, 1); } PII ret = query(1, n, 1, n, 1); int a = ret.first, b = ret.second; if(b == 0) { a = 0; } else { update(a, 0, 1, n, 1); PII temp = query(1, n, 1, n, 1); b = *upper_bound(v[a].begin(), v[a].end(), temp.second); } printf("%d %d\n", a, b); update(ret.first, ret.second, 1, n, 1); for(int i = 0; i < k; i++) { int sz = v[buf[i]].size(); if(!sz) continue; update(buf[i], v[buf[i]][sz - 1], 1, n, 1); } } return 0;}
1 0
- [Codeforces #388D Leaving Auction] 线段树+二分
- Codeforces 749D Leaving Auction 二分+Set
- Codeforces Round #388(Div. 2)D. Leaving Auction【二分+思维】好题~
- Codeforces Round #388 (Div. 2)D. Leaving Auction(二分+思维)
- Codeforces Round #388 (Div. 2)D. Leaving Auction
- Codeforces Round #388 (Div. 2)D. Leaving Auction
- Codeforces Round #388 (Div. 2)D. Leaving Auction(水题呀?)
- Codeforces Round #388 (Div. 2) D. Leaving Auction
- Codeforces Round #388 (Div. 2)-D. Leaving Auction
- Codeforces Round #388 (Div. 2)D Leaving Auction
- Codeforces Round #388 (Div. 2)D. Leaving Auction
- Codeforces 749D Leaving Auction binary search+data structures
- CodeForces749D(Leaving Auction) 二分二分二分
- codeforce 749 D. Leaving Auction 拍卖 (set+二分) 思维题!!!
- codeforces 488D Strip 线段树+dp+二分
- COJ1025 Chocolate Auction线段树
- codeforces 527D D. Clique Problem(二分+线段树+贪心+dp)
- Codeforces 864D D. Make a Permutation!【思维+线段树+二分+这是一个煞笔做法】
- springMVC源码分析--HandlerMethod
- ajax传递参数给springmvc一句话总结
- Leetcode 21 Merge Two Sorted Lists
- Two sum
- Glide清除缓存
- [Codeforces #388D Leaving Auction] 线段树+二分
- nginx服务器操作命令(重启命令关闭)
- HDU 5997 BestCoder Round #90 1003 rausen loves cakes 线段树 树状数组
- Bitmap实例
- 将Azure Web应用配置成的反向代理应用
- Android屏幕待机时间的获取和设置
- Java中字符串与byte数组之间的相互转换
- Swift基础之数据持久化UserDefaults(适合初学者)
- Ant 条件判断 if