This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#define DIM 100005
#define f first
#define s second
using namespace std;
int n, q, i, ii, x, y, t, sol;
int poz[3][DIM], v[3][DIM];
pair<long long, long long> aint[4 * DIM];
void update(int nod, int st, int dr, int p){
    if(st == dr){
        aint[nod].f = aint[nod].s = 2 * st - poz[0][ v[1][p] ] - poz[0][ v[2][p] ];
    }
    else{
        int mid = (st + dr) / 2;
        if(p <= mid){
            update(2 * nod, st, mid, p);
        }
        else{
            update(2 * nod + 1, mid + 1, dr, p);
        }
        aint[nod].s = aint[2 * nod].s + aint[2 * nod + 1].s;
        aint[nod].f = max(aint[2 * nod].f, aint[2 * nod + 1].f + aint[2 * nod].s);
    }
}
int query(int nod, int st, int dr){
    if(st == dr){
        return st;
    }
    else{
        int mid = (st + dr) / 2;
        if(aint[nod].f == aint[2 * nod].f){
            return query(2 * nod, st, mid);
        }
        else{
            return query(2 * nod + 1, mid + 1, dr);
        }
    }
}
int main(){
    cin>> n >> q;
    for(ii = 0; ii < 3; ii++){
        for(i = 1; i <= n; i++){
            cin>> v[ii][i];
            poz[ii][ v[ii][i] ] = i;
        }
    }
    for(i = 1; i <= n; i++){
        update(1, 1, n, i);
    }
    sol = query(1, 1, n);
    for(; q; q--){
        cin>> t;
        if(t == 1){
            cin>> x;
            if(poz[0][x] <= sol){
                cout<<"DA\n";
            }
            else{
                cout<<"NE\n";
            }
        }
        else{
            cin>> ii >> x >> y;
            ii--;
            swap(poz[ii][x], poz[ii][y]);
            v[ii][ poz[ii][x] ] = x;
            v[ii][ poz[ii][y] ] = y;
            update(1, 1, n, poz[1][x]);
            update(1, 1, n, poz[1][y]);
            update(1, 1, n, poz[2][x]);
            update(1, 1, n, poz[2][y]);
            sol = query(1, 1, n);
        }
    }
}
| # | 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... |