Submission #209771

# Submission time Handle Problem Language Result Execution time Memory
209771 2020-03-15T14:06:45 Z igzi Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
1077 ms 262148 KB
#include <bits/stdc++.h>
#define maxN 1000006
 
using namespace std;
 
struct segment{
vector <int> v;
int res;
};
int a[maxN],n,m,i,l,d,k,ans,M;
segment seg[4*maxN];
 
void build(int n,int l,int d){
if(l==d){
    seg[n].v.push_back(a[l]);
    seg[n].res=0;
    return;
}
int m=(l+d)/2;
build(2*n,l,m);
build(2*n+1,m+1,d);
int i,j;
i=j=0;
while(i<seg[2*n].v.size() & j<seg[2*n+1].v.size()){
    if(seg[2*n].v[i]<=seg[2*n+1].v[j]) {seg[n].v.push_back(seg[2*n].v[i]); i++;}
    else {seg[n].v.push_back(seg[2*n+1].v[j]); j++;}
}
while(i<seg[2*n].v.size()) {seg[n].v.push_back(seg[2*n].v[i]); i++;}
while(j<seg[2*n+1].v.size()) {seg[n].v.push_back(seg[2*n+1].v[j]); j++;}
M=seg[2*n].v.back();
int tmp=lower_bound(seg[2*n+1].v.begin(),seg[2*n+1].v.end(),M)-seg[2*n+1].v.begin();
tmp--;
seg[n].res=max(seg[2*n].res,seg[2*n+1].res);
if(tmp>=0) seg[n].res=max(seg[n].res,seg[2*n+1].v[tmp]+M);
}
 
void resi(int n,int l,int d,int x,int y){
if(d<x || l>y || ans==0){
return;
}
if(l>=x && d<=y){
//cout<<l<<" "<<d<<" "<<M<<" "<<seg[n].res<<endl;
int tmp=lower_bound(seg[n].v.begin(),seg[n].v.end(),M)-seg[n].v.begin();
tmp--;
if(tmp>=0 && seg[n].v[tmp]+M>k) ans=0;
if(seg[n].res>k) ans=0;
M=max(M,seg[n].v.back());
return;
}
int m=(l+d)/2;
resi(2*n,l,m,x,y);
resi(2*n+1,m+1,d,x,y);
}
 
int main()
{
    std::ios_base::sync_with_stdio(0);
    cin>>n>>m;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    build(1,0,n-1);
    for(i=0;i<m;i++){
        cin>>l>>d>>k;
        ans=1;
        M=0;
        resi(1,0,n-1,l-1,d-1);
        cout<<ans<<"\n";
    }
    return 0;
}

Compilation message

