이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int64_t n,m;cin>>n>>m;
vector<int64_t>extra(2*n);
vector<vector<int64_t>>tree(2*n);
vector<int64_t>arr(n);
for (int64_t i = 0;i<n;++i){
	cin>>arr[i];
}
int64_t curans = 0;
int64_t maxxy = 0;
function<void(int64_t,int64_t,int64_t)> build = [&](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);
        build(node+1,node_low,y);
        build(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]));    
    }  
};
function<void(int64_t,int64_t,int64_t,int64_t,int64_t)>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);
};
build(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;}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |