Submission #957901

# Submission time Handle Problem Language Result Execution time Memory
957901 2024-04-04T12:56:40 Z sleepntsheep Abracadabra (CEOI22_abracadabra) C
100 / 100
512 ms 42072 KB
#include<stdio.h>
#include<stdlib.h>

#define N 200004
int n,a[N],t[N],q,sz[N],at[N],*eh[N],eo[N],zz[1000005],nxt[N];

void upd(int p,int k) { for(;p<N;p|=p+1)t[p]+=k; }
int qry(int p) {int z=0;for(;p>0;p&=p-1)z+=t[p-1];return z;}

void add(int p,int k) { sz[p]=k; upd(p,k); }
void rem(int p) { upd(p,-sz[p]); }

int grp(int x)
{
    int p=0,v=0;
    for(int j=1<<19;j>0;j>>=1) if(p+j<=N&&v+t[p+j-1]<x)p+=j,v+=t[p-1];
    return p;
}

void append(int i,int j)
{
    int o=eo[i]++;
    if(o>=2&&(o&o-1)==0)eh[i]=(int*)realloc(eh[i],2*o*sizeof**eh);
    eh[i][o]=j;
}

void shuffle()
{
    int g1=grp(n/2),g2=grp(n/2+1);
    if(g1!=g2)return;
    int rl=qry(g1);
    int st=at[g1];
    int md=n/2-rl+at[g1];
    int ed=at[g1]+sz[g1];
    for(int j=md;j<ed;j=nxt[j])add(a[j],(ed<nxt[j]?ed:nxt[j])-j);
    rem(g1);
    add(g1,n/2-rl);
}

int main()
{
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;++i)scanf("%d",a+i),at[a[i]]=i;

    {
        static int s[N];int so=0;
        for(int i=1;i<=n;++i)
        {
            while(so&&a[i]>a[s[so]])nxt[s[so--]]=i;
            s[++so]=i;
        }
        while(so)nxt[s[so--]]=n+1;
        for(int i=1;i<=n;i=nxt[i])add(a[i],nxt[i]-i);
    }

    for(int i=0;i<=n;++i)eh[i]=(int*)malloc(2*sizeof**eh);

    for(int t,p,i=0;i<q;++i)
    {
        scanf("%d%d",&t,&p);
        if(t>n)t=n;
        append(t,i),append(t,p);
    }

    for(int i=0;i<=n;++i)
    {
        for(int j=0;j<eo[i];j+=2)
        {
            int gg=grp(eh[i][j+1]);
            int idx=eh[i][j+1]-qry(gg);
            zz[eh[i][j]]=a[at[gg]+idx-1];
        }
        shuffle();
    }

    for(int i=0;i<q;++i)printf("%d\n",zz[i]);

    return 0;
}

Compilation message

Main.c: In function 'append':
Main.c:23:18: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   23 |     if(o>=2&&(o&o-1)==0)eh[i]=(int*)realloc(eh[i],2*o*sizeof**eh);
      |                 ~^~
Main.c: In function 'shuffle':
Main.c:32:9: warning: unused variable 'st' [-Wunused-variable]
   32 |     int st=at[g1];
      |         ^~
Main.c: In function 'main':
Main.c:42:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d%d",&n,&q);
      |     ^~~~~~~~~~~~~~~~~~~
Main.c:43:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     for(int i=1;i<=n;++i)scanf("%d",a+i),at[a[i]]=i;
      |                          ^~~~~~~~~~~~~~~
Main.c:60:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         scanf("%d%d",&t,&p);
      |         ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 269 ms 26960 KB Output is correct
2 Correct 272 ms 25616 KB Output is correct
3 Correct 261 ms 24976 KB Output is correct
4 Correct 269 ms 24344 KB Output is correct
5 Correct 262 ms 26964 KB Output is correct
6 Correct 268 ms 27476 KB Output is correct
7 Correct 278 ms 28420 KB Output is correct
8 Correct 276 ms 25972 KB Output is correct
9 Correct 249 ms 25364 KB Output is correct
10 Correct 252 ms 24660 KB Output is correct
11 Correct 264 ms 24996 KB Output is correct
12 Correct 247 ms 23064 KB Output is correct
13 Correct 264 ms 23868 KB Output is correct
14 Correct 264 ms 26704 KB Output is correct
15 Correct 269 ms 24240 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 251 ms 23020 KB Output is correct
18 Correct 236 ms 22800 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 332 ms 38832 KB Output is correct
2 Correct 315 ms 37804 KB Output is correct
3 Correct 255 ms 33104 KB Output is correct
4 Correct 281 ms 33532 KB Output is correct
5 Correct 256 ms 34388 KB Output is correct
6 Correct 262 ms 32856 KB Output is correct
7 Correct 295 ms 37460 KB Output is correct
8 Correct 313 ms 36084 KB Output is correct
9 Correct 279 ms 32848 KB Output is correct
10 Correct 304 ms 35648 KB Output is correct
11 Correct 241 ms 32636 KB Output is correct
12 Correct 257 ms 32336 KB Output is correct
13 Correct 306 ms 35084 KB Output is correct
14 Correct 246 ms 32336 KB Output is correct
15 Correct 318 ms 36668 KB Output is correct
16 Correct 39 ms 12892 KB Output is correct
17 Correct 299 ms 34504 KB Output is correct
18 Correct 259 ms 32076 KB Output is correct
19 Correct 102 ms 19148 KB Output is correct
20 Correct 103 ms 19724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 13560 KB Output is correct
2 Correct 64 ms 13536 KB Output is correct
3 Correct 58 ms 13436 KB Output is correct
4 Correct 55 ms 13340 KB Output is correct
5 Correct 63 ms 13512 KB Output is correct
6 Correct 55 ms 13392 KB Output is correct
7 Correct 58 ms 13576 KB Output is correct
8 Correct 55 ms 13304 KB Output is correct
9 Correct 59 ms 13392 KB Output is correct
10 Correct 50 ms 13396 KB Output is correct
11 Correct 52 ms 13648 KB Output is correct
12 Correct 50 ms 13580 KB Output is correct
13 Correct 50 ms 13400 KB Output is correct
14 Correct 51 ms 13668 KB Output is correct
15 Correct 52 ms 13404 KB Output is correct
16 Correct 22 ms 8796 KB Output is correct
17 Correct 52 ms 13108 KB Output is correct
18 Correct 50 ms 13436 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 269 ms 26960 KB Output is correct
2 Correct 272 ms 25616 KB Output is correct
3 Correct 261 ms 24976 KB Output is correct
4 Correct 269 ms 24344 KB Output is correct
5 Correct 262 ms 26964 KB Output is correct
6 Correct 268 ms 27476 KB Output is correct
7 Correct 278 ms 28420 KB Output is correct
8 Correct 276 ms 25972 KB Output is correct
9 Correct 249 ms 25364 KB Output is correct
10 Correct 252 ms 24660 KB Output is correct
11 Correct 264 ms 24996 KB Output is correct
12 Correct 247 ms 23064 KB Output is correct
13 Correct 264 ms 23868 KB Output is correct
14 Correct 264 ms 26704 KB Output is correct
15 Correct 269 ms 24240 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 251 ms 23020 KB Output is correct
18 Correct 236 ms 22800 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4524 KB Output is correct
21 Correct 332 ms 38832 KB Output is correct
22 Correct 315 ms 37804 KB Output is correct
23 Correct 255 ms 33104 KB Output is correct
24 Correct 281 ms 33532 KB Output is correct
25 Correct 256 ms 34388 KB Output is correct
26 Correct 262 ms 32856 KB Output is correct
27 Correct 295 ms 37460 KB Output is correct
28 Correct 313 ms 36084 KB Output is correct
29 Correct 279 ms 32848 KB Output is correct
30 Correct 304 ms 35648 KB Output is correct
31 Correct 241 ms 32636 KB Output is correct
32 Correct 257 ms 32336 KB Output is correct
33 Correct 306 ms 35084 KB Output is correct
34 Correct 246 ms 32336 KB Output is correct
35 Correct 318 ms 36668 KB Output is correct
36 Correct 39 ms 12892 KB Output is correct
37 Correct 299 ms 34504 KB Output is correct
38 Correct 259 ms 32076 KB Output is correct
39 Correct 102 ms 19148 KB Output is correct
40 Correct 103 ms 19724 KB Output is correct
41 Correct 62 ms 13560 KB Output is correct
42 Correct 64 ms 13536 KB Output is correct
43 Correct 58 ms 13436 KB Output is correct
44 Correct 55 ms 13340 KB Output is correct
45 Correct 63 ms 13512 KB Output is correct
46 Correct 55 ms 13392 KB Output is correct
47 Correct 58 ms 13576 KB Output is correct
48 Correct 55 ms 13304 KB Output is correct
49 Correct 59 ms 13392 KB Output is correct
50 Correct 50 ms 13396 KB Output is correct
51 Correct 52 ms 13648 KB Output is correct
52 Correct 50 ms 13580 KB Output is correct
53 Correct 50 ms 13400 KB Output is correct
54 Correct 51 ms 13668 KB Output is correct
55 Correct 52 ms 13404 KB Output is correct
56 Correct 22 ms 8796 KB Output is correct
57 Correct 52 ms 13108 KB Output is correct
58 Correct 50 ms 13436 KB Output is correct
59 Correct 1 ms 4444 KB Output is correct
60 Correct 1 ms 4440 KB Output is correct
61 Correct 512 ms 40228 KB Output is correct
62 Correct 476 ms 42072 KB Output is correct
63 Correct 442 ms 39932 KB Output is correct
64 Correct 385 ms 40532 KB Output is correct
65 Correct 386 ms 42052 KB Output is correct
66 Correct 392 ms 40464 KB Output is correct
67 Correct 349 ms 40728 KB Output is correct
68 Correct 358 ms 39504 KB Output is correct
69 Correct 352 ms 41304 KB Output is correct
70 Correct 343 ms 32116 KB Output is correct
71 Correct 310 ms 34792 KB Output is correct
72 Correct 369 ms 32596 KB Output is correct
73 Correct 344 ms 33736 KB Output is correct
74 Correct 338 ms 35012 KB Output is correct
75 Correct 352 ms 33832 KB Output is correct
76 Correct 40 ms 12112 KB Output is correct
77 Correct 391 ms 29780 KB Output is correct
78 Correct 312 ms 30200 KB Output is correct
79 Correct 1 ms 4440 KB Output is correct
80 Correct 1 ms 4440 KB Output is correct