답안 #167139

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167139 2019-12-06T06:20:30 Z rzbt Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2213 ms 141576 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 1000006
typedef long long ll;


using namespace std;

int n,m;
vector<int> s;
vector<pair<pair<int,int>,int> > query[MAXN];
vector<int> gube[MAXN];
int niz[MAXN],res[MAXN];
int tr[MAXN];
int seg[4*MAXN];
void dodaj(int l,int d,int p,int k,int x){
    if(l==d){
        seg[k]=x;
        return;
    }
    int mid=(l+d)/2;
    if(p<=mid)dodaj(l,mid,p,k+k,x);
    else dodaj(mid+1,d,p,k+k+1,x);
    seg[k]=max(seg[k+k],seg[k+k+1]);
}

int dobij(int l,int d,int tl,int td,int k){
    if(l>td || d<tl)return 0;
    if(l>=tl && d<=td)return seg[k];
    int mid=(l+d)/2;
    return max(dobij(l,mid,tl,td,k+k),
            dobij(mid+1,d,tl,td,k+k+1));

}

void izgradi(int l,int d,int k){
    if(l==d){
        seg[k]=tr[l];
        return;
    }
    int mid=(l+d)/2;
    izgradi(l,mid,k+k);
    izgradi(mid+1,d,k+k+1);
    seg[k]=max(seg[k+k],seg[k+k+1]);

}

