답안 #830651

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
830651 2023-08-19T08:52:55 Z Amylopectin Abracadabra (CEOI22_abracadabra) C++14
100 / 100
603 ms 41912 KB
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
using namespace std;
const int mxn = 4e6 + 10;
struct we
{
    int tt,ii,idx,vall;
};
bool cmp(const struct we &l,const struct we &r)
{
    return l.tt < r.tt;
}
bool cmp2(const struct we &l,const struct we &r)
{
    return l.idx < r.idx;
}
struct we sot[mxn] = {};
int ta[mxn] = {},fa[mxn] = {},u[mxn] = {},li[mxn] = {},cma = 0,se[mxn] = {}
,fipo,lef,mat[mxn] = {},va[mxn] = {},poi[mxn] = {},stac[mxn] = {};
int ad(int cl,int cr,int no,int tar,int ava)
{
    if(cl > tar || cr < tar)
    {
        return 0;
    }
    if(cl == cr)
    {
        se[no] = ava;
        return 0;
    }
    int mid = (cl+cr) / 2;
    ad(cl,mid,no*2,tar,ava);
    ad(mid+1,cr,no*2+1,tar,ava);
    se[no] = se[no*2] + se[no*2+1];
    return 0;
}
int fii(int cl,int cr,int no,int fiva)
{
    if(cl == cr)
    {
        fipo = cl;
        lef = fiva;
        return 0;
    }
    int mid = (cl+cr) / 2;
    if(se[no*2] < fiva)
    {
        fiva -= se[no*2];
        fii(mid+1,cr,no*2+1,fiva);
    }
    else 
    {
        fii(cl,mid,no*2,fiva);
    }
    return 0;
}
int main()
{
    // freopen("t7.out","w",stdout);
    int i,j,n,q,k,m,cn,cm,fn,fm,cl,cr,cru,ru,cbe,bep,tst = 0,clim;
    scanf("%d %d",&n,&q);
    stac[0] = n+1;
    for(i=1; i<=n; i++)
    {
        poi[i] = -1;
    }
    for(i=0; i<n; i++)
    {
        scanf("%d",&ta[i]);
        mat[ta[i]] = i;
        while(stac[tst] < ta[i])
        {
            poi[stac[tst]] = ta[i];
            tst --;
        }
        tst ++;
        stac[tst] = ta[i];
    }
    for(i=0; i<q; i++)
    {
        scanf("%d %d",&cn,&cm);
        sot[i] = {cn,cm,i,-1};
    }
    cbe = ta[0];
    bep = 0;
    for(i=1; i<n/2; i++)
    {
        if(ta[i] > cbe)
        {
            va[cbe] = i-bep;
            ad(1,n,1,cbe,i-bep);
            bep = i;
            cbe = ta[i];
        }
    }
    va[cbe] = n/2-bep;
    ad(1,n,1,cbe,n/2-bep);
    bep = n/2;
    cbe = ta[n/2];
    for(i=n/2+1; i<n; i++)
    {
        if(ta[i] > cbe)
        {
            va[cbe] = i-bep;
            ad(1,n,1,cbe,i-bep);
            bep = i;
            cbe = ta[i];
        }
    }
    va[cbe] = n-bep;
    ad(1,n,1,cbe,n-bep);
    sort(sot,sot+q,cmp);
    // for(j=0; j<n; j++)
    //     {
    //         printf("%d ",ta[j]);
    //     }
    //     printf("\n");
    // re(-1,n,0);
    // printf("%d\n",cma);
    ru = 0;
    while(ru < q && sot[ru].tt == 0)
        {
            sot[ru].vall = ta[sot[ru].ii-1];
            ru ++;
        }
    for(i=1; i<=n; i++)
    {
        while(ru < q && sot[ru].tt == i)
        {
            fii(1,n,1,sot[ru].ii);
            sot[ru].vall = ta[mat[fipo]+lef-1];
            ru ++;
        }
        if(ru == q)
        {
            break;
        }
        fii(1,n,1,n/2);
        cn = fipo;
        cm = lef;
        clim = mat[cn] + va[cn];
        if(va[cn] == cm)
        {
            break;
        }
        ad(1,n,1,cn,lef);
        va[cn] = lef;
        cn = ta[mat[cn]+lef];
        while(1)
        {
            fn = poi[cn];
            if(fn == -1)
            {
                break;
            }
            if(mat[fn] >= clim)
            {
                break;
            }
            ad(1,n,1,cn,mat[fn] - mat[cn]);
            va[cn] = mat[fn] - mat[cn];
            cn = fn;
        }
        // fn = 
        // fm = va[cn] - lef;
        
        ad(1,n,1,cn,clim - mat[cn]);
        va[cn] = clim - mat[cn];
        // va[fn] = fm;

        // cl = 0;
        // cr = n/2;
        // for(j=0; j<n; j++)
        // {
        //     if(cl == n/2)
        //     {
        //         fa[j] = ta[cr];
        //         cr ++;
        //     }
        //     else if(cr == n)
        //     {
        //         fa[j] = ta[cl];
        //         cl ++;
        //     }
        //     else if(ta[cl] < ta[cr])
        //     {
        //         fa[j] = ta[cl];
        //         cl ++;
        //     }
        //     else 
        //     {
        //         fa[j] = ta[cr];
        //         cr ++;
        //     }
        // }
        // for(j=0; j<n; j++)
        // {
        //     ta[j] = fa[j];
            
        //     // printf("%d ",fa[j]);
        // }
        // while(ru < q && sot[ru].tt == i)
        // {
        //     fii(1,n,1,sot[ru].ii);
        //     sot[ru].vall = ta[mat[fipo]+lef-1];
        //     ru ++;
        // }
        // if(ru == q)
        // {
        //     break;
        // }
        // printf("\n");
    }
    while(ru < q)
        {
            fii(1,n,1,sot[ru].ii);
            sot[ru].vall = ta[mat[fipo]+lef-1];
            ru ++;
        }
    sort(sot,sot+q,cmp2);
    for(i=0; i<q; i++)
    {
        printf("%d\n",sot[i].vall);
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:62:11: warning: unused variable 'j' [-Wunused-variable]
   62 |     int i,j,n,q,k,m,cn,cm,fn,fm,cl,cr,cru,ru,cbe,bep,tst = 0,clim;
      |           ^
Main.cpp:62:17: warning: unused variable 'k' [-Wunused-variable]
   62 |     int i,j,n,q,k,m,cn,cm,fn,fm,cl,cr,cru,ru,cbe,bep,tst = 0,clim;
      |                 ^
Main.cpp:62:19: warning: unused variable 'm' [-Wunused-variable]
   62 |     int i,j,n,q,k,m,cn,cm,fn,fm,cl,cr,cru,ru,cbe,bep,tst = 0,clim;
      |                   ^
Main.cpp:62:30: warning: unused variable 'fm' [-Wunused-variable]
   62 |     int i,j,n,q,k,m,cn,cm,fn,fm,cl,cr,cru,ru,cbe,bep,tst = 0,clim;
      |                              ^~
Main.cpp:62:33: warning: unused variable 'cl' [-Wunused-variable]
   62 |     int i,j,n,q,k,m,cn,cm,fn,fm,cl,cr,cru,ru,cbe,bep,tst = 0,clim;
      |                                 ^~
Main.cpp:62:36: warning: unused variable 'cr' [-Wunused-variable]
   62 |     int i,j,n,q,k,m,cn,cm,fn,fm,cl,cr,cru,ru,cbe,bep,tst = 0,clim;
      |                                    ^~
Main.cpp:62:39: warning: unused variable 'cru' [-Wunused-variable]
   62 |     int i,j,n,q,k,m,cn,cm,fn,fm,cl,cr,cru,ru,cbe,bep,tst = 0,clim;
      |                                       ^~~
Main.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |     scanf("%d %d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         scanf("%d",&ta[i]);
      |         ~~~~~^~~~~~~~~~~~~
Main.cpp:83:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         scanf("%d %d",&cn,&cm);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 421 ms 19908 KB Output is correct
2 Correct 426 ms 26700 KB Output is correct
3 Correct 417 ms 25868 KB Output is correct
4 Correct 364 ms 24684 KB Output is correct
5 Correct 399 ms 26436 KB Output is correct
6 Correct 368 ms 24996 KB Output is correct
7 Correct 403 ms 26516 KB Output is correct
8 Correct 368 ms 25564 KB Output is correct
9 Correct 396 ms 25240 KB Output is correct
10 Correct 392 ms 25656 KB Output is correct
11 Correct 400 ms 25552 KB Output is correct
12 Correct 357 ms 24564 KB Output is correct
13 Correct 411 ms 25480 KB Output is correct
14 Correct 387 ms 26292 KB Output is correct
15 Correct 393 ms 26128 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 292 ms 24832 KB Output is correct
18 Correct 348 ms 24764 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 452 ms 27364 KB Output is correct
2 Correct 419 ms 40580 KB Output is correct
3 Correct 341 ms 32944 KB Output is correct
4 Correct 316 ms 33392 KB Output is correct
5 Correct 332 ms 34132 KB Output is correct
6 Correct 323 ms 32832 KB Output is correct
7 Correct 402 ms 40200 KB Output is correct
8 Correct 388 ms 39220 KB Output is correct
9 Correct 337 ms 33976 KB Output is correct
10 Correct 411 ms 38124 KB Output is correct
11 Correct 330 ms 32056 KB Output is correct
12 Correct 313 ms 32092 KB Output is correct
13 Correct 361 ms 37372 KB Output is correct
14 Correct 300 ms 32952 KB Output is correct
15 Correct 361 ms 39108 KB Output is correct
16 Correct 27 ms 5584 KB Output is correct
17 Correct 331 ms 35740 KB Output is correct
18 Correct 279 ms 28164 KB Output is correct
19 Correct 75 ms 10000 KB Output is correct
20 Correct 110 ms 13964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 5272 KB Output is correct
2 Correct 83 ms 6808 KB Output is correct
3 Correct 81 ms 6760 KB Output is correct
4 Correct 54 ms 6504 KB Output is correct
5 Correct 69 ms 6708 KB Output is correct
6 Correct 55 ms 6460 KB Output is correct
7 Correct 64 ms 6716 KB Output is correct
8 Correct 59 ms 6484 KB Output is correct
9 Correct 63 ms 6520 KB Output is correct
10 Correct 49 ms 6280 KB Output is correct
11 Correct 51 ms 6524 KB Output is correct
12 Correct 49 ms 6276 KB Output is correct
13 Correct 51 ms 6436 KB Output is correct
14 Correct 54 ms 6516 KB Output is correct
15 Correct 49 ms 6220 KB Output is correct
16 Correct 10 ms 3404 KB Output is correct
17 Correct 47 ms 6224 KB Output is correct
18 Correct 39 ms 5232 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 421 ms 19908 KB Output is correct
2 Correct 426 ms 26700 KB Output is correct
3 Correct 417 ms 25868 KB Output is correct
4 Correct 364 ms 24684 KB Output is correct
5 Correct 399 ms 26436 KB Output is correct
6 Correct 368 ms 24996 KB Output is correct
7 Correct 403 ms 26516 KB Output is correct
8 Correct 368 ms 25564 KB Output is correct
9 Correct 396 ms 25240 KB Output is correct
10 Correct 392 ms 25656 KB Output is correct
11 Correct 400 ms 25552 KB Output is correct
12 Correct 357 ms 24564 KB Output is correct
13 Correct 411 ms 25480 KB Output is correct
14 Correct 387 ms 26292 KB Output is correct
15 Correct 393 ms 26128 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 292 ms 24832 KB Output is correct
18 Correct 348 ms 24764 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 452 ms 27364 KB Output is correct
22 Correct 419 ms 40580 KB Output is correct
23 Correct 341 ms 32944 KB Output is correct
24 Correct 316 ms 33392 KB Output is correct
25 Correct 332 ms 34132 KB Output is correct
26 Correct 323 ms 32832 KB Output is correct
27 Correct 402 ms 40200 KB Output is correct
28 Correct 388 ms 39220 KB Output is correct
29 Correct 337 ms 33976 KB Output is correct
30 Correct 411 ms 38124 KB Output is correct
31 Correct 330 ms 32056 KB Output is correct
32 Correct 313 ms 32092 KB Output is correct
33 Correct 361 ms 37372 KB Output is correct
34 Correct 300 ms 32952 KB Output is correct
35 Correct 361 ms 39108 KB Output is correct
36 Correct 27 ms 5584 KB Output is correct
37 Correct 331 ms 35740 KB Output is correct
38 Correct 279 ms 28164 KB Output is correct
39 Correct 75 ms 10000 KB Output is correct
40 Correct 110 ms 13964 KB Output is correct
41 Correct 83 ms 5272 KB Output is correct
42 Correct 83 ms 6808 KB Output is correct
43 Correct 81 ms 6760 KB Output is correct
44 Correct 54 ms 6504 KB Output is correct
45 Correct 69 ms 6708 KB Output is correct
46 Correct 55 ms 6460 KB Output is correct
47 Correct 64 ms 6716 KB Output is correct
48 Correct 59 ms 6484 KB Output is correct
49 Correct 63 ms 6520 KB Output is correct
50 Correct 49 ms 6280 KB Output is correct
51 Correct 51 ms 6524 KB Output is correct
52 Correct 49 ms 6276 KB Output is correct
53 Correct 51 ms 6436 KB Output is correct
54 Correct 54 ms 6516 KB Output is correct
55 Correct 49 ms 6220 KB Output is correct
56 Correct 10 ms 3404 KB Output is correct
57 Correct 47 ms 6224 KB Output is correct
58 Correct 39 ms 5232 KB Output is correct
59 Correct 1 ms 316 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 603 ms 41912 KB Output is correct
62 Correct 592 ms 41012 KB Output is correct
63 Correct 598 ms 39828 KB Output is correct
64 Correct 513 ms 39148 KB Output is correct
65 Correct 553 ms 40820 KB Output is correct
66 Correct 498 ms 39116 KB Output is correct
67 Correct 500 ms 40268 KB Output is correct
68 Correct 511 ms 38860 KB Output is correct
69 Correct 499 ms 38960 KB Output is correct
70 Correct 481 ms 38468 KB Output is correct
71 Correct 454 ms 37496 KB Output is correct
72 Correct 470 ms 38136 KB Output is correct
73 Correct 475 ms 38112 KB Output is correct
74 Correct 526 ms 39160 KB Output is correct
75 Correct 497 ms 39304 KB Output is correct
76 Correct 18 ms 5584 KB Output is correct
77 Correct 347 ms 35900 KB Output is correct
78 Correct 356 ms 33740 KB Output is correct
79 Correct 0 ms 340 KB Output is correct
80 Correct 1 ms 308 KB Output is correct