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>
#include<cstdio>
#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(){
    scanf("%d%d", &n, &q);
    for(ii = 0; ii < 3; ii++){
        for(i = 1; i <= n; i++){
            scanf("%d", &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--){
        scanf("%d", &t);
        if(t == 1){
            scanf("%d", &x);
            if(poz[0][x] <= sol){
                cout<<"DA\n";
            }
            else{
                cout<<"NE\n";
            }
        }
        else{
            scanf("%d%d%d", &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);
        }
    }
}
Compilation message (stderr)
tenis.cpp: In function 'int main()':
tenis.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~
tenis.cpp:44:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &v[ii][i]);
             ~~~~~^~~~~~~~~~~~~~~~~
tenis.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &t);
         ~~~~~^~~~~~~~~~
tenis.cpp:55:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
tenis.cpp:64:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d%d", &ii, &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~| # | 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... |