sortbooks.cpp: In function 'void build(int, int, int)':
sortbooks.cpp:24:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 while(i<seg[2*n].v.size() & j<seg[2*n+1].v.size()){
       ~^~~~~~~~~~~~~~~~~~
sortbooks.cpp:24:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 while(i<seg[2*n].v.size() & j<seg[2*n+1].v.size()){
                             ~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:24:8: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
 while(i<seg[2*n].v.size() & j<seg[2*n+1].v.size()){
       ~^~~~~~~~~~~~~~~~~~
sortbooks.cpp:28:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 while(i<seg[2*n].v.size()) {seg[n].v.push_back(seg[2*n].v[i]); i++;}
       ~^~~~~~~~~~~~~~~~~~
sortbooks.cpp:29:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 while(j<seg[2*n+1].v.size()) {seg[n].v.push_back(seg[2*n+1].v[j]); j++;}
       ~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 76 ms 125560 KB Output is correct
2 Correct 75 ms 125560 KB Output is correct
3 Correct 81 ms 125560 KB Output is correct
4 Correct 76 ms 125560 KB Output is correct
5 Correct 76 ms 125560 KB Output is correct
6 Correct 76 ms 125688 KB Output is correct
7 Correct 80 ms 125692 KB Output is correct
8 Correct 77 ms 125688 KB Output is correct
9 Correct 76 ms 125560 KB Output is correct
10 Correct 79 ms 125688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 125560 KB Output is correct
2 Correct 75 ms 125560 KB Output is correct
3 Correct 81 ms 125560 KB Output is correct
4 Correct 76 ms 125560 KB Output is correct
5 Correct 76 ms 125560 KB Output is correct
6 Correct 76 ms 125688 KB Output is correct
7 Correct 80 ms 125692 KB Output is correct
8 Correct 77 ms 125688 KB Output is correct
9 Correct 76 ms 125560 KB Output is correct
10 Correct 79 ms 125688 KB Output is correct
11 Correct 84 ms 125816 KB Output is correct
12 Correct 86 ms 126328 KB Output is correct
13 Correct 85 ms 126328 KB Output is correct
14 Correct 91 ms 126456 KB Output is correct
15 Correct 93 ms 126456 KB Output is correct
16 Correct 89 ms 126328 KB Output is correct
17 Correct 92 ms 126072 KB Output is correct
18 Correct 90 ms 126328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 676 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 428 ms 139380 KB Output is correct
2 Correct 416 ms 139764 KB Output is correct
3 Correct 476 ms 139952 KB Output is correct
4 Correct 465 ms 141424 KB Output is correct
5 Correct 490 ms 141428 KB Output is correct
6 Correct 403 ms 141296 KB Output is correct
7 Correct 406 ms 141296 KB Output is correct
8 Correct 426 ms 141036 KB Output is correct
9 Correct 322 ms 127224 KB Output is correct
10 Correct 440 ms 141040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 125560 KB Output is correct
2 Correct 75 ms 125560 KB Output is correct
3 Correct 81 ms 125560 KB Output is correct
4 Correct 76 ms 125560 KB Output is correct
5 Correct 76 ms 125560 KB Output is correct
6 Correct 76 ms 125688 KB Output is correct
7 Correct 80 ms 125692 KB Output is correct
8 Correct 77 ms 125688 KB Output is correct
9 Correct 76 ms 125560 KB Output is correct
10 Correct 79 ms 125688 KB Output is correct
11 Correct 84 ms 125816 KB Output is correct
12 Correct 86 ms 126328 KB Output is correct
13 Correct 85 ms 126328 KB Output is correct
14 Correct 91 ms 126456 KB Output is correct
15 Correct 93 ms 126456 KB Output is correct
16 Correct 89 ms 126328 KB Output is correct
17 Correct 92 ms 126072 KB Output is correct
18 Correct 90 ms 126328 KB Output is correct
19 Correct 856 ms 157292 KB Output is correct
20 Correct 865 ms 160620 KB Output is correct
21 Correct 808 ms 160492 KB Output is correct
22 Correct 795 ms 160456 KB Output is correct
23 Correct 801 ms 160496 KB Output is correct
24 Correct 854 ms 160364 KB Output is correct
25 Correct 873 ms 160364 KB Output is correct
26 Correct 969 ms 160492 KB Output is correct
27 Correct 981 ms 160620 KB Output is correct
28 Correct 954 ms 160620 KB Output is correct
29 Correct 980 ms 160648 KB Output is correct
30 Correct 951 ms 160620 KB Output is correct
31 Correct 984 ms 160708 KB Output is correct
32 Correct 1006 ms 160620 KB Output is correct
33 Correct 1077 ms 160616 KB Output is correct
34 Correct 799 ms 160292 KB Output is correct
35 Correct 796 ms 160236 KB Output is correct
36 Correct 809 ms 160136 KB Output is correct
37 Correct 810 ms 159980 KB Output is correct
38 Correct 769 ms 160236 KB Output is correct
39 Correct 848 ms 159212 KB Output is correct
40 Correct 793 ms 146672 KB Output is correct
41 Correct 820 ms 158700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 125560 KB Output is correct
2 Correct 75 ms 125560 KB Output is correct
3 Correct 81 ms 125560 KB Output is correct
4 Correct 76 ms 125560 KB Output is correct
5 Correct 76 ms 125560 KB Output is correct
6 Correct 76 ms 125688 KB Output is correct
7 Correct 80 ms 125692 KB Output is correct
8 Correct 77 ms 125688 KB Output is correct
9 Correct 76 ms 125560 KB Output is correct
10 Correct 79 ms 125688 KB Output is correct
11 Correct 84 ms 125816 KB Output is correct
12 Correct 86 ms 126328 KB Output is correct
13 Correct 85 ms 126328 KB Output is correct
14 Correct 91 ms 126456 KB Output is correct
15 Correct 93 ms 126456 KB Output is correct
16 Correct 89 ms 126328 KB Output is correct
17 Correct 92 ms 126072 KB Output is correct
18 Correct 90 ms 126328 KB Output is correct
19 Runtime error 676 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Halted 0 ms 0 KB -