Submission #1041852

# Submission time Handle Problem Language Result Execution time Memory
1041852 2024-08-02T08:44:16 Z 12345678 Tenis (COI19_tenis) C++17
100 / 100
100 ms 8072 KB
#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
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Correct 0 ms 2516 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Correct 0 ms 2516 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2464 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Correct 0 ms 2516 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2464 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2516 KB Output is correct
13 Correct 37 ms 6200 KB Output is correct
14 Correct 32 ms 5996 KB Output is correct
15 Correct 32 ms 5968 KB Output is correct
16 Correct 31 ms 5968 KB Output is correct
17 Correct 32 ms 6016 KB Output is correct
18 Correct 32 ms 5972 KB Output is correct
19 Correct 40 ms 6224 KB Output is correct
20 Correct 36 ms 5972 KB Output is correct
21 Correct 34 ms 5968 KB Output is correct
22 Correct 31 ms 5832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 5712 KB Output is correct
2 Correct 42 ms 6428 KB Output is correct
3 Correct 40 ms 6480 KB Output is correct
4 Correct 43 ms 6484 KB Output is correct
5 Correct 40 ms 6388 KB Output is correct
6 Correct 41 ms 6480 KB Output is correct
7 Correct 47 ms 6480 KB Output is correct
8 Correct 45 ms 6384 KB Output is correct
9 Correct 42 ms 6484 KB Output is correct
10 Correct 41 ms 6480 KB Output is correct
11 Correct 43 ms 6380 KB Output is correct
12 Correct 63 ms 6572 KB Output is correct
13 Correct 40 ms 6520 KB Output is correct
14 Correct 40 ms 6480 KB Output is correct
15 Correct 42 ms 6480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Correct 0 ms 2516 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2464 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2516 KB Output is correct
13 Correct 37 ms 6200 KB Output is correct
14 Correct 32 ms 5996 KB Output is correct
15 Correct 32 ms 5968 KB Output is correct
16 Correct 31 ms 5968 KB Output is correct
17 Correct 32 ms 6016 KB Output is correct
18 Correct 32 ms 5972 KB Output is correct
19 Correct 40 ms 6224 KB Output is correct
20 Correct 36 ms 5972 KB Output is correct
21 Correct 34 ms 5968 KB Output is correct
22 Correct 31 ms 5832 KB Output is correct
23 Correct 40 ms 5712 KB Output is correct
24 Correct 42 ms 6428 KB Output is correct
25 Correct 40 ms 6480 KB Output is correct
26 Correct 43 ms 6484 KB Output is correct
27 Correct 40 ms 6388 KB Output is correct
28 Correct 41 ms 6480 KB Output is correct
29 Correct 47 ms 6480 KB Output is correct
30 Correct 45 ms 6384 KB Output is correct
31 Correct 42 ms 6484 KB Output is correct
32 Correct 41 ms 6480 KB Output is correct
33 Correct 43 ms 6380 KB Output is correct
34 Correct 63 ms 6572 KB Output is correct
35 Correct 40 ms 6520 KB Output is correct
36 Correct 40 ms 6480 KB Output is correct
37 Correct 42 ms 6480 KB Output is correct
38 Correct 86 ms 5052 KB Output is correct
39 Correct 57 ms 5212 KB Output is correct
40 Correct 88 ms 5040 KB Output is correct
41 Correct 68 ms 4952 KB Output is correct
42 Correct 94 ms 7760 KB Output is correct
43 Correct 100 ms 8072 KB Output is correct
44 Correct 55 ms 7760 KB Output is correct
45 Correct 66 ms 7936 KB Output is correct
46 Correct 54 ms 7764 KB Output is correct
47 Correct 61 ms 7760 KB Output is correct
48 Correct 56 ms 7764 KB Output is correct
49 Correct 68 ms 7772 KB Output is correct
50 Correct 53 ms 7764 KB Output is correct
51 Correct 68 ms 7748 KB Output is correct
52 Correct 92 ms 7992 KB Output is correct
53 Correct 60 ms 7764 KB Output is correct
54 Correct 64 ms 7780 KB Output is correct
55 Correct 65 ms 7764 KB Output is correct
56 Correct 70 ms 7764 KB Output is correct
57 Correct 61 ms 8024 KB Output is correct
58 Correct 67 ms 7884 KB Output is correct