int main()
{
    scanf("%d %d", &n, &m);
    for(int i=1;i<=n;i++){
        scanf("%d",niz+i);
        while(!s.empty() && niz[s.back()] <= niz[i])s.pop_back();
        if(s.empty())s.pb(i);
        else{
            int o=s.back();
            gube[o].pb(i);
            tr[i]=niz[i]+niz[o];
            s.push_back(i);
        }
    }
    izgradi(1,n,1);
    for(int i=1;i<=m;i++){
        int t1,t2,t3;
        scanf("%d %d %d", &t1, &t2, &t3);
        query[t1].pb(mp(mp(t2,t3), i));
    }
    for(int i=1;i<=n;i++){
        for(auto x:query[i]){

            if(dobij(1,n,i,x.F.F,1)<=x.F.S)res[x.S]=1;
            else res[x.S]=0;
        }
        for(auto x:gube[i]){
            dodaj(1,n,x,1,0);

        }
    }
    for(int i=1;i<=m;i++)printf("%d\n",res[i]);

    return 0;//
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
sortbooks.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",niz+i);
         ~~~~~^~~~~~~~~~~~
sortbooks.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &t1, &t2, &t3);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 47352 KB Output is correct
2 Correct 47 ms 47352 KB Output is correct
3 Correct 59 ms 47336 KB Output is correct
4 Correct 46 ms 47308 KB Output is correct
5 Correct 50 ms 47352 KB Output is correct
6 Correct 48 ms 47344 KB Output is correct
7 Correct 47 ms 47352 KB Output is correct
8 Correct 47 ms 47304 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 46 ms 47352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 47352 KB Output is correct
2 Correct 47 ms 47352 KB Output is correct
3 Correct 59 ms 47336 KB Output is correct
4 Correct 46 ms 47308 KB Output is correct
5 Correct 50 ms 47352 KB Output is correct
6 Correct 48 ms 47344 KB Output is correct
7 Correct 47 ms 47352 KB Output is correct
8 Correct 47 ms 47304 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 46 ms 47352 KB Output is correct
11 Correct 52 ms 47560 KB Output is correct
12 Correct 52 ms 47608 KB Output is correct
13 Correct 52 ms 47696 KB Output is correct
14 Correct 69 ms 47864 KB Output is correct
15 Correct 53 ms 47736 KB Output is correct
16 Correct 55 ms 47708 KB Output is correct
17 Correct 63 ms 47652 KB Output is correct
18 Correct 51 ms 47608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2142 ms 108572 KB Output is correct
2 Correct 2118 ms 108188 KB Output is correct
3 Correct 2150 ms 107292 KB Output is correct
4 Correct 2140 ms 107372 KB Output is correct
5 Correct 1768 ms 87412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 54436 KB Output is correct
2 Correct 179 ms 54136 KB Output is correct
3 Correct 173 ms 52272 KB Output is correct
4 Correct 171 ms 52344 KB Output is correct
5 Correct 175 ms 52344 KB Output is correct
6 Correct 133 ms 51832 KB Output is correct
7 Correct 133 ms 51960 KB Output is correct
8 Correct 153 ms 52536 KB Output is correct
9 Correct 97 ms 50224 KB Output is correct
10 Correct 152 ms 52388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 47352 KB Output is correct
2 Correct 47 ms 47352 KB Output is correct
3 Correct 59 ms 47336 KB Output is correct
4 Correct 46 ms 47308 KB Output is correct
5 Correct 50 ms 47352 KB Output is correct
6 Correct 48 ms 47344 KB Output is correct
7 Correct 47 ms 47352 KB Output is correct
8 Correct 47 ms 47304 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 46 ms 47352 KB Output is correct
11 Correct 52 ms 47560 KB Output is correct
12 Correct 52 ms 47608 KB Output is correct
13 Correct 52 ms 47696 KB Output is correct
14 Correct 69 ms 47864 KB Output is correct
15 Correct 53 ms 47736 KB Output is correct
16 Correct 55 ms 47708 KB Output is correct
17 Correct 63 ms 47652 KB Output is correct
18 Correct 51 ms 47608 KB Output is correct
19 Correct 408 ms 66564 KB Output is correct
20 Correct 404 ms 66396 KB Output is correct
21 Correct 352 ms 66020 KB Output is correct
22 Correct 356 ms 65756 KB Output is correct
23 Correct 357 ms 65784 KB Output is correct
24 Correct 282 ms 61688 KB Output is correct
25 Correct 283 ms 61716 KB Output is correct
26 Correct 322 ms 61936 KB Output is correct
27 Correct 318 ms 61944 KB Output is correct
28 Correct 326 ms 61992 KB Output is correct
29 Correct 354 ms 62480 KB Output is correct
30 Correct 356 ms 62444 KB Output is correct
31 Correct 342 ms 62364 KB Output is correct
32 Correct 343 ms 62420 KB Output is correct
33 Correct 360 ms 62428 KB Output is correct
34 Correct 248 ms 60920 KB Output is correct
35 Correct 251 ms 60900 KB Output is correct
36 Correct 250 ms 60664 KB Output is correct
37 Correct 251 ms 60632 KB Output is correct
38 Correct 248 ms 60920 KB Output is correct
39 Correct 345 ms 61588 KB Output is correct
40 Correct 233 ms 58156 KB Output is correct
41 Correct 294 ms 60784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 47352 KB Output is correct
2 Correct 47 ms 47352 KB Output is correct
3 Correct 59 ms 47336 KB Output is correct
4 Correct 46 ms 47308 KB Output is correct
5 Correct 50 ms 47352 KB Output is correct
6 Correct 48 ms 47344 KB Output is correct
7 Correct 47 ms 47352 KB Output is correct
8 Correct 47 ms 47304 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 46 ms 47352 KB Output is correct
11 Correct 52 ms 47560 KB Output is correct
12 Correct 52 ms 47608 KB Output is correct
13 Correct 52 ms 47696 KB Output is correct
14 Correct 69 ms 47864 KB Output is correct
15 Correct 53 ms 47736 KB Output is correct
16 Correct 55 ms 47708 KB Output is correct
17 Correct 63 ms 47652 KB Output is correct
18 Correct 51 ms 47608 KB Output is correct
19 Correct 2142 ms 108572 KB Output is correct
20 Correct 2118 ms 108188 KB Output is correct
21 Correct 2150 ms 107292 KB Output is correct
22 Correct 2140 ms 107372 KB Output is correct
23 Correct 1768 ms 87412 KB Output is correct
24 Correct 200 ms 54436 KB Output is correct
25 Correct 179 ms 54136 KB Output is correct
26 Correct 173 ms 52272 KB Output is correct
27 Correct 171 ms 52344 KB Output is correct
28 Correct 175 ms 52344 KB Output is correct
29 Correct 133 ms 51832 KB Output is correct
30 Correct 133 ms 51960 KB Output is correct
31 Correct 153 ms 52536 KB Output is correct
32 Correct 97 ms 50224 KB Output is correct
33 Correct 152 ms 52388 KB Output is correct
34 Correct 408 ms 66564 KB Output is correct
35 Correct 404 ms 66396 KB Output is correct
36 Correct 352 ms 66020 KB Output is correct
37 Correct 356 ms 65756 KB Output is correct
38 Correct 357 ms 65784 KB Output is correct
39 Correct 282 ms 61688 KB Output is correct
40 Correct 283 ms 61716 KB Output is correct
41 Correct 322 ms 61936 KB Output is correct
42 Correct 318 ms 61944 KB Output is correct
43 Correct 326 ms 61992 KB Output is correct
44 Correct 354 ms 62480 KB Output is correct
45 Correct 356 ms 62444 KB Output is correct
46 Correct 342 ms 62364 KB Output is correct
47 Correct 343 ms 62420 KB Output is correct
48 Correct 360 ms 62428 KB Output is correct
49 Correct 248 ms 60920 KB Output is correct
50 Correct 251 ms 60900 KB Output is correct
51 Correct 250 ms 60664 KB Output is correct
52 Correct 251 ms 60632 KB Output is correct
53 Correct 248 ms 60920 KB Output is correct
54 Correct 345 ms 61588 KB Output is correct
55 Correct 233 ms 58156 KB Output is correct
56 Correct 294 ms 60784 KB Output is correct
57 Correct 2213 ms 141576 KB Output is correct
58 Correct 2184 ms 141540 KB Output is correct
59 Correct 2103 ms 139432 KB Output is correct
60 Correct 2109 ms 139432 KB Output is correct
61 Correct 2116 ms 139372 KB Output is correct
62 Correct 2076 ms 139640 KB Output is correct
63 Correct 1391 ms 113612 KB Output is correct
64 Correct 1317 ms 113552 KB Output is correct
65 Correct 1833 ms 119144 KB Output is correct
66 Correct 1733 ms 118108 KB Output is correct
67 Correct 1746 ms 117996 KB Output is correct
68 Correct 1781 ms 119212 KB Output is correct
69 Correct 1797 ms 120196 KB Output is correct
70 Correct 1772 ms 115536 KB Output is correct
71 Correct 1793 ms 120952 KB Output is correct
72 Correct 1821 ms 114272 KB Output is correct
73 Correct 1186 ms 98680 KB Output is correct
74 Correct 1212 ms 94852 KB Output is correct
75 Correct 1165 ms 92376 KB Output is correct
76 Correct 1202 ms 95008 KB Output is correct
77 Correct 1198 ms 97008 KB Output is correct
78 Correct 1619 ms 109792 KB Output is correct
79 Correct 1102 ms 99700 KB Output is correct
80 Correct 1475 ms 113016 KB Output is correct