Codeforces Round #388 (Div. 2)D. Leaving Auction(水题呀?)

Posted AC_Arthur

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #388 (Div. 2)D. Leaving Auction(水题呀?)相关的知识,希望对你有一定的参考价值。

题目链接:点击打开链接

思路:

我们只要把每个人竞价的最大值存起来, 并且把每个人的所有竞价维护在一个有序数组(方便二分), 对于一组询问,  我们从大到小遍历这k个数,把不在这k个数的最终竞价最大的两个人找到(复杂度O(K)), 然后在竞价最大的那个人的set里二分第二大的人的竞价最大值就行了。

细节参见代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <ctime>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
typedef long double ld;
const double eps = 1e-6;
const double PI = acos(-1);
const int mod = 1000000000 + 7;
const int INF = 0x3f3f3f3f;
const int seed = 131;
const ll INF64 = ll(1e18);
const int maxn = 2e5 + 10;
int T,n,m,a[maxn],b[maxn],maxv[maxn];
set<int> g[maxn];
set<int> :: iterator it;
struct node 
    int id, pos;
    node(int id=0, int pos=0):id(id), pos(pos) 
    bool operator < (const node& rhs) const 
        if(pos != rhs.pos) return pos < rhs.pos;
        else return id < rhs.id;
    
;
int main() 
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) 
        scanf("%d%d", &a[i], &b[i]);
        g[a[i]].insert(b[i]); /// 每个人拍卖的价格
        maxv[a[i]] = b[i];
    
    vector<node> res;
    for(int i = 1; i <= n; i++) 
        if(maxv[i]) res.push_back(node(i, maxv[i])); ///所有来参加竞拍的人, id和最大拍卖价格
    
    sort(res.begin(), res.end());
    int q; scanf("%d", &q);
    while(q--) 
        int k; scanf("%d", &k);
        vector<node> cur;
        for(int i = 1; i <= k; i++) 
            int v; scanf("%d", &v);
            if(maxv[v]) cur.push_back(node(v, maxv[v]));  /// 扔掉的人
        
        sort(cur.begin(), cur.end());
        int len = cur.size();
        int l1 = res.size()-1, l2 = cur.size()-1;
        vector<node> ans;
        while(true) 
            if(l1 < 0) break;
            else if(l2 < 0 && l1 >= 0) ans.push_back(res[l1]), l1--;
            else if(cur[l2].pos < res[l1].pos) ans.push_back(res[l1]), l1--;
            else if(cur[l2].pos == res[l1].pos) l1--, l2--;
            if(ans.size() >= 2) break;
        
        if(ans.size() == 0) printf("0 0\\n");
        else if(ans.size() == 1) 
            it = g[ans[0].id].begin();
            printf("%d %d\\n", ans[0].id, *it);
        
        else 
            int v = maxv[ans[1].id];
            it = g[ans[0].id].upper_bound(v);
            printf("%d %d\\n", ans[0].id, *it);
        
    
    return 0;


以上是关于Codeforces Round #388 (Div. 2)D. Leaving Auction(水题呀?)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #388 (Div. 2) A

Codeforces Round #388 (Div. 2) D

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

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

Codeforces Round #388 (Div. 2)D. Leaving Auction(水题呀?)

Codeforces Round #744 (Div. 3) A-F