Submission #539362

# Submission time Handle Problem Language Result Execution time Memory
539362 2022-03-18T18:39:32 Z 1ne Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
671 ms 262144 KB
#include<bits/stdc++.h>
using namespace std;
vector<int64_t>extra;
vector<vector<int64_t>>tree;
void build(vector<int64_t>&arr,int64_t node,int64_t node_low,int64_t node_high){
    if (node_low==node_high){
        tree[node].push_back(arr[node_low]);
    }
    else {
    	int y = (node_low + node_high) >> 1;
    	int z = node + ((y - node_low + 1) << 1);
        int64_t mid  =(node_low+node_high)>>1;
        build(arr,node+1,node_low,y);
        build(arr,z,y+1,node_high);
        extra[node] = max(extra[node+1],extra[z]);
	    auto right = lower_bound(tree[z].begin(),tree[z].end(),tree[node+1].back()) - tree[z].begin();
		while(right>=0){
			if (tree[z][right]>=tree[node+1].back() || right>=(int)tree[z].size()){
				--right;
			}
			else break;
		}
		if (right>=0){
			extra[node] = max(extra[node],tree[node+1].back() + tree[z][right]);
		}
        merge(tree[node+1].begin(),tree[node+1].end(),tree[z].begin(),tree[z].end(),back_inserter(tree[node]));    
    }  
}
int64_t curans = 0;
int64_t maxxy = 0;
void query(int64_t node,int64_t node_low,int64_t node_high,int64_t query_low,int64_t query_high){
    if (node_low>node_high||query_high<node_low||query_low>node_high)return ;
    if (query_low<=node_low&&query_high>=node_high){
    	curans = max(curans,extra[node]);
    	auto right = lower_bound(tree[node].begin(),tree[node].end(),maxxy) - tree[node].begin();
		while(right>=0){
			if (tree[node][right]>=maxxy || right>=(int)tree[node].size()){
				--right;
			}
			else break;
		}
		if (right>=0){
			curans = max(curans,maxxy + tree[node][right]);
		}
	    maxxy = max(maxxy,tree[node].back());
	    return ;
    }
    int y = (node_low + node_high) >> 1;
    int z = node + ((y - node_low + 1) << 1);
   	query(node+1,node_low,y,query_low,query_high);
   	query(z,y+1,node_high,query_low,query_high);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int64_t n,m;cin>>n>>m;
vector<int64_t>arr(n);
for (int64_t i = 0;i<n;++i){
	cin>>arr[i];
}
extra.resize(2 * n - 1,0);
tree.resize(2 * n - 1);
build(arr,0,0,n-1);
for (int64_t i = 0;i<m;++i){
	int64_t l,r,k;cin>>l>>r>>k;
	--l,--r;
	curans = 0;
	maxxy = 0;
	query(0,0,n-1,l,r);
	//cout<<curans<<" "<<maxxy<<'\n';
	if (curans>k){
		cout<<0<<'\n';
	}
	else cout<<1<<'\n';
}
return 0;}

Compilation message

sortbooks.cpp: In function 'void build(std::vector<long int>&, int64_t, int64_t, int64_t)':
sortbooks.cpp:12:17: warning: unused variable 'mid' [-Wunused-variable]
   12 |         int64_t mid  =(node_low+node_high)>>1;
      |                 ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 232 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 360 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 232 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 360 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 10 ms 1672 KB Output is correct
13 Correct 10 ms 1620 KB Output is correct
14 Correct 9 ms 1704 KB Output is correct
15 Correct 9 ms 1620 KB Output is correct
16 Correct 7 ms 1700 KB Output is correct
17 Correct 8 ms 1236 KB Output is correct
18 Correct 7 ms 1704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 527 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 292 ms 28996 KB Output is correct
2 Correct 234 ms 28884 KB Output is correct
3 Correct 268 ms 28768 KB Output is correct
4 Correct 233 ms 28860 KB Output is correct
5 Correct 227 ms 28852 KB Output is correct
6 Correct 136 ms 28880 KB Output is correct
7 Correct 163 ms 28884 KB Output is correct
8 Correct 221 ms 28824 KB Output is correct
9 Correct 45 ms 936 KB Output is correct
10 Correct 168 ms 28864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 232 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 360 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 10 ms 1672 KB Output is correct
13 Correct 10 ms 1620 KB Output is correct
14 Correct 9 ms 1704 KB Output is correct
15 Correct 9 ms 1620 KB Output is correct
16 Correct 7 ms 1700 KB Output is correct
17 Correct 8 ms 1236 KB Output is correct
18 Correct 7 ms 1704 KB Output is correct
19 Correct 614 ms 58812 KB Output is correct
20 Correct 671 ms 58908 KB Output is correct
21 Correct 509 ms 58972 KB Output is correct
22 Correct 496 ms 58944 KB Output is correct
23 Correct 472 ms 58912 KB Output is correct
24 Correct 394 ms 58872 KB Output is correct
25 Correct 425 ms 58920 KB Output is correct
26 Correct 499 ms 58924 KB Output is correct
27 Correct 542 ms 58868 KB Output is correct
28 Correct 565 ms 58900 KB Output is correct
29 Correct 555 ms 58908 KB Output is correct
30 Correct 548 ms 58884 KB Output is correct
31 Correct 529 ms 58948 KB Output is correct
32 Correct 543 ms 59088 KB Output is correct
33 Correct 528 ms 58912 KB Output is correct
34 Correct 345 ms 58908 KB Output is correct
35 Correct 313 ms 58896 KB Output is correct
36 Correct 312 ms 58888 KB Output is correct
37 Correct 324 ms 58864 KB Output is correct
38 Correct 310 ms 58828 KB Output is correct
39 Correct 474 ms 58812 KB Output is correct
40 Correct 354 ms 34556 KB Output is correct
41 Correct 452 ms 58720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 232 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 360 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 10 ms 1672 KB Output is correct
13 Correct 10 ms 1620 KB Output is correct
14 Correct 9 ms 1704 KB Output is correct
15 Correct 9 ms 1620 KB Output is correct
16 Correct 7 ms 1700 KB Output is correct
17 Correct 8 ms 1236 KB Output is correct
18 Correct 7 ms 1704 KB Output is correct
19 Runtime error 527 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -