Submission #537640

# Submission time Handle Problem Language Result Execution time Memory
537640 2022-03-15T10:30:22 Z 1ne Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
1474 ms 249444 KB
#include<bits/stdc++.h>
using namespace std;
vector<int>extra;
void combine(vector<int>tree1,vector<int>tree2,int node){
	auto right = lower_bound(tree2.begin(),tree2.end(),tree1.back() - 1) - tree2.begin();
	while(right>=0){
		if (tree2[right]>=tree1.back()){
			--right;
		}
		else break;
	}
	if (right>=0){
		extra[node] = max(extra[node],tree1.back() + tree2[right]);
	}
	// if there is a element in right segment which is less than left maximum
}
void build(vector<vector<int>>&tree,vector<int>&arr,int node,int node_low,int node_high){
    if (node_low==node_high){
        tree[node].push_back(arr[node_low]);
    }
    else {
        int mid  =(node_low+node_high)>>1;
        build(tree,arr,node*2,node_low,mid);
        build(tree,arr,node*2 + 1,mid+1,node_high);
        combine(tree[2*node],tree[node*2 + 1],node);
        merge(tree[2*node].begin(),tree[2*node].end(),tree[2*node + 1].begin(),tree[2*node + 1].end(),back_inserter(tree[node]));        
    }  
}
int query(vector<vector<int>>&tree,int node,int node_low,int node_high,int query_low,int query_high){
    if (query_high<node_low||query_low>node_high)return 0;
    if (query_low<=node_low&&query_high>=node_high){
	    return extra[node];
    }
    int mid = (node_low+node_high)>>1;
    return max(query(tree,node*2,node_low,mid,query_low,query_high),query(tree,node*2 + 1,mid+1,node_high,query_low,query_high));
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;cin>>n>>m;
vector<int>arr(n);
for (int i = 0;i<n;++i){
	cin>>arr[i];
}
vector<vector<int>>tree(4*n);
extra.resize(4*n,0);
build(tree,arr,1,0,n-1);
for (int i = 0;i<m;++i){
	int l,r,k;cin>>l>>r>>k;
	--l;
	--r;
	int ans = query(tree,1,0,n-1,l,r);
	//cout<<ans<<'\n';
	if (ans>k){
		cout<<0<<'\n';
	}
	else cout<<1<<'\n';
}
return 0;}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1474 ms 249444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 118 ms 25036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -