Submission #769782

# Submission time Handle Problem Language Result Execution time Memory
769782 2023-06-30T08:58:55 Z bgnbvnbv Tenis (COI19_tenis) C++14
100 / 100
145 ms 9916 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5;
const ll inf=1e18;
const ll mod=1e9+7;
ll lazy[4*maxN],st[4*maxN];
void down(ll id)
{
    ll &x=lazy[id];
    st[id*2]+=x;
    lazy[id*2]+=x;
    st[id*2+1]+=x;
    lazy[id*2+1]+=x;
    x=0;
}
ll n;
void update(ll i,ll j,ll v,ll id=1,ll l=2,ll r=n)
{
    if(j<l||r<i) return;
    if(i<=l&&r<=j)
    {
        st[id]+=v;
        lazy[id]+=v;
        return;
    }
    ll mid=l+r>>1;
    down(id);
    update(i,j,v,id*2,l,mid);
    update(i,j,v,id*2+1,mid+1,r);
    st[id]=min(st[id*2],st[id*2+1]);
}
ll get()
{
    ll id=1,l=2,r=n;
    if(st[1]>0) return n+1;
    while(true)
    {
        if(l==r) return l;
        ll mid=l+r>>1;
        down(id);
        if(st[id*2]>0)
        {
            id=id*2+1;
            l=mid+1;
        }
        else
        {
            id=id*2;
            r=mid;
        }
    }
}
ll q;
ll pos[5][maxN];
ll gt(ll i)
{
    ll cc=n+1;
    for(int j=1;j<=3;j++)
    {
        cc=min(cc,pos[j][i]);
    }
    return cc;
}
void solve()
{
    cin >> n >> q;
    for(int i=1;i<=3;i++)
    {
        ll x;
        for(int j=1;j<=n;j++) cin >> x,pos[i][x]=j;
    }
    for(int i=n;i>=2;i--)
    {
        update(2,i,1);
        ll cc=n+1;
    }
    for(int i=1;i<=n;i++)
    {
        ll cc=gt(i);
        update(2,cc,-1);
    }
    for(int i=1;i<=q;i++)
    {
        ll t;
        cin >> t;
        if(t==1)
        {
            ll x;
            cin >> x;
            ll vd=get();
            ll cc=gt(x);
            if(vd<=cc) cout <<"NE\n";
            else cout <<"DA\n";
        }
        else
        {
            ll j,x,y;
            cin >> j >> x >> y;
            ll cc=gt(x);
            update(2,cc,1);
            cc=gt(y);
            update(2,cc,1);
            swap(pos[j][x],pos[j][y]);
            cc=gt(x);
            update(2,cc,-1);
            cc=gt(y);
            update(2,cc,-1);
        }
    }
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

Compilation message

tenis.cpp: In function 'void update(ll, ll, ll, ll, ll, ll)':
tenis.cpp:33:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |     ll mid=l+r>>1;
      |            ~^~
tenis.cpp: In function 'll get()':
tenis.cpp:46:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |         ll mid=l+r>>1;
      |                ~^~
tenis.cpp: In function 'void solve()':
tenis.cpp:82:12: warning: unused variable 'cc' [-Wunused-variable]
   82 |         ll cc=n+1;
      |            ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 54 ms 8400 KB Output is correct
14 Correct 54 ms 8496 KB Output is correct
15 Correct 54 ms 8504 KB Output is correct
16 Correct 52 ms 8384 KB Output is correct
17 Correct 53 ms 8500 KB Output is correct
18 Correct 53 ms 8484 KB Output is correct
19 Correct 52 ms 8480 KB Output is correct
20 Correct 53 ms 8412 KB Output is correct
21 Correct 55 ms 8396 KB Output is correct
22 Correct 54 ms 8528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 9544 KB Output is correct
2 Correct 70 ms 9472 KB Output is correct
3 Correct 75 ms 9488 KB Output is correct
4 Correct 79 ms 9608 KB Output is correct
5 Correct 72 ms 9532 KB Output is correct
6 Correct 72 ms 9520 KB Output is correct
7 Correct 70 ms 9476 KB Output is correct
8 Correct 70 ms 9576 KB Output is correct
9 Correct 69 ms 9584 KB Output is correct
10 Correct 68 ms 9484 KB Output is correct
11 Correct 70 ms 9592 KB Output is correct
12 Correct 71 ms 9484 KB Output is correct
13 Correct 72 ms 9576 KB Output is correct
14 Correct 68 ms 9476 KB Output is correct
15 Correct 70 ms 9536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 54 ms 8400 KB Output is correct
14 Correct 54 ms 8496 KB Output is correct
15 Correct 54 ms 8504 KB Output is correct
16 Correct 52 ms 8384 KB Output is correct
17 Correct 53 ms 8500 KB Output is correct
18 Correct 53 ms 8484 KB Output is correct
19 Correct 52 ms 8480 KB Output is correct
20 Correct 53 ms 8412 KB Output is correct
21 Correct 55 ms 8396 KB Output is correct
22 Correct 54 ms 8528 KB Output is correct
23 Correct 72 ms 9544 KB Output is correct
24 Correct 70 ms 9472 KB Output is correct
25 Correct 75 ms 9488 KB Output is correct
26 Correct 79 ms 9608 KB Output is correct
27 Correct 72 ms 9532 KB Output is correct
28 Correct 72 ms 9520 KB Output is correct
29 Correct 70 ms 9476 KB Output is correct
30 Correct 70 ms 9576 KB Output is correct
31 Correct 69 ms 9584 KB Output is correct
32 Correct 68 ms 9484 KB Output is correct
33 Correct 70 ms 9592 KB Output is correct
34 Correct 71 ms 9484 KB Output is correct
35 Correct 72 ms 9576 KB Output is correct
36 Correct 68 ms 9476 KB Output is correct
37 Correct 70 ms 9536 KB Output is correct
38 Correct 122 ms 9836 KB Output is correct
39 Correct 82 ms 9564 KB Output is correct
40 Correct 120 ms 9916 KB Output is correct
41 Correct 92 ms 9684 KB Output is correct
42 Correct 91 ms 9780 KB Output is correct
43 Correct 116 ms 9880 KB Output is correct
44 Correct 84 ms 9676 KB Output is correct
45 Correct 102 ms 9696 KB Output is correct
46 Correct 84 ms 9684 KB Output is correct
47 Correct 94 ms 9676 KB Output is correct
48 Correct 95 ms 9560 KB Output is correct
49 Correct 93 ms 9756 KB Output is correct
50 Correct 83 ms 9600 KB Output is correct
51 Correct 90 ms 9724 KB Output is correct
52 Correct 145 ms 9852 KB Output is correct
53 Correct 87 ms 9740 KB Output is correct
54 Correct 93 ms 9708 KB Output is correct
55 Correct 91 ms 9748 KB Output is correct
56 Correct 94 ms 9676 KB Output is correct
57 Correct 89 ms 9760 KB Output is correct
58 Correct 93 ms 9680 KB Output is correct