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 ...
随机推荐
- 浅淡!important对CSS的重要性
SS中的!important是一个非常重要的属性,有时候发挥着非常大的作用,52CSS.com这方面的知识并不是非常多,我们看下面的文章,对它作比较感观的了解. 前几天写一些CSS代码的时候又难为我了 ...
- Codeforces Round #376 (Div. 2) F. Video Cards —— 前缀和 & 后缀和
题目链接:http://codeforces.com/contest/731/problem/F F. Video Cards time limit per test 1 second memory ...
- 近期测试BUG总结
前些日子上线了新版的app,在上线后发现了几个重大的bug,在此总结,在以后的测试工作中需要额外的关注. 需求流程bug 页面刷新bug 标签栏刷新bug 第一个bug出现的原因是产品需求与运营实际操 ...
- Eclipse jar打包详解
通过Eclipse下的演示工程,介绍如何打包这样的项目:要导出的类里边用到了别的jar包. 方法/步骤 1. Eclipse下的演示工程结构如下图所示,其中Task.java是当前工程运行的M ...
- PYTHON 异常处理 一 ASSERT
assert语句,如果没记错,这个东西在C或者C++里面也有的.属于短小的断言.下面的是来自python help document的说明: Assert statements are a conve ...
- POJ2217(最长公共子串)
Secretary Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 992 Accepted: 408 Descripti ...
- 蓝桥杯G将军
G将军有一支训练有素的军队,这个军队除开G将军外,每名士兵都有一个直接上级(可能是其他士兵,也可能是G将军).现在G将军将接受一个特别的任务,需要派遣一部分士兵(至少一个)组成一个敢死队,为了增加敢死 ...
- android 怎么实现跑马灯效果
自定义控件 FocusedTextView, 使android系统误以为它拥有焦点 public class FocusedTextView extends TextView { public Foc ...
- jquery登录的异步验证
//定义一个json var validate = { username : false, pwd : false, pwded : false, verify : false, loginUsern ...
- 洛谷 P4704 太极剑【贪心】
首先考虑分割线能分割一条线当且仅当分割线一个端点在这条线的ab中间,另一端点在外面,也就是分割线对应的一条弧不能同时有这条线的两个端点 每条线的两端点都染同色,然后分段,一段里面颜色互不相同,分割线就 ...