大意: 若干个人参加拍卖会, 给定每个人出价顺序, 保证价格递增, q个询问, 给出k个人的编号, 求删除这k个人的所有出价后, 最终谁赢, 他最少出价多少.

set维护每个人最后一次投票的时间, 每次询问直接暴力找到最后一个未删除的, 假设为$x$, 那么$x$就是最后赢家, 求最少出价的话, 只要$x$的出价大于$x$之前一位的最大出价即可.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 1e6+10;
int m, n, a[N], b[N], pos[N], no[N];
set<int> c[N]; int main() {
scanf("%d", &n);
REP(i,1,n) {
scanf("%d%d", a+i, b+i);
pos[a[i]] = i;
no[i] = a[i];
c[a[i]].insert(b[i]);
}
set<int,greater<int> > q;
REP(i,1,n) if (pos[i]) q.insert(pos[i]);
scanf("%d", &m);
REP(i,1,m) {
int k, t;
scanf("%d", &k);
set<int> del;
REP(i,1,k) scanf("%d", &t),del.insert(t);
int x = 0;
for (auto &&t:q) if (!del.count(no[t])) {
x = no[t];
del.insert(x);
break;
}
if (!x) {puts("0 0"); continue;}
int y = 0;
for (auto &&t:q) if (!del.count(no[t])) {
y = no[t];
break;
}
if (!y) printf("%d %d\n", x, *c[x].begin());
else {
int w = *(--c[y].end());
printf("%d %d\n", x, *c[x].lower_bound(w));
}
}
}

Leaving Auction CodeForces - 749D (set,贪心,模拟)的更多相关文章

  1. Leaving Auction CF 749D

    题目:http://codeforces.com/problemset/problem/749/D 题目大意: 有n个人竞拍,也有n个叫牌,一个人可以有多个叫价牌,但也可能有一些人根本不叫价 每个叫牌 ...

  2. Codeforces 950C Zebras ( 贪心 && 模拟 )

    题意 : 给出一个 01 串,要求你将其分隔出若干个子序列 ( 每个数字只能属于某一个子序列 ) ,子序列必须满足由 0 开头和结尾,且中间需 01 交替构成.若无法做到,则输出 -1. 分析 :  ...

  3. CodeForces 6C(贪心 + 模拟)

    题目链接 思路如下 贪心的思想,⚠️女士优先的策略,当它们吃掉之前的物品所用的时间相同的时候,此时女士先开始 继续吃 题解如下 #include<iostream> using names ...

  4. Codeforces 749D. Leaving Auction set+二分

    D. Leaving Auction time limit per test: 2 seconds memory limit per test:256 megabytes input:standard ...

  5. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  6. CodeForces ---596B--Wilbur and Array(贪心模拟)

    Wilbur and Array Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Su ...

  7. cf 749D Leaving Auction

    Leaving Auction time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  8. CF749D Leaving Auction set排序查找

    CodeForces 749D. Leaving Auction 传送门 There are n people taking part in auction today. The rules of a ...

  9. Leaving Auction

    Leaving Auction 题目链接:http://codeforces.com/contest/749/problem/D 二分 本来以为是哪种神奇的数据结构,没想到sort+lower_bon ...

随机推荐

  1. HDU6579 Operation

    题目链接 问题分析 区间求异或和最大,比较自然的想到了线性基.而每次求一个区间的线性基显然是行不通的.我们考虑在每个位置求出首位置到当前位置的线性基.同时我们要使线性基中高位的位置所选的数尽量靠后.这 ...

  2. linux 文件目录介绍

    网上的资源 太多了,copy 过来 留给自己用吧! 摘自 : http:/ 使用linux也有一年多时间了  最近也是一直在维护网站系统主机  下面是linux目录结构说明 本人使用的是centos系 ...

  3. Spring boot之JPA/Hibernate/Spring Data

    1.什么是JPA? JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. JPA(Java Per ...

  4. 实现一个成熟的底层毛玻璃效果(纯CSS)

    写在前面 毛玻璃背景是一个很常见的网页样式,想要实现,其实并不难,但经过我在网上的搜索发现,大量实现方法都较为不规范,且把问题复杂化了(例如各种z-index属性和position的定位)现提供一个代 ...

  5. Linux系统下Java开发环境的配置(未完...)

    1.查看jdk版本   java -version 2.将下载好的jdk放在/usr/lib/jvm里(其中jvm是自己起的名)   sudo mv jdk1.8.0_111 /usr/lib/jvm ...

  6. 客户端浏览器向服务器发起http请求的全过程

    http协议的参考:http://blog.csdn.net/hefeng6500/article/details/75081047 (1)浏览器先搜索自身的DNS缓存 (2)操作系统搜索自身的DNS ...

  7. LocalDateTime自动转化格式

    开发中,遇到这样的问题.一个LocalDateTime类型的属性返回给前端是中间带T的格式,前端说转不了. 可以引入jackson包转换一下 <properties> <jackso ...

  8. docker启动redis并使用java连接

    一.先查找镜像 docker search redis 二.拉取镜像 docker pull redis三.等待拉取完毕 四.查看拉去的镜像 docker iamges 五.运行redis 连接1:h ...

  9. vue-preview 缩略图

    如果我们在 vue 中想使用缩略图的话,可以使用 vue-preview 的插件 小图的缩略 大图的样式 使用方法:vue-preview 下  载:   npm i vue-preview 使用方法 ...

  10. vue组件化初体验 全局组件和局部组件

    vue组件化初体验 全局组件和局部组件 vue组件化 全局组件 局部组件  关于vue入门案例请参阅 https://www.cnblogs.com/singledogpro/p/11938222.h ...