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 <bits/stdc++.h>
using namespace std;
const int nx=1e5+5;
int n, q, p[4][nx], t, x, a, b, opr, mx[nx], res;
struct segtree
{
    int d[4*nx], lz[4*nx];
    void pushlz(int l, int r, int i)
    {
        d[i]+=lz[i];
        if (l!=r) lz[2*i]+=lz[i], lz[2*i+1]+=lz[i];
        lz[i]=0;
    }
    void build(int l, int r, int i)
    {
        if (l==r&&l==1) d[i]--;
        if (l==r) return d[i]-=(n-l+1), void();
        int md=(l+r)/2;
        build(l, md, 2*i);
        build(md+1, r, 2*i+1);
        d[i]=max(d[2*i], d[2*i+1]);
    }
    void update(int l, int r, int i, int ql, int qr, int vl)
    {
        pushlz(l, r, i);
        if (qr<l||r<ql) return;
        if (ql<=l&&r<=qr) return lz[i]=vl, pushlz(l, r, i), void();
        int md=(l+r)/2;
        update(l, md, 2*i ,ql, qr, vl);
        update(md+1, r, 2*i+1, ql, qr, vl);
        d[i]=max(d[2*i], d[2*i+1]);
    }
    int query(int l, int r, int i)
    {
        pushlz(l, r, i);
        if (d[i]<0) return n+1;
        if (l==r) return l;
        int md=(l+r)/2;
        pushlz(l, md, 2*i), pushlz(md+1, r, 2*i+1);
        if (d[2*i]==0) return query(l, md, 2*i);
        else return query(md+1, r, 2*i+1);
    }
    void show(int l, int r, int i)
    {
        pushlz(l, r, i);
        if (l==r) return cout<<d[i]<<' ', void();
        int md=(l+r)/2;
        show(l, md, 2*i);
        show(md+1, r, 2*i+1);
    }
} s;
int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>q;
    for (int i=1; i<=n; i++) cin>>x, p[1][x]=i;
    for (int i=1; i<=n; i++) cin>>x, p[2][x]=i;
    for (int i=1; i<=n; i++) cin>>x, p[3][x]=i;
    s.build(1, n, 1);
    //cout<<"show ";
    //s.show(1,n , 1);
    //cout<<'\n';
    for (int i=1; i<=n; i++) s.update(1, n, 1, 1, min({p[1][i], p[2][i], p[3][i]}), 1);
    //cout<<"show ";
    //s.show(1,n , 1);
    //cout<<'\n';
    res=s.query(1, n, 1);
    while (q--)
    {
        cin>>opr;
        //cout<<"debug "<<res<<'\n';
        if (opr==1) cin>>a, cout<<(min({p[1][a], p[2][a], p[3][a]})<res?"DA\n":"NE\n");
        else 
        {
            cin>>t>>a>>b;
            s.update(1, n, 1, 1, min({p[1][a], p[2][a], p[3][a]}), -1);
            s.update(1, n, 1, 1, min({p[1][b], p[2][b], p[3][b]}), -1);
            swap(p[t][a], p[t][b]);
            s.update(1, n, 1, 1, min({p[1][a], p[2][a], p[3][a]}), 1);
            s.update(1, n, 1, 1, min({p[1][b], p[2][b], p[3][b]}), 1);
            res=s.query(1, n, 1);
        }
    }
}
| # | 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... |