This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Never let them see you bleed...
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
int b[3][maxn], mx[maxn];
int val[4 * maxn], MX[4 * maxn], n;
void add(int pos, int x, int l = 0, int r = n, int id = 1){
val[id]+= x;
if(r-l == 1){
MX[id] = val[id];
return;
}
int mid = (l+r) >> 1;
if(pos < mid)
add(pos, x, l, mid, 2*id);
else
add(pos, x, mid, r, 2*id+1);
MX[id] = max(MX[2*id], val[2*id] + MX[2*id+1]);
}
int solve(int x = 0, int l = 0, int r = n, int id = 1){
if(r-l == 1)
return l;
int mid = (l+r) >> 1;
if(MX[2*id] == x)
return solve(x, l, mid, 2*id);
return solve(x - val[2*id], mid, r, 2*id+1);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
int q;
cin >> n >> q;
for(int i = 0; i < 3; i++){
for(int j = 0; j < n; j++){
int x;
cin >> x;
--x;
b[i][x] = j;
}
}
for(int i = 0; i < n; i++){
mx[i] = max({b[0][i], b[1][i], b[2][i]});
add(mx[i], 1);
add(i, -1);
}
while(q--){
int task;
cin >> task;
if(task == 1){
int x;
cin >> x;
--x;
cout << (mx[x] <= solve() ? "DA\n" : "NE\n");
}
else{
int p, x, y;
cin >> p >> x >> y;
--p, --x, --y;
add(mx[x], -1);
add(mx[y], -1);
swap(b[p][x], b[p][y]);
mx[x] = max({b[0][x], b[1][x], b[2][x]});
mx[y] = max({b[0][y], b[1][y], b[2][y]});
add(mx[x], 1);
add(mx[y], 1);
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |