Штуки
Some checks failed
Build and Push Docker Images / build (src/LiquidCode.Tester.Gateway/Dockerfile, git.nullptr.top/liquidcode/liquidcode-tester-gateway-roman, gateway) (push) Successful in 1m12s
Build and Push Docker Images / build (src/LiquidCode.Tester.Worker/Dockerfile, git.nullptr.top/liquidcode/liquidcode-tester-worker-roman, worker) (push) Has been cancelled
Some checks failed
Build and Push Docker Images / build (src/LiquidCode.Tester.Gateway/Dockerfile, git.nullptr.top/liquidcode/liquidcode-tester-gateway-roman, gateway) (push) Successful in 1m12s
Build and Push Docker Images / build (src/LiquidCode.Tester.Worker/Dockerfile, git.nullptr.top/liquidcode/liquidcode-tester-worker-roman, worker) (push) Has been cancelled
This commit is contained in:
62
exam-queue-17/solutions/nyatl_ok.cpp
Normal file
62
exam-queue-17/solutions/nyatl_ok.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define MAX 101000
|
||||
|
||||
int n, k;
|
||||
int a[MAX];
|
||||
map<int, int> nxt;
|
||||
map<int, int> prv;
|
||||
|
||||
int main() {
|
||||
scanf("%d %d", &n, &k);
|
||||
for (int i = 1; i <= n; i++) {
|
||||
scanf("%d", &a[i]);
|
||||
}
|
||||
for (int i = 1; i < n; i++) {
|
||||
nxt[a[i]] = a[i + 1];
|
||||
}
|
||||
for (int i = 2; i <= n; i++) {
|
||||
prv[a[i]] = a[i - 1];
|
||||
}
|
||||
int last = a[n];
|
||||
for (int i = 1; i <= k; i++) {
|
||||
int type;
|
||||
scanf("%d", &type);
|
||||
if (type == 1) {
|
||||
int x, y;
|
||||
scanf("%d %d", &x, &y);
|
||||
tie(nxt[x], prv[x], nxt[prv[y]], prv[y]) = {y, prv[y], x, x};
|
||||
} else if (type == 2) {
|
||||
int x;
|
||||
scanf("%d", &x);
|
||||
nxt[last] = x;
|
||||
prv[x] = last;
|
||||
last = x;
|
||||
} else if (type == 3) {
|
||||
int x;
|
||||
scanf("%d", &x);
|
||||
tie(nxt[prv[x]], prv[nxt[x]]) = {nxt[x], prv[x]};
|
||||
if (last == x) last = prv[x];
|
||||
nxt[x] = prv[x] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
vector<int> ans;
|
||||
int x = last;
|
||||
while (x != 0) {
|
||||
ans.push_back(x);
|
||||
x = prv[x];
|
||||
}
|
||||
printf("%d\n", (int)ans.size());
|
||||
for (int i = (int)ans.size() - 1; i >= 0; i--) {
|
||||
printf("%d ", ans[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user