首页 > 代码库 > cf749 D. Leaving Auction

cf749 D. Leaving Auction

 1 #include<bits/stdc++.h>
 2 #define lowbit(x) x&(-x) 
 3 #define LL long long 
 4 #define N 200005
 5 #define M 1000005
 6 #define mod 1000000007LL
 7 #define inf 0x7ffffffff
 8 using namespace std;
 9 inline int ra()
10 {
11     int x=0,f=1; char ch=getchar();
12     while (ch<0 || ch>9){if (ch==-) f=-1; ch=getchar();}
13     while (ch>=0 && ch<=9){x=x*10+ch-0; ch=getchar();}
14     return x*f;
15 }
16 vector<int> man[N];
17 int mx[N],person[N];
18 bool cmp(int a, int b)
19 {
20     return mx[a]<mx[b];
21 }
22 int main()
23 {
24     int n=ra();
25     for (int i=1; i<=n; i++)
26     {
27         int a=ra(),b=ra();
28         man[a].push_back(b);
29         mx[a]=b;
30         person[i]=i;
31     }
32     sort(person+1,person+1+n,cmp);
33     int q=ra();
34     while (q--)
35     {
36         set<int> leave;
37         int k=ra();
38         for (int i=1; i<=k; i++)
39         {
40             int t=ra();
41             leave.insert(t);
42         }
43         int tmp[2],num=0;
44         tmp[0]=tmp[1]=0;
45         for (int i=n; i>=1; i--)
46         {
47             if (leave.count(person[i])) continue;
48             tmp[num++]=person[i];
49             if (num==2) break;
50         }
51         if (man[tmp[0]].size()==0)
52         {
53             cout<<"0 0"<<endl;
54             continue;
55         }
56         if (num==2)
57         {
58             int it=*lower_bound(man[tmp[0]].begin(),man[tmp[0]].end(),mx[tmp[1]]);
59             printf("%d %d\n",tmp[0],it);
60         }
61         else if (num==1)
62             printf("%d %d\n",tmp[0],man[tmp[0]][0]);
63     }
64     return 0;
65 }
66 //真是尴尬了一开始,竟然觉得找个最大的就可以了2333
67 //没想到只是比第二大最大的大就可以,真是已经弱智了。
68 //第一次发现vector还可以用lower_bound玩2333 

 

cf749 D. Leaving Auction