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 ...
随机推荐
- UESTC - 900 方老师炸弹 —— 割点
题目链接:https://vjudge.net/problem/UESTC-900 方老师炸弹 Time Limit: 4000/2000MS (Java/Others) Memory L ...
- Nginx安装教程(Centos6.8)
1.安装gcc gcc-c++(如新环境,未安装请先安装 yum install -y gcc gcc-c++ 2.安装wget yum -y install wget 3.安装PCRE库 cd /h ...
- centos 配置
安装 node 源地址: http://my.oschina.net/blogshi/blog/260953 (一) 编译好的文件 简单说就是解压后,在bin文件夹中已经存在node以及npm,如果你 ...
- [转]FPGA入门——basys2开发板的伪随机gold码的生成
本文原创,转载请注明出处:http://www.cnblogs.com/risten/p/4166169.html 1.系统原理 通过频率控制字选择相位步进,产生访问ROM的地址,进而控制DAC的输出 ...
- 精选Java面试题
什么是隐式类型转换?什么是显示类型转换? 当将占位数少的类型赋值给占位数多的类型时,Java自动使用隐式类型转换(如int型转为long型).当把在级别高的变量的值赋给级别底变量时,必须使用显示类型转 ...
- 大数相乘(hdu 1402)
------------------题目链接--------------------- 题目没啥说的,两个数相乘,fft,一发模板就AC,kuangbin模板大法好,不懂原理的小白也能体验AC. 个人 ...
- hdu-5744 Keep On Movin(思维)
题目链接: Keep On Movin Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- hdu-2647 Reward && hdu-2049产生冠军 &&hdu-3342Legal or Not(拓扑排序)
题目链接: hdu-2647 /*Problem : 2647 ( Reward ) Judge Status : Accepted RunId : 16919085 Language : G++ A ...
- 多线程之:正确使用 Volatile 变量
转载:http://www.ibm.com/developerworks/cn/java/j-jtp06197.html Java™ 语言包含两种内在的同步机制:同步块(或方法)和 volatile ...
- 洛谷P1073最优贸易——双向取值
题目:https://www.luogu.org/problemnew/show/P1073 由于任何城市都可以多次经过,所以可以随便走,也就不用太在意有向边和无向边,把无向边当做两条有向边处理: 根 ...