Submission #600795

# Submission time Handle Problem Language Result Execution time Memory
600795 2022-07-21T07:51:30 Z 장태환(#8468) Arranging Tickets (JOI17_arranging_tickets) C++17
45 / 100
4248 ms 8620 KB
#include <bits/stdc++.h>
using namespace std;
int stree[1<<20];
int lazy[1<<20];
int treeN;
void ul(int n)
{
    stree[n]+=lazy[n];
    if(n<treeN)
    {
        lazy[n*2]+=lazy[n];
        lazy[n*2+1]+=lazy[n];
    }
    lazy[n]=0;
}
void upd(int qs,int qe,int p,int s=0,int e=treeN-1,int i=1)
{
    ul(i);
    if(s>qe||qs>e)
    return;
    if(qs<=s&&e<=qe)
    {
        lazy[i]+=p;
        ul(i);
        return;
    }
    upd(qs,qe,p,s,(s+e)/2,i*2);
    upd(qs,qe,p,(s+e)/2+1,e,i*2+1);
    stree[i]=max(stree[i*2],stree[i*2+1]);
}
int arr[100100][2];
bool v[100100];
int main()
{
    int N,M;
    cin >>N>>M;
    for(treeN=1;treeN<N;treeN*=2);
    int i;
    random_device rd;
    mt19937 gen(rd());
    uniform_int_distribution<int> d(0,M-1);
    int RT=10;
    int mi=1<<30;
    while(RT--)
    {
        memset(stree,0,sizeof(stree));
        memset(lazy,0,sizeof(lazy));
        memset(v,0,sizeof(v));
        for(i=0;i<M;i++)
    {
        int a;
        if(RT==9)
            cin >>arr[i][0]>>arr[i][1]>>a;
        if(RT==9&&arr[i][0]>arr[i][1])
            swap(arr[i][0],arr[i][1]);
        if(RT==9)
            arr[i][1]--;
        upd(arr[i][0],arr[i][1],1);
        if(d(gen)%2)
        {
            v[i]=1;
            upd(arr[i][0],arr[i][1],-2);
            upd(0,N-1,1);
        }
    }

    int T=300000;

    int c=0;
    while(T--)
    {
        int a=d(gen);
        int b=stree[1];

        if(v[a])
        {
            upd(arr[a][0],arr[a][1],2);
            upd(0,N-1,-1);
        }
        else
        {
            upd(arr[a][0],arr[a][1],-2);
            upd(0,N-1,1);
        }
        v[a]=1-v[a];
        mi=min(mi,b);
        if(stree[1]>b)
        {
            c++;
            if(d(gen)<=c/M)
                continue;
            if(v[a])
            {
                upd(arr[a][0],arr[a][1],2);
                upd(0,N-1,-1);
            }
            else
            {
                upd(arr[a][0],arr[a][1],-2);
                upd(0,N-1,1);
            }
            v[a]=1-v[a];
            }
            else
            {
                c=0;
            }
        }

    }
    cout <<mi;

}
# Verdict Execution time Memory Grader output
1 Correct 1416 ms 8596 KB Output is correct
2 Correct 1427 ms 8592 KB Output is correct
3 Correct 1283 ms 8592 KB Output is correct
4 Correct 1259 ms 8592 KB Output is correct
5 Correct 1114 ms 8592 KB Output is correct
6 Correct 1126 ms 8592 KB Output is correct
7 Correct 1228 ms 8592 KB Output is correct
8 Correct 1154 ms 8592 KB Output is correct
9 Correct 1051 ms 8532 KB Output is correct
10 Correct 1181 ms 8588 KB Output is correct
11 Correct 1116 ms 8588 KB Output is correct
12 Correct 1220 ms 8592 KB Output is correct
13 Correct 1082 ms 8596 KB Output is correct
14 Correct 1289 ms 8596 KB Output is correct
15 Correct 1081 ms 8596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1416 ms 8596 KB Output is correct
2 Correct 1427 ms 8592 KB Output is correct
3 Correct 1283 ms 8592 KB Output is correct
4 Correct 1259 ms 8592 KB Output is correct
5 Correct 1114 ms 8592 KB Output is correct
6 Correct 1126 ms 8592 KB Output is correct
7 Correct 1228 ms 8592 KB Output is correct
8 Correct 1154 ms 8592 KB Output is correct
9 Correct 1051 ms 8532 KB Output is correct
10 Correct 1181 ms 8588 KB Output is correct
11 Correct 1116 ms 8588 KB Output is correct
12 Correct 1220 ms 8592 KB Output is correct
13 Correct 1082 ms 8596 KB Output is correct
14 Correct 1289 ms 8596 KB Output is correct
15 Correct 1081 ms 8596 KB Output is correct
16 Correct 2583 ms 8596 KB Output is correct
17 Correct 2868 ms 8600 KB Output is correct
18 Correct 2703 ms 8596 KB Output is correct
19 Correct 2527 ms 8596 KB Output is correct
20 Correct 2844 ms 8600 KB Output is correct
21 Correct 2691 ms 8600 KB Output is correct
22 Correct 2556 ms 8600 KB Output is correct
23 Correct 2360 ms 8596 KB Output is correct
24 Correct 2311 ms 8600 KB Output is correct
25 Correct 2200 ms 8596 KB Output is correct
26 Correct 2413 ms 8596 KB Output is correct
27 Correct 2539 ms 8592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1416 ms 8596 KB Output is correct
2 Correct 1427 ms 8592 KB Output is correct
3 Correct 1283 ms 8592 KB Output is correct
4 Correct 1259 ms 8592 KB Output is correct
5 Correct 1114 ms 8592 KB Output is correct
6 Correct 1126 ms 8592 KB Output is correct
7 Correct 1228 ms 8592 KB Output is correct
8 Correct 1154 ms 8592 KB Output is correct
9 Correct 1051 ms 8532 KB Output is correct
10 Correct 1181 ms 8588 KB Output is correct
11 Correct 1116 ms 8588 KB Output is correct
12 Correct 1220 ms 8592 KB Output is correct
13 Correct 1082 ms 8596 KB Output is correct
14 Correct 1289 ms 8596 KB Output is correct
15 Correct 1081 ms 8596 KB Output is correct
16 Correct 2583 ms 8596 KB Output is correct
17 Correct 2868 ms 8600 KB Output is correct
18 Correct 2703 ms 8596 KB Output is correct
19 Correct 2527 ms 8596 KB Output is correct
20 Correct 2844 ms 8600 KB Output is correct
21 Correct 2691 ms 8600 KB Output is correct
22 Correct 2556 ms 8600 KB Output is correct
23 Correct 2360 ms 8596 KB Output is correct
24 Correct 2311 ms 8600 KB Output is correct
25 Correct 2200 ms 8596 KB Output is correct
26 Correct 2413 ms 8596 KB Output is correct
27 Correct 2539 ms 8592 KB Output is correct
28 Correct 4185 ms 8620 KB Output is correct
29 Correct 4248 ms 8620 KB Output is correct
30 Correct 3773 ms 8616 KB Output is correct
31 Correct 3489 ms 8620 KB Output is correct
32 Correct 3475 ms 8616 KB Output is correct
33 Incorrect 3588 ms 8616 KB Output isn't correct
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1416 ms 8596 KB Output is correct
2 Correct 1427 ms 8592 KB Output is correct
3 Correct 1283 ms 8592 KB Output is correct
4 Correct 1259 ms 8592 KB Output is correct
5 Correct 1114 ms 8592 KB Output is correct
6 Correct 1126 ms 8592 KB Output is correct
7 Correct 1228 ms 8592 KB Output is correct
8 Correct 1154 ms 8592 KB Output is correct
9 Correct 1051 ms 8532 KB Output is correct
10 Correct 1181 ms 8588 KB Output is correct
11 Correct 1116 ms 8588 KB Output is correct
12 Correct 1220 ms 8592 KB Output is correct
13 Correct 1082 ms 8596 KB Output is correct
14 Correct 1289 ms 8596 KB Output is correct
15 Correct 1081 ms 8596 KB Output is correct
16 Correct 2583 ms 8596 KB Output is correct
17 Correct 2868 ms 8600 KB Output is correct
18 Correct 2703 ms 8596 KB Output is correct
19 Correct 2527 ms 8596 KB Output is correct
20 Correct 2844 ms 8600 KB Output is correct
21 Correct 2691 ms 8600 KB Output is correct
22 Correct 2556 ms 8600 KB Output is correct
23 Correct 2360 ms 8596 KB Output is correct
24 Correct 2311 ms 8600 KB Output is correct
25 Correct 2200 ms 8596 KB Output is correct
26 Correct 2413 ms 8596 KB Output is correct
27 Correct 2539 ms 8592 KB Output is correct
28 Correct 4185 ms 8620 KB Output is correct
29 Correct 4248 ms 8620 KB Output is correct
30 Correct 3773 ms 8616 KB Output is correct
31 Correct 3489 ms 8620 KB Output is correct
32 Correct 3475 ms 8616 KB Output is correct
33 Incorrect 3588 ms 8616 KB Output isn't correct
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1416 ms 8596 KB Output is correct
2 Correct 1427 ms 8592 KB Output is correct
3 Correct 1283 ms 8592 KB Output is correct
4 Correct 1259 ms 8592 KB Output is correct
5 Correct 1114 ms 8592 KB Output is correct
6 Correct 1126 ms 8592 KB Output is correct
7 Correct 1228 ms 8592 KB Output is correct
8 Correct 1154 ms 8592 KB Output is correct
9 Correct 1051 ms 8532 KB Output is correct
10 Correct 1181 ms 8588 KB Output is correct
11 Correct 1116 ms 8588 KB Output is correct
12 Correct 1220 ms 8592 KB Output is correct
13 Correct 1082 ms 8596 KB Output is correct
14 Correct 1289 ms 8596 KB Output is correct
15 Correct 1081 ms 8596 KB Output is correct
16 Correct 2583 ms 8596 KB Output is correct
17 Correct 2868 ms 8600 KB Output is correct
18 Correct 2703 ms 8596 KB Output is correct
19 Correct 2527 ms 8596 KB Output is correct
20 Correct 2844 ms 8600 KB Output is correct
21 Correct 2691 ms 8600 KB Output is correct
22 Correct 2556 ms 8600 KB Output is correct
23 Correct 2360 ms 8596 KB Output is correct
24 Correct 2311 ms 8600 KB Output is correct
25 Correct 2200 ms 8596 KB Output is correct
26 Correct 2413 ms 8596 KB Output is correct
27 Correct 2539 ms 8592 KB Output is correct
28 Correct 4185 ms 8620 KB Output is correct
29 Correct 4248 ms 8620 KB Output is correct
30 Correct 3773 ms 8616 KB Output is correct
31 Correct 3489 ms 8620 KB Output is correct
32 Correct 3475 ms 8616 KB Output is correct
33 Incorrect 3588 ms 8616 KB Output isn't correct
34 Halted 0 ms 0 KB -