답안 #168565

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168565 2019-12-13T18:39:23 Z beso123 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1781 ms 107280 KB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,pair<int,pair<int,int>>>
#define x first
#define y second.first
#define z second.second.first
#define p second.second.second
using namespace std;
const int N=(1e6)+3;
int n,q,a[N],t[4*N],gr[N],ans[N];
vector<pii> Q;
stack<int> st;
void UPD(int v,int i,int j,int pos,int val){
    if(i==j && pos==i){
       t[v]=val;
       return;
    }
    int mid=(i+j)/2;
    if(pos<=mid)
        UPD(v*2,i,mid,pos,val);
    else
        UPD(v*2+1,mid+1,j,pos,val);
    t[v]=max(t[v*2],t[v*2+1]);
}
int GET(int v,int i,int j,int l,int r){
    if(l>r)
        return -LONG_LONG_MAX;
    if(i==l && j==r)
        return t[v];
    int mid=(i+j)/2;
    int g1=GET(v*2,i,mid,l,min(r,mid));
    int g2=GET(v*2+1,mid+1,j,max(mid+1,l),r);
    return max(g1,g2);
}
bool comp_sort(pii a,pii b){
    return a.y<b.y;
}
main(){
scanf("%lld%lld",&n,&q);
for(int k=1;k<=n;k++)
    scanf("%lld",&a[k]);
a[0]=LONG_LONG_MAX;
st.push(0);
for(int k=1;k<=n;k++){
    while(a[st.top()]<=a[k]){
        st.pop();
    }
    gr[k]=st.top();
    st.push(k);
}
for(int k=1;k<=q;k++){
   int a,b,c;
   scanf("%lld%lld%lld",&a,&b,&c);
   Q.push_back({a,{b,{c,k}}});
}
sort(Q.begin(),Q.end(),comp_sort);
int j=0;
for(int k=1;k<=n;k++){
   if(gr[k])
    UPD(1,1,n,gr[k],a[gr[k]]+a[k]);
    while(j<Q.size() && Q[j].y==k){
        if(GET(1,1,n,Q[j].x,Q[j].y)<=Q[j].z)
            ans[Q[j].p]=1;
        j++;
    }
}
for(int k=1;k<=q;k++)
    printf("%lld\n",ans[k]);
return 0;
}

Compilation message

sortbooks.cpp:38:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:59:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    if(gr[k])
    ^~
sortbooks.cpp:61:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
     while(j<Q.size() && Q[j].y==k){
     ^~~~~
sortbooks.cpp:61:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(j<Q.size() && Q[j].y==k){
           ~^~~~~~~~~
sortbooks.cpp:39:6: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf("%lld%lld",&n,&q);
 ~~~~~^~~~~~~~~~~~~~~~~~
sortbooks.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&a[k]);
     ~~~~~^~~~~~~~~~~~~~
sortbooks.cpp:53:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld%lld%lld",&a,&b,&c);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 5 ms 760 KB Output is correct
12 Correct 6 ms 888 KB Output is correct
13 Correct 7 ms 888 KB Output is correct
14 Correct 8 ms 1012 KB Output is correct
15 Correct 8 ms 1012 KB Output is correct
16 Correct 7 ms 936 KB Output is correct
17 Correct 6 ms 888 KB Output is correct
18 Correct 7 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1728 ms 66644 KB Output is correct
2 Correct 1745 ms 97944 KB Output is correct
3 Correct 1742 ms 98160 KB Output is correct
4 Correct 1721 ms 98592 KB Output is correct
5 Correct 1505 ms 90196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 137 ms 8924 KB Output is correct
2 Correct 133 ms 9052 KB Output is correct
3 Correct 117 ms 7012 KB Output is correct
4 Correct 116 ms 7032 KB Output is correct
5 Correct 119 ms 6984 KB Output is correct
6 Correct 100 ms 6884 KB Output is correct
7 Correct 99 ms 6884 KB Output is correct
8 Correct 108 ms 7004 KB Output is correct
9 Correct 66 ms 5468 KB Output is correct
10 Correct 109 ms 7364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 5 ms 760 KB Output is correct
12 Correct 6 ms 888 KB Output is correct
13 Correct 7 ms 888 KB Output is correct
14 Correct 8 ms 1012 KB Output is correct
15 Correct 8 ms 1012 KB Output is correct
16 Correct 7 ms 936 KB Output is correct
17 Correct 6 ms 888 KB Output is correct
18 Correct 7 ms 888 KB Output is correct
19 Correct 321 ms 17008 KB Output is correct
20 Correct 322 ms 16976 KB Output is correct
21 Correct 296 ms 17052 KB Output is correct
22 Correct 293 ms 17016 KB Output is correct
23 Correct 294 ms 17024 KB Output is correct
24 Correct 250 ms 12892 KB Output is correct
25 Correct 263 ms 12892 KB Output is correct
26 Correct 276 ms 13020 KB Output is correct
27 Correct 265 ms 12864 KB Output is correct
28 Correct 263 ms 12928 KB Output is correct
29 Correct 271 ms 12936 KB Output is correct
30 Correct 270 ms 13100 KB Output is correct
31 Correct 269 ms 13008 KB Output is correct
32 Correct 273 ms 12892 KB Output is correct
33 Correct 273 ms 12864 KB Output is correct
34 Correct 237 ms 13008 KB Output is correct
35 Correct 236 ms 12892 KB Output is correct
36 Correct 232 ms 13008 KB Output is correct
37 Correct 235 ms 13048 KB Output is correct
38 Correct 244 ms 12892 KB Output is correct
39 Correct 243 ms 14416 KB Output is correct
40 Correct 195 ms 11920 KB Output is correct
41 Correct 231 ms 12880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 5 ms 760 KB Output is correct
12 Correct 6 ms 888 KB Output is correct
13 Correct 7 ms 888 KB Output is correct
14 Correct 8 ms 1012 KB Output is correct
15 Correct 8 ms 1012 KB Output is correct
16 Correct 7 ms 936 KB Output is correct
17 Correct 6 ms 888 KB Output is correct
18 Correct 7 ms 888 KB Output is correct
19 Correct 1728 ms 66644 KB Output is correct
20 Correct 1745 ms 97944 KB Output is correct
21 Correct 1742 ms 98160 KB Output is correct
22 Correct 1721 ms 98592 KB Output is correct
23 Correct 1505 ms 90196 KB Output is correct
24 Correct 137 ms 8924 KB Output is correct
25 Correct 133 ms 9052 KB Output is correct
26 Correct 117 ms 7012 KB Output is correct
27 Correct 116 ms 7032 KB Output is correct
28 Correct 119 ms 6984 KB Output is correct
29 Correct 100 ms 6884 KB Output is correct
30 Correct 99 ms 6884 KB Output is correct
31 Correct 108 ms 7004 KB Output is correct
32 Correct 66 ms 5468 KB Output is correct
33 Correct 109 ms 7364 KB Output is correct
34 Correct 321 ms 17008 KB Output is correct
35 Correct 322 ms 16976 KB Output is correct
36 Correct 296 ms 17052 KB Output is correct
37 Correct 293 ms 17016 KB Output is correct
38 Correct 294 ms 17024 KB Output is correct
39 Correct 250 ms 12892 KB Output is correct
40 Correct 263 ms 12892 KB Output is correct
41 Correct 276 ms 13020 KB Output is correct
42 Correct 265 ms 12864 KB Output is correct
43 Correct 263 ms 12928 KB Output is correct
44 Correct 271 ms 12936 KB Output is correct
45 Correct 270 ms 13100 KB Output is correct
46 Correct 269 ms 13008 KB Output is correct
47 Correct 273 ms 12892 KB Output is correct
48 Correct 273 ms 12864 KB Output is correct
49 Correct 237 ms 13008 KB Output is correct
50 Correct 236 ms 12892 KB Output is correct
51 Correct 232 ms 13008 KB Output is correct
52 Correct 235 ms 13048 KB Output is correct
53 Correct 244 ms 12892 KB Output is correct
54 Correct 243 ms 14416 KB Output is correct
55 Correct 195 ms 11920 KB Output is correct
56 Correct 231 ms 12880 KB Output is correct
57 Correct 1781 ms 105604 KB Output is correct
58 Correct 1768 ms 107184 KB Output is correct
59 Correct 1746 ms 107280 KB Output is correct
60 Correct 1733 ms 107128 KB Output is correct
61 Correct 1739 ms 107280 KB Output is correct
62 Correct 1721 ms 106952 KB Output is correct
63 Correct 1372 ms 89068 KB Output is correct
64 Correct 1377 ms 78452 KB Output is correct
65 Correct 1490 ms 88044 KB Output is correct
66 Correct 1480 ms 88636 KB Output is correct
67 Correct 1484 ms 88140 KB Output is correct
68 Correct 1503 ms 89360 KB Output is correct
69 Correct 1512 ms 89316 KB Output is correct
70 Correct 1521 ms 89700 KB Output is correct
71 Correct 1502 ms 89720 KB Output is correct
72 Correct 1564 ms 89940 KB Output is correct
73 Correct 1240 ms 86492 KB Output is correct
74 Correct 1250 ms 80964 KB Output is correct
75 Correct 1244 ms 83456 KB Output is correct
76 Correct 1239 ms 79928 KB Output is correct
77 Correct 1254 ms 79484 KB Output is correct
78 Correct 1318 ms 83068 KB Output is correct
79 Correct 1010 ms 72076 KB Output is correct
80 Correct 1258 ms 76912 KB Output is correct