#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 100007;
const ll inf = 2e9;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-6;
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;
ll n, q, pos[5][M], mx[M], seg[4 * M], lazy[4 * M];
void push(int node, int l, int r){
if(lazy[node]){
seg[node] += lazy[node];
if(l != r){
lazy[2 * node] += lazy[node];
lazy[2 * node + 1] += lazy[node];
}
lazy[node] = 0;
}
return;
}
void upd(int st, int en, int v, int node = 1, int l = 0, int r = n){
push(node, l, r);
if(l > en || r < st) return;
if(l >= st && r <= en){
lazy[node] += v;
push(node, l, r);
return;
}
int mid = (l + r) / 2;
upd(st, en, v, 2 * node, l, mid);
upd(st, en, v, 2 * node + 1, mid + 1, r);
seg[node] = min(seg[2 * node], seg[2 * node + 1]);
return;
}
ll get(int pos, int node = 1, int l = 0, int r = n){
if(l > pos) return inf;
if(r <= pos) return seg[node];
int mid = (l + r) / 2;
return min(get(pos, 2 * node, l, mid), get(pos, 2 * node + 1, mid + 1, r));
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
for(int i = 1; i <= 3; ++i){
for(int j = 1; j <= n; ++j){
int x; cin >> x;
pos[i][x] = j;
mx[x] = max(mx[x], 1ll * j);
}
}
upd(0, 0, inf);
for(int i = 1; i <= n; ++i){
upd(mx[i], n, -1);
upd(i, i, i);
}
while(q--){
int type;
cin >> type;
if(type == 1){
int x;
cin >> x;
if(get(mx[x] - 1)) cout << "DA\n";
else cout << "NE\n";
}
else{
int k, x, y;
cin >> k >> x >> y;
upd(mx[x], n, 1); upd(mx[y], n, 1);
swap(pos[k][x], pos[k][y]);
mx[x] = mx[y] = 0;
for(int i = 1; i <= 3; ++i){
mx[x] = max(mx[x], pos[i][x]);
mx[y] = max(mx[y], pos[i][y]);
}
upd(mx[x], n, -1); upd(mx[y], n, -1);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
134 ms |
10312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |