답안 #957900

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957900 2024-04-04T12:55:54 Z vjudge1 Abracadabra (CEOI22_abracadabra) C++17
100 / 100
542 ms 48388 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.cpp: In function 'void append(int, int)':
Main.cpp: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.cpp: In function 'void shuffle()':
Main.cpp:32:9: warning: unused variable 'st' [-Wunused-variable]
   32 |     int st=at[g1];
      |         ^~
Main.cpp: In function 'int main()':
Main.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d%d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~
Main.cpp:43:31: warning: ignoring return value of 'int scanf(const char*, ...)' 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.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         scanf("%d%d",&t,&p);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 270 ms 22608 KB Output is correct
2 Correct 276 ms 27476 KB Output is correct
3 Correct 266 ms 27012 KB Output is correct
4 Correct 252 ms 25804 KB Output is correct
5 Correct 272 ms 29324 KB Output is correct
6 Correct 253 ms 29008 KB Output is correct
7 Correct 268 ms 30516 KB Output is correct
8 Correct 260 ms 27560 KB Output is correct
9 Correct 268 ms 26528 KB Output is correct
10 Correct 256 ms 26208 KB Output is correct
11 Correct 262 ms 26448 KB Output is correct
12 Correct 265 ms 24428 KB Output is correct
13 Correct 262 ms 25380 KB Output is correct
14 Correct 270 ms 28244 KB Output is correct
15 Correct 269 ms 25844 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 260 ms 24836 KB Output is correct
18 Correct 245 ms 24088 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 336 ms 31000 KB Output is correct
2 Correct 349 ms 44044 KB Output is correct
3 Correct 263 ms 39196 KB Output is correct
4 Correct 288 ms 38276 KB Output is correct
5 Correct 265 ms 39188 KB Output is correct
6 Correct 274 ms 37424 KB Output is correct
7 Correct 309 ms 43788 KB Output is correct
8 Correct 318 ms 42252 KB Output is correct
9 Correct 263 ms 39400 KB Output is correct
10 Correct 328 ms 41032 KB Output is correct
11 Correct 261 ms 37728 KB Output is correct
12 Correct 264 ms 36436 KB Output is correct
13 Correct 324 ms 40652 KB Output is correct
14 Correct 280 ms 37468 KB Output is correct
15 Correct 338 ms 41952 KB Output is correct
16 Correct 40 ms 13576 KB Output is correct
17 Correct 310 ms 39328 KB Output is correct
18 Correct 265 ms 35416 KB Output is correct
19 Correct 102 ms 20252 KB Output is correct
20 Correct 105 ms 21608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 12336 KB Output is correct
2 Correct 69 ms 14028 KB Output is correct
3 Correct 62 ms 13824 KB Output is correct
4 Correct 54 ms 13904 KB Output is correct
5 Correct 62 ms 13784 KB Output is correct
6 Correct 55 ms 13648 KB Output is correct
7 Correct 60 ms 13836 KB Output is correct
8 Correct 68 ms 14164 KB Output is correct
9 Correct 59 ms 13640 KB Output is correct
10 Correct 57 ms 13908 KB Output is correct
11 Correct 52 ms 14160 KB Output is correct
12 Correct 52 ms 13996 KB Output is correct
13 Correct 54 ms 13700 KB Output is correct
14 Correct 53 ms 14164 KB Output is correct
15 Correct 55 ms 13908 KB Output is correct
16 Correct 24 ms 8796 KB Output is correct
17 Correct 54 ms 13332 KB Output is correct
18 Correct 53 ms 13780 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 270 ms 22608 KB Output is correct
2 Correct 276 ms 27476 KB Output is correct
3 Correct 266 ms 27012 KB Output is correct
4 Correct 252 ms 25804 KB Output is correct
5 Correct 272 ms 29324 KB Output is correct
6 Correct 253 ms 29008 KB Output is correct
7 Correct 268 ms 30516 KB Output is correct
8 Correct 260 ms 27560 KB Output is correct
9 Correct 268 ms 26528 KB Output is correct
10 Correct 256 ms 26208 KB Output is correct
11 Correct 262 ms 26448 KB Output is correct
12 Correct 265 ms 24428 KB Output is correct
13 Correct 262 ms 25380 KB Output is correct
14 Correct 270 ms 28244 KB Output is correct
15 Correct 269 ms 25844 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 260 ms 24836 KB Output is correct
18 Correct 245 ms 24088 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 336 ms 31000 KB Output is correct
22 Correct 349 ms 44044 KB Output is correct
23 Correct 263 ms 39196 KB Output is correct
24 Correct 288 ms 38276 KB Output is correct
25 Correct 265 ms 39188 KB Output is correct
26 Correct 274 ms 37424 KB Output is correct
27 Correct 309 ms 43788 KB Output is correct
28 Correct 318 ms 42252 KB Output is correct
29 Correct 263 ms 39400 KB Output is correct
30 Correct 328 ms 41032 KB Output is correct
31 Correct 261 ms 37728 KB Output is correct
32 Correct 264 ms 36436 KB Output is correct
33 Correct 324 ms 40652 KB Output is correct
34 Correct 280 ms 37468 KB Output is correct
35 Correct 338 ms 41952 KB Output is correct
36 Correct 40 ms 13576 KB Output is correct
37 Correct 310 ms 39328 KB Output is correct
38 Correct 265 ms 35416 KB Output is correct
39 Correct 102 ms 20252 KB Output is correct
40 Correct 105 ms 21608 KB Output is correct
41 Correct 66 ms 12336 KB Output is correct
42 Correct 69 ms 14028 KB Output is correct
43 Correct 62 ms 13824 KB Output is correct
44 Correct 54 ms 13904 KB Output is correct
45 Correct 62 ms 13784 KB Output is correct
46 Correct 55 ms 13648 KB Output is correct
47 Correct 60 ms 13836 KB Output is correct
48 Correct 68 ms 14164 KB Output is correct
49 Correct 59 ms 13640 KB Output is correct
50 Correct 57 ms 13908 KB Output is correct
51 Correct 52 ms 14160 KB Output is correct
52 Correct 52 ms 13996 KB Output is correct
53 Correct 54 ms 13700 KB Output is correct
54 Correct 53 ms 14164 KB Output is correct
55 Correct 55 ms 13908 KB Output is correct
56 Correct 24 ms 8796 KB Output is correct
57 Correct 54 ms 13332 KB Output is correct
58 Correct 53 ms 13780 KB Output is correct
59 Correct 1 ms 4444 KB Output is correct
60 Correct 1 ms 4444 KB Output is correct
61 Correct 542 ms 47184 KB Output is correct
62 Correct 502 ms 48388 KB Output is correct
63 Correct 494 ms 46300 KB Output is correct
64 Correct 407 ms 46680 KB Output is correct
65 Correct 399 ms 48336 KB Output is correct
66 Correct 404 ms 46564 KB Output is correct
67 Correct 380 ms 47060 KB Output is correct
68 Correct 385 ms 45136 KB Output is correct
69 Correct 377 ms 47280 KB Output is correct
70 Correct 372 ms 44220 KB Output is correct
71 Correct 335 ms 45604 KB Output is correct
72 Correct 361 ms 44344 KB Output is correct
73 Correct 360 ms 45020 KB Output is correct
74 Correct 338 ms 46980 KB Output is correct
75 Correct 363 ms 45852 KB Output is correct
76 Correct 41 ms 13648 KB Output is correct
77 Correct 380 ms 38800 KB Output is correct
78 Correct 331 ms 39508 KB Output is correct
79 Correct 1 ms 4444 KB Output is correct
80 Correct 2 ms 4444 KB Output is correct