Submission #448693

# Submission time Handle Problem Language Result Execution time Memory
448693 2021-07-31T17:45:02 Z MOUF_MAHMALAT Tenis (COI19_tenis) C++14
100 / 100
317 ms 4112 KB
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
using namespace std;
typedef int ll;
ll n,q,a[100009][3],x,y,t,o,u;
ll p[400009],lz[400009];
void push(ll d,ll l,ll r)
{
    p[d]+=lz[d];
    if(l<r)
    {
        lz[d*2]+=lz[d];
        lz[d*2+1]+=lz[d];
    }
    lz[d]=0;
}
void up(ll d,ll l,ll r,ll z)
{
    push(d,l,r);
    if(r<x||l>y)
        return;
    if(x<=l&&y>=r)
    {
        lz[d]+=z;
        push(d,l,r);
        return;
    }
    ll m=(l+r)/2,i=d*2;
    up(i,l,m,z),up(i+1,m+1,r,z);
    p[d]=min(p[i],p[i+1]);
}
ll best(ll d,ll l,ll r)
{
    if(l>y)
        return 1e9;
    push(d,l,r);
    if(r<=y)
        return p[d];
    ll m=(l+r)/2,i=d*2;
    return min(best(i,l,m),best(i+1,m+1,r));
}
int main()
{
    scanf("%d%d",&n,&q);
    for(ll j=0; j<3; j++)
        for(ll i=1; i<=n; i++)
        {
            scanf("%d",&x);
            a[x][j]=i;
        }
    for(ll i=1; i<=n; i++)
    {
        x=min(a[i][0],min(a[i][1],a[i][2]));
        y=max(a[i][0],max(a[i][1],a[i][2]))-1;
        up(1,1,n,1);
    }
    while(q--)
    {
        scanf("%d",&t);
        if(t==1)
        {
            scanf("%d",&x);
            y=min(a[x][0],min(a[x][1],a[x][2]))-1;
            if(best(1,1,n))
                printf("DA\n");
            else
                printf("NE\n");
            continue;
        }
        scanf("%d%d%d",&t,&o,&u),t--;
        x=min(a[o][0],min(a[o][1],a[o][2]));
        y=max(a[o][0],max(a[o][1],a[o][2]))-1;
        up(1,1,n,-1);
        x=min(a[u][0],min(a[u][1],a[u][2]));
        y=max(a[u][0],max(a[u][1],a[u][2]))-1;
        up(1,1,n,-1);

        swap(a[o][t],a[u][t]);
        x=min(a[o][0],min(a[o][1],a[o][2]));
        y=max(a[o][0],max(a[o][1],a[o][2]))-1;
        up(1,1,n,1);
        x=min(a[u][0],min(a[u][1],a[u][2]));
        y=max(a[u][0],max(a[u][1],a[u][2]))-1;
        up(1,1,n,1);
    }
    return 0;
}

Compilation message

tenis.cpp: In function 'int main()':
tenis.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     scanf("%d%d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~
tenis.cpp:48:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |             scanf("%d",&x);
      |             ~~~~~^~~~~~~~~
tenis.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         scanf("%d",&t);
      |         ~~~~~^~~~~~~~~
tenis.cpp:62:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |             scanf("%d",&x);
      |             ~~~~~^~~~~~~~~
tenis.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         scanf("%d%d%d",&t,&o,&u),t--;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 2 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 2 ms 312 KB Output is correct
13 Correct 110 ms 3788 KB Output is correct
14 Correct 100 ms 3908 KB Output is correct
15 Correct 92 ms 3908 KB Output is correct
16 Correct 93 ms 3780 KB Output is correct
17 Correct 104 ms 3800 KB Output is correct
18 Correct 96 ms 3788 KB Output is correct
19 Correct 107 ms 3792 KB Output is correct
20 Correct 119 ms 3680 KB Output is correct
21 Correct 88 ms 3780 KB Output is correct
22 Correct 91 ms 3788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 4044 KB Output is correct
2 Correct 155 ms 4056 KB Output is correct
3 Correct 159 ms 4028 KB Output is correct
4 Correct 158 ms 4048 KB Output is correct
5 Correct 149 ms 4020 KB Output is correct
6 Correct 164 ms 4048 KB Output is correct
7 Correct 155 ms 4044 KB Output is correct
8 Correct 146 ms 4044 KB Output is correct
9 Correct 156 ms 4052 KB Output is correct
10 Correct 203 ms 4016 KB Output is correct
11 Correct 152 ms 3972 KB Output is correct
12 Correct 162 ms 4048 KB Output is correct
13 Correct 163 ms 4036 KB Output is correct
14 Correct 156 ms 4036 KB Output is correct
15 Correct 150 ms 4112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 2 ms 312 KB Output is correct
13 Correct 110 ms 3788 KB Output is correct
14 Correct 100 ms 3908 KB Output is correct
15 Correct 92 ms 3908 KB Output is correct
16 Correct 93 ms 3780 KB Output is correct
17 Correct 104 ms 3800 KB Output is correct
18 Correct 96 ms 3788 KB Output is correct
19 Correct 107 ms 3792 KB Output is correct
20 Correct 119 ms 3680 KB Output is correct
21 Correct 88 ms 3780 KB Output is correct
22 Correct 91 ms 3788 KB Output is correct
23 Correct 154 ms 4044 KB Output is correct
24 Correct 155 ms 4056 KB Output is correct
25 Correct 159 ms 4028 KB Output is correct
26 Correct 158 ms 4048 KB Output is correct
27 Correct 149 ms 4020 KB Output is correct
28 Correct 164 ms 4048 KB Output is correct
29 Correct 155 ms 4044 KB Output is correct
30 Correct 146 ms 4044 KB Output is correct
31 Correct 156 ms 4052 KB Output is correct
32 Correct 203 ms 4016 KB Output is correct
33 Correct 152 ms 3972 KB Output is correct
34 Correct 162 ms 4048 KB Output is correct
35 Correct 163 ms 4036 KB Output is correct
36 Correct 156 ms 4036 KB Output is correct
37 Correct 150 ms 4112 KB Output is correct
38 Correct 304 ms 3868 KB Output is correct
39 Correct 183 ms 4060 KB Output is correct
40 Correct 317 ms 3864 KB Output is correct
41 Correct 201 ms 3900 KB Output is correct
42 Correct 206 ms 3916 KB Output is correct
43 Correct 315 ms 3972 KB Output is correct
44 Correct 177 ms 3908 KB Output is correct
45 Correct 285 ms 3888 KB Output is correct
46 Correct 182 ms 3916 KB Output is correct
47 Correct 200 ms 3992 KB Output is correct
48 Correct 211 ms 4040 KB Output is correct
49 Correct 211 ms 4064 KB Output is correct
50 Correct 187 ms 3916 KB Output is correct
51 Correct 216 ms 3908 KB Output is correct
52 Correct 291 ms 3972 KB Output is correct
53 Correct 216 ms 4016 KB Output is correct
54 Correct 204 ms 4016 KB Output is correct
55 Correct 223 ms 3912 KB Output is correct
56 Correct 207 ms 3908 KB Output is correct
57 Correct 189 ms 3920 KB Output is correct
58 Correct 232 ms 4044 KB Output is correct