C. 竞拍问题–还是签到
A市举办了一个盛大的拍卖会,一共有N个人参加这个拍卖会。拍卖会的规则十分的简单,就是价格出的最高的人拍下展品。总共给出了
M个出价,当然,有一些人因为竞价会多次出价,而有一些人则纯粹饱饱眼福,不会出价。
每个出价都是由两个整数ai,bi定义的,ai表示出价人的编号,bi表示出价人的报价。给出的所有ai,bi都按照时间排序。有一些情况是一定的,即每个人的出价都比他之前的人的出价要高。此外,一个人不可能更新自己的出价,即他出过一次价后,在别人没有出价的情况下,又出一次价。
当然这样最后让你求出是谁赢得了拍卖会以及拍下的价格这未必也太简单了,所以要稍微转换一下,如果我去掉一些出价人,那么最后赢得展品的是谁,他赢得展品的出价又是多少呢?删去一些人指的是在出价表中去掉这些人所有的出价信息,此外,删去一些人可能会导致有不正常的出价表,则按照上面给出的情况处理。
Input
输入包含多个案例。
每个案例第一行包含一个个整数M,(1<=M<=2e5) 表示总共的出价M次。
接下来有M行,每行两个数,ai (1<=ai,bi<=2e5) ,bi,ai表示出价人的编号,bi表示出价人的报价。
接下来一行包括一个整数Q (1<=Q<=1e5),表示有Q个询问。
接下来有Q行,每行以一个整数K (1<=Q<=1e5) 开头,表示要删掉K人,接着跟K个整数,ki,表示删掉人的编号。
题目保证,所有案例的K的和不会超过200000。
Output
对于每一个案例,输出Q行,每行有两个数,ans1,ans2,代表出价人的编号以及他赢得展品的报价。如果没有人赢得,则输出”0 0”。
Sample Input
4
1 3
2 7
1 8
3 10
6
1 1
1 2
1 3
2 2 3
2 2 4
4 1 2 3 4
Sample Output
3 10
3 10
1 8
1 3
3 10
0 0
Powered by NIT ACM Team | C
蛇皮模拟,我写的好臭;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<functional>
using namespace std;
const int MAX = 999999;
const double Eps = 1e-12;
const double PI = acos(-1.0);
int gcd(int x, int y)
{
return x%y == 0 ? y : gcd(y, x%y);
}
typedef long long ll;
struct node
{
int a, b;
}num[200100];
int stu[200100] = { 0 };
int x[200100];
int main()
{
int n;
while (~scanf("%d", &n))
{
int pp = 0;
for (int i = 0; i < n; i++)
{
scanf("%d %d", &num[i].a, &num[i].b);
// if (num[i].a > pp)
//pp = num[i].a;
}
int k, t;
scanf("%d", &k);
while (k--)
{
int a1 = MAX, a2 = MAX, b1 = MAX, b2 = MAX;
scanf("%d", &t);
for (int i = 0; i < t; i++)
{
scanf("%d", &x[i]);
stu[x[i]] = 1;
}
int flag = 0, flag2 = 0;
int pos = MAX;
for (int i = n - 1; i >= 0; i--)
{
if (!stu[num[i].a])
{
if (!flag)
{
a1 = num[i].a;
a2 = num[i].b;
flag = 1;
}
else
{
if (a1 == num[i].a)
a2 = num[i].b;
else
{
pos = i;
break;
}
}
}
}
if (pos != MAX)
{
for (int i = pos; i >= 0; i--)
{
if (!flag2)
{
b1 = num[i].a;
b2 = num[i].b;
flag2 = 1;
}
else
{
if (b1 == num[i].a)
b2 = num[i].b;
else
{
break;
}
}
}
}
for(int i=0;i<t;i++)
stu[x[i]] = 0;
if (a2 == b2)
puts("0 0");
else
{
printf("%d %d\n", a1, a2);
}
}
}
return 0;
}
队友的代码
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
using namespace std;
const int maxn = 10 + (1e5);
int num[maxn];
int val[maxn];
int main()
{
int n;
set<int>se;
while (scanf("%d", &n) != EOF)
{
for (int i = 0; i < n; i++)
{
int q, p;
scanf("%d%d", &p, &q);
num[i] = p;
val[i] = q;
}
int m;
scanf("%d", &m);
while (m--)
{
se.clear();
int ge = 0;
scanf("%d", &ge);
int k= 0;
for (int i = 0; i < ge; i++)
{
scanf("%d", &k);
se.insert(k);
}
int nout = 0;
int vout = 0;
int sy=0;
for (int i = n - 1; i >= 0; i--)
if (se.count(num[i]) == 0)
{
sy = num[i];
break;
}
for (int i = n-1; i >=0; i--)
{
if (se.count(num[i]) == 0)
{
if (sy != num[i])
goto end;
nout = num[i];
vout = val[i];
sy = num[i];
}
}end:int mdzz;
printf("%d %d\n", nout, vout);
}
}
}