Codeforces Round #388 (Div. 2) D
There are n people taking part in auction today. The rules of auction are classical. There were n bids made, though it's not guaranteed they were from different people. It might happen that some people made no bids at all.
Each bid is define by two integers (ai, bi), where ai is the index of the person, who made this bid and bi is its size. Bids are given in chronological order, meaning bi < bi + 1 for all i < n. Moreover, participant never makes two bids in a row (no one updates his own bid), i.e.ai ≠ ai + 1 for all i < n.
Now you are curious with the following question: who (and which bid) will win the auction if some participants were absent? Consider that if someone was absent, all his bids are just removed and no new bids are added.
Note, that if during this imaginary exclusion of some participants it happens that some of the remaining participants makes a bid twice (or more times) in a row, only first of these bids is counted. For better understanding take a look at the samples.
You have several questions in your mind, compute the answer for each of them.
The first line of the input contains an integer n (1 ≤ n ≤ 200 000) — the number of participants and bids.
Each of the following n lines contains two integers ai and bi (1 ≤ ai ≤ n, 1 ≤ bi ≤ 109, bi < bi + 1) — the number of participant who made the i-th bid and the size of this bid.
Next line contains an integer q (1 ≤ q ≤ 200 000) — the number of question you have in mind.
Each of next q lines contains an integer k (1 ≤ k ≤ n), followed by k integers lj (1 ≤ lj ≤ n) — the number of people who are not coming in this question and their indices. It is guarenteed that lj values are different for a single question.
It's guaranteed that the sum of k over all question won't exceed 200 000.
For each question print two integer — the index of the winner and the size of the winning bid. If there is no winner (there are no remaining bids at all), print two zeroes.
6
1 10
2 100
3 1000
1 10000
2 100000
3 1000000
3
1 3
2 2 3
2 1 2
2 100000
1 10
3 1000
3
1 10
2 100
1 1000
2
2 1 2
2 2 3
0 0
1 10
Consider the first sample:
- In the first question participant number 3 is absent so the sequence of bids looks as follows:
- 1 10
- 2 100
- 1 10 000
- 2 100 000
Participant number 2 wins with the bid 100 000.
- In the second question participants 2 and 3 are absent, so the sequence of bids looks:
- 1 10
- 1 10 000
The winner is, of course, participant number 1 but the winning bid is 10 instead of 10 000 as no one will ever increase his own bid (in this problem).
- In the third question participants 1 and 2 are absent and the sequence is:
- 3 1 000
- 3 1 000 000
The winner is participant 3 with the bid 1 000.
题意:有个拍卖会,然后出价(出价貌似是上升的),最后说有几个出价是失效的,问最后是哪个价格竞拍到了
1 10
2 100
3 1000
1 10000
2 100000
3 1000000
比如这个,我们知道每人两次出价(价格上升),最后3出价失效,最后保留1 2,2的出价最高,输出2 10000
解法:
1 模拟
2 没有剩下就是的0 0,剩下一个出价人就是取最高值
3 如果留下多个,最后一个出价人的价格和倒数第二个出价比较,找一个比倒数第二个出价最高的还高的出价就行(不一定要最高),如果找不到就取当前的最大值
4 说是数据结构,拿现成的工具套。。
#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
using namespace std;
set<pair<int,int>>Se;
vector<int>Ve[];
int flag[];
int query[];
int main(){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++){
int a,b;
scanf("%d%d",&a,&b);
Ve[a].push_back(b);
flag[a]=;
}
for(int i=;i<=n;i++){
if(flag[i]){
Se.insert({Ve[i][Ve[i].size()-],i});
}
}
int m;
scanf("%d",&m);
while(m--){
int num;
scanf("%d",&num);
for(int i=;i<=num;i++){
scanf("%d",&query[i]);
if(flag[query[i]]==) continue;
Se.erase({Ve[query[i]][Ve[query[i]].size()-],query[i]});
}
if(Se.size()==){
printf("0 0\n");
}else if(Se.size()==){
printf("%d %d\n",Se.begin()->second,Ve[Se.begin()->second][]);
}else{
auto k = --Se.end();
int t1 = k->first, t2 = k->second;
Se.erase({t1, t2});
auto l = --Se.end();
printf("%d %d\n", k->second, *upper_bound(Ve[t2].begin(), Ve[t2].end(), l->first));
Se.insert({t1, t2});
}
for(int i=;i<=num;i++){
if(flag[query[i]]){
Se.insert({Ve[query[i]][Ve[query[i]].size()-],query[i]});
}
}
}
return ;
}
Codeforces Round #388 (Div. 2) D的更多相关文章
- Codeforces Round #388 (Div. 2)
# Name A Bachgold Problem standard input/output 1 s, 256 MB x6036 B Parallelogram is Back s ...
- Codeforces Round #388 (Div. 2) - C
题目链接:http://codeforces.com/contest/749/problem/C 题意:给定一个长度为n的D/R序列,代表每个人的派别,然后进行发表意见,顺序是从1到n.每个人到他的回 ...
- Codeforces Round #388 (Div. 2) - B
题目链接:http://codeforces.com/contest/749/problem/B 题意:给定平行四边形的3个点,输出所有可能的第四个点. 思路:枚举任意两个点形成的直线,然后利用这两个 ...
- Codeforces Round #388 (Div. 2) - A
题目链接:http://codeforces.com/contest/749/problem/A 题意:给定一个数n,求把n分解成尽量多的素数相加.输入素数个数和具体方案. 思路:因为要尽量多的素数, ...
- Codeforces Round #388 (Div. 2) A,B,C,D
A. Bachgold Problem time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #388 (Div. 2) 749E(巧妙的概率dp思想)
题目大意 给定一个1到n的排列,然后随机选取一个区间,让这个区间内的数随机改变顺序,问这样的一次操作后,该排列的逆序数的期望是多少 首先,一个随机的长度为len的排列的逆序数是(len)*(len-1 ...
- Codeforces Round #388 (Div. 2) A+B+C!
A. Bachgold Problem 任何一个数都可以由1和2组成,由于n是大于等于2的,也就是可以由2和3组成.要求最多的素数即素数越小越好,很明显2越多越好,如果n为奇数则再输出一个3即可. i ...
- Codeforces Round #388 (Div. 2) C. Voting
题意:有n个人,每个人要么是属于D派要么就是R派的.从编号1开始按顺序,每个人都有一次机会可以剔除其他任何一个人(被剔除的人就不在序列中也就失去了剔除其他人的机会了):当轮完一遍后就再次从头从仅存的人 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- SPOJ7258
传送门 这题可以参考平衡树求第k大的过程,需要预处理一下从当前节点往下走能走出多少个子串. 原本准备存个图用反向的topsort,发现极为麻烦,看了别人的代码后发现,他们按step大小用了基排,省了很 ...
- javascript学习第一天
从大学第一次接触到JavaScript,到现在一直是个软肋,之前也是学习过一遍,但是缺乏系统学习,基础不牢,那么今天开始从基础部分学起来,今天是第一天,每天至少要保证效率,也要保证学习质量. 恩,要按 ...
- HDU1133 Buy the Ticket —— 卡特兰数
题目链接:https://vjudge.net/problem/HDU-1133 Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Me ...
- ffmpeg: error while loading shared libraries: libavdevice.so.52
今天在编译安装ffmpeg的时候出现了题目中的问题,最终解决方案如下: errors: ffmpeg正常安装后执行ffmpeg时出现如下错误:ffmpeg: error while loading s ...
- BestCoder6 1002 Goffi and Squary Partition(hdu 4982) 解题报告
题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=530 (格式有一点点问题,直接粘 ...
- (转)使用cygwin注意事项一
原文出处:http://gotgit.readthedocs.io/en/latest/01-meet-git/050-install-on-windows-cygwin.html 在Windows下 ...
- [AH2017/HNOI2017]抛硬币
传送门 这个题的暴力比较好想--然后用一些组合的知识就可以变成正解了. 首先我们考虑a=b的情况.我们把扔出来的硬币看成是一个01序列,那么对于一个b获胜的序列,他在每一位都按位异或1之后必然是一个a ...
- NOIP2000提高组(RQNOJ314)方格取数
题目描述 设有N*N的方格图(N<=10,我们将其中的某些方格中填入正整数,而其他的方格中则放入数字0.如下图所示(见样例): 某人从图的左上角的A 点出发,可以向下行走,也可以向右走,直到到达 ...
- junit4 Assert静态方法及API
junit中的assert方法全部放在Assert类中. 1.assertTrue/False([String message,]boolean condition); 用来查看变量是是否为fa ...
- PorterDuffXfermode 图像混合技术在漫画APP中的应用
此文已由作者游葳授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 写在开头 随着应用开发的深入,视觉同学在完成了页面的基本设计后,再也按耐不住心中的寂寞,开始对各种细节不满意, ...