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.

Input

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.

Output

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.

Examples
input
6
1 10
2 100
3 1000
1 10000
2 100000
3 1000000
3
1 3
2 2 3
2 1 2
output
2 100000
1 10
3 1000
input
3
1 10
2 100
1 1000
2
2 1 2
2 2 3
output
0 0
1 10
Note

Consider the first sample:

  • In the first question participant number 3 is absent so the sequence of bids looks as follows:
    1. 1 10
    2. 2 100
    3. 1 10 000
    4. 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. 1 10
    2. 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:
    1. 3 1 000
    2. 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的更多相关文章

  1. Codeforces Round #388 (Div. 2)

      # Name     A Bachgold Problem standard input/output 1 s, 256 MB    x6036 B Parallelogram is Back s ...

  2. Codeforces Round #388 (Div. 2) - C

    题目链接:http://codeforces.com/contest/749/problem/C 题意:给定一个长度为n的D/R序列,代表每个人的派别,然后进行发表意见,顺序是从1到n.每个人到他的回 ...

  3. Codeforces Round #388 (Div. 2) - B

    题目链接:http://codeforces.com/contest/749/problem/B 题意:给定平行四边形的3个点,输出所有可能的第四个点. 思路:枚举任意两个点形成的直线,然后利用这两个 ...

  4. Codeforces Round #388 (Div. 2) - A

    题目链接:http://codeforces.com/contest/749/problem/A 题意:给定一个数n,求把n分解成尽量多的素数相加.输入素数个数和具体方案. 思路:因为要尽量多的素数, ...

  5. 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 ...

  6. Codeforces Round #388 (Div. 2) 749E(巧妙的概率dp思想)

    题目大意 给定一个1到n的排列,然后随机选取一个区间,让这个区间内的数随机改变顺序,问这样的一次操作后,该排列的逆序数的期望是多少 首先,一个随机的长度为len的排列的逆序数是(len)*(len-1 ...

  7. Codeforces Round #388 (Div. 2) A+B+C!

    A. Bachgold Problem 任何一个数都可以由1和2组成,由于n是大于等于2的,也就是可以由2和3组成.要求最多的素数即素数越小越好,很明显2越多越好,如果n为奇数则再输出一个3即可. i ...

  8. Codeforces Round #388 (Div. 2) C. Voting

    题意:有n个人,每个人要么是属于D派要么就是R派的.从编号1开始按顺序,每个人都有一次机会可以剔除其他任何一个人(被剔除的人就不在序列中也就失去了剔除其他人的机会了):当轮完一遍后就再次从头从仅存的人 ...

  9. 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 ...

随机推荐

  1. PYTHON 爬虫笔记四:正则表达式基础用法

    知识点一:正则表达式详解及其基本使用方法 什么是正则表达式 正则表达式对子符串操作的一种逻辑公式,就是事先定义好的一些特定字符.及这些特定字符的组合,组成一个‘规则字符串’,这个‘规则字符串’用来表达 ...

  2. FFmpeg big changes. ffmpeg 接口的一些改变

    Big changes have been made from FFmpeg 0.5.1… Refer to http://cekirdek.pardus.org.tr/~ismail/ffmpeg- ...

  3. java-线程(一)

    1.进程与线程的区别 多个进程的内部数据和状态都是完全独立的,而多个线程是共享一块内存空间和一组系统资源,有可能互相影响.多线程程序比多进程程序需要更少的管理费用.进程是重量级的任务,需要分配他们的单 ...

  4. 上传图片 ajax input type="file" 兼容 ie chroem 火狐

    上传图片,转载请注明出处!!! 兼容 ie chroem 火狐 html: <div id="uploadForm"> <input id="file& ...

  5. a标签无法传递中文参数问题的解决

    a标签无法传递中文参数问题的解决. 可以通过form表单提交 隐藏域的方法解决. 前台jsp页面: <a class="vsb_buton" href="javas ...

  6. [LeetCode] Scramble String -- 三维动态规划的范例

    (Version 0.0) 作为一个小弱,这个题目是我第一次碰到三维的动态规划.在自己做的时候意识到了所谓的scramble实际上有两种可能的类型,一类是在较低层的节点进行的两个子节点的对调,这样的情 ...

  7. bzoj 1098 [POI2007]办公楼biu——链表

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1098 求补图的连通块大小.与自己没有边的和自己在一个连通块里. 用链表把所有点串起来.先给自 ...

  8. SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis)(转载)

    使用SSM(Spring.SpringMVC和Mybatis)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方.之前没有记录SSM整合 ...

  9. Ipython使用总结1

    安装了Anaconda就会发现安装了很多组件.也就省去了安装包时候的依赖问题 https://www.continuum.io/downloads 2 Ipython基础 (1)启动: win+R 启 ...

  10. 3、webpack打包出的文件解析

    分析打包后的结果,看看打包后的结果是什么东西 把打包后的结果.注释什么的删删‘’ 当前是一个匿名函数. 默认的时候会执行,执行的时候会传一个对象,对象有几部分,第一部分是我们的key.第二部分是我们的 ...