Description
Input
Output
Sample Input
10000 12
2 1
3
2 9999
3
1 1
3
2 1
3
2 10000
3
2 9999
3
Sample Output
1
9999 1
9999
9999
10000 9999
9999 10000
做法: 暴力模拟即可
代码如下:
#include <cstdio>
#include <cstring>
#include <iostream>
#define N 270
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define dep(i, a, b) for (int i = a; i >= b; i--)
#define ll long long
using namespace std;
ll n, m, a[N], s[N], st, tot;
ll x, y;
void print()
{
tot = 0;
rep(i, 1, m + 3)
if (a[i] != 0 && tot < 20) cout << a[i] << " ", tot++;
cout << endl;
}
int main()
{
freopen("problem.in", "r", stdin);
freopen("problem.out", "w", stdout);
cin >> n >> m;
rep(p, 1, m)
{
cin >> x;
if (x == 3) print();
else
{
cin >> y;
if (x == 1)
{
bool b = 1;
rep(i, 1, st)
if (s[i] == y) b = 0;
if (b) s[++st] = y;
rep(i, 1, m + 10)
if (a[i] == y) a[i] = 0;
}
else if (x == 2)
{
bool b = 1;
rep(i, 1, st)
if (s[i] == y) b = 0;
if (!b) continue;
int j = 0;
rep(i, 1, m + 3)
if (a[i] == y) a[i] = 0;
rep(i, 1, m + 3)
if (a[i] != 0)
{
j = i;
break;
}
if (j == 0) j = m + 3;
a[j - 1] = y;
}
}
}
fclose(stdin);
fclose(stdout);
return 0;
}