大意: 若干个人参加拍卖会, 给定每个人出价顺序, 保证价格递增, 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. Acwing:137. 雪花雪花雪花(Hash表)

    有N片雪花,每片雪花由六个角组成,每个角都有长度. 第i片雪花六个角的长度从某个角开始顺时针依次记为ai,1,ai,2,…,ai,6ai,1,ai,2,…,ai,6. 因为雪花的形状是封闭的环形,所以 ...

  2. JavaWeb-SpringBoot_使用MySQL数据库实现用户管理_demo

    使用Gradle编译项目 传送门 项目已托管到Github上 传送门 SpringBoot使用MySQL实现 实现功能:普通用户注册.普通用户登录.管理员通过edit-user页面和show-all- ...

  3. 使用jQuery创建可删除添加行的动态表格,超级简单实用的方法

    使用jQuery动态的添加和删除表格里面的行,不多说了直接上代码. <!DOCTYPE html> <html> <head> <meta charset=& ...

  4. linux系统基础优化及高级操作命令

    Linux基础系统优化 引言没有,只有一张图. Linux的网络功能相当强悍,一时之间我们无法了解所有的网络命令,在配置服务器基础环境时,先了解下网络参数设定命令. ifconfig 查询.设置网卡和 ...

  5. python学习---50行代码实现图片转字符画1

    转自:https://blog.csdn.net/mm1030533738/article/details/78447714 项目链接: https://www.shiyanlou.com/cours ...

  6. 用过消息队列?Kafka?能否手写一个消息队列?懵

    是否有同样的经历?面试官问你做过啥项目,我一顿胡侃,项目利用到了消息队列,kafka,rocketMQ等等. 好的,那请开始你的表演,面试官递过一支笔:给我手写一个消息队列!!WHAT? 为了大家遇到 ...

  7. 第六周学习总结&java实验报告四

    第六周学习总结&java实验报告四 学习总结: 上一周因为接近国庆假期,所以老师没有讲太多的新知识点,只要是带我们一起做了一个动物模拟变声器的实验,进一步了解和学习到继承的 有关知识点和应用: ...

  8. Error-ASP.NET:The Value of property CloneFrom can not be empty string!

    ylbtech-Error-ASP.NET:The Value of property CloneFrom can not be empty string! 1.返回顶部 1. “/”应用程序中的服务 ...

  9. Other | 十招教你找到海量PPT模板

    转载自:https://www.douban.com/note/330962457/ 问:PPT模板是什么含义? 答: 先假定你们要的是这种网上到处泛滥成灾的主题PPT吧,下面请耐心看到最后,秋叶老师 ...

  10. flutter dialog

    flutter Dialog import 'dart:math'; import 'package:flutter/material.dart'; import 'test.dart'; impor ...