二分查找,$set$。

对于某一次询问,如果把人删光了,那么输出$0$ $0$。

如果只剩下$1$个人,那么输出那个人喊的最低价格。

如果剩下的人数有大于等于两个,

这时最底下出现的情景必然是红色部分由一个人喊,紫色部分由另一个人喊。

这两个人分别是喊价最高价次高者和最高者,并且红色部分最后一个位置的下一个位置就是答案。因此只需在获取两个人的信息后,在最高者喊价序列中二分即可。

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
using namespace std; const int maxn=;
int n,q; struct X
{
int id,val;
}s[maxn]; struct XX{
int a,b;
XX () { }
XX(int A,int B)
{
a=A;
b=B;
} bool operator < (const XX &aa) const
{
return b>aa.b;
}
}; XX fir,sec; vector<int> v[maxn];
set<XX> h; int tmp[maxn],mn[maxn],mx[maxn]; bool check(int x)
{
int tt=v[fir.a][x];
if(s[tt].val<sec.b) return ;
return ;
} int main()
{
scanf("%d",&n);
for(int i=;i<=;i++) mx[i]=,mn[i]=; for(int i=;i<=n;i++)
{
scanf("%d%d",&s[i].id,&s[i].val);
v[s[i].id].push_back(i);
mx[s[i].id]=max(mx[s[i].id],s[i].val);
mn[s[i].id]=min(mn[s[i].id],s[i].val);
} for(int i=;i<=;i++)
{
if(mx[i]==) continue;
h.insert(XX(i,mx[i]));
} scanf("%d",&q);
for(int i=;i<=q;i++)
{
int k; scanf("%d",&k);
for(int j=;j<=k;j++) scanf("%d",&tmp[j]);
for(int j=;j<=k;j++)
{
if(mx[tmp[j]]==) continue;
h.erase(XX(tmp[j],mx[tmp[j]]));
} if(h.size()==)
{
printf("0 0\n");
}
else if(h.size()==)
{
XX ans = *h.begin();
printf("%d %d\n",ans.a,mn[ans.a]);
}
else
{
set<XX>::iterator iter;
int cnt=; for(iter = h.begin() ; iter != h.end(); iter++)
{
cnt++;
if(cnt==) fir = *iter;
else if(cnt==) { sec = *iter; break; }
} int L=,R=v[fir.a].size()-;
int ans; while(L<=R)
{
int mid=(L+R)/;
if(check(mid)) ans=mid,R=mid-;
else L=mid+;
} int tt=v[fir.a][ans];
printf("%d %d\n",s[tt].id,s[tt].val); } for(int j=;j<=k;j++)
{
if(mx[tmp[j]]==) continue;
h.insert(XX(tmp[j],mx[tmp[j]]));
}
}
return ;
}

CodeForces 749D Leaving Auction的更多相关文章

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

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

  2. codeforces 749D Leaving Auction(二分)

    题目链接:http://codeforces.com/problemset/problem/749/D 题意:就是类似竞拍,然后报价肯定要比上一个高,然后查询输入k个数表示那些人的竞拍无效, 输出最后 ...

  3. cf 749D Leaving Auction

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

  4. CF749D Leaving Auction set排序查找

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

  5. Leaving Auction

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

  6. Codeforces 749D:Leaving Auction(set+二分)

    http://codeforces.com/contest/749/problem/D 题意:有几个人在拍卖场竞价,一共有n次喊价,有q个询问,每一个询问有一个num,接下来num个人从这次拍卖中除去 ...

  7. 【codeforces 749D】Leaving Auction

    [题目链接]:http://codeforces.com/problemset/problem/749/D [题意] 有n个人在竞价; 按照时间的顺序给出n次竞价(可能有一些人没有参加竞价); 每次竞 ...

  8. Leaving Auction CodeForces - 749D (set,贪心,模拟)

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

  9. Leaving Auction CF 749D

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

随机推荐

  1. 我的Android 4 学习系列之开始入手:配置开发环境与理解Hello World!

    目录 如何安装Android SDK.创建开发环境和调试项目 移动设计中一些注意事项 使用Android虚拟设备.模拟器和其他开发工具 如何安装Android SDK.创建开发环境和调试项目 下载和安 ...

  2. Android中怎么去除标题栏详解

    怎么出去标题栏,我再另一个博客中亦有实例在这里再详细的解释一下,也让自己能更加巩固最简单也是小重要的东西. 这里有两种方法是比较好的... 第一种: 首先,在values中建一个theme.xml 代 ...

  3. Apache Httpd Server 2.2升级2.4

    Apache Httpd Server 2.2升级2.4 (2 votes, average: 5.00 out of 5) 2,302 views 2012 年 3 月 20 日Web服务器.服务器 ...

  4. gof设计模式回顾

    gof23根据讲师学习笔记回顾: 1.gof:Gang of Four;叫grasp更具有针对性,解决具体的问题; ---------------------总共分为三大类: ---------创建型 ...

  5. python chanllenge题解

    网址:chanllenge 修改url最后的html的前缀为答案,就可以过关. 页面上很多只有一幅图片,实际上题目描述全在页面源码中. 然后推荐一个在线代码运行的网站 ideone 查看所有源码:ht ...

  6. MVC文件上传与下载

    MVC文件上传与下载 MVC文件上传与下载 想想自己从毕业到工作也有一年多,以前公司的任务的比较重,项目中有的时候需要用到什么东西都去搜索一下,基础知识感觉还没有以前在学校中的好.最近开始写博客,真的 ...

  7. USBWebserver v8.6 PHP环境

    USBWebserver v8.6 Welcome on usbwebserver.com/net/eu USBWebserver v8.6 New in this version New langu ...

  8. [google面试CTCI] 1-8.判断子字符串

    [字符串与数组] Q:Assume you have a method isSubstring which checks if one word is a substring of another G ...

  9. SharePoint RBS 安装(集成Office Web Apps)

    前言 本文完全原创,转载请说明出处,希望对大家有用. 本篇博客是个人总结,一方面以便日后查看,另一方面希望能为其他人提供一些便利. 阅读目录 安装RBS 为多个内容数据库开启RBS 正文 目的:在Sh ...

  10. phantomjs初次认识

    phantomjs初次认识 最近没什么重要的任务,就抽空看了看项目组爬虫小组的代码,因为我们的爬虫主要是以python的scrapy框架为主,看起来比较方便.在看代码的时候看到一个叫phantomjs ...