Submission #837028

#TimeUsernameProblemLanguageResultExecution timeMemory
837028MODDIHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
3096 ms22096 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int n, m;
vi arr;
int main(){
	cin>>n>>m;
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		arr.pb(a);
	}
	while(m--){
		int l, r, k;
		cin>>l>>r>>k;
		l--; r--;
		// minimum and maximum number that are not in the desired place
		vi here;
		for(int i = l; i <= r; i++)	here.pb(i);
			
		sort(here.begin(), here.end());
		int s = 0, e = (int)here.size()-1;
		while(s <(int)here.size() && arr[l+s] == here[s])	s++;
		while(e >= 0 && arr[r-e] == here[e]) e--;
		if(e <= s)	cout<<0<<endl;
		else{
			int maxi = 0, mini = 1e9;
			for(int i = s; i <= e; i++){
				maxi = max(maxi, arr[i]);
				mini = min(mini, arr[i]);
			}
			if(maxi + mini <= k)	cout<<1<<endl;
			else cout<<0<<endl;	
		}
		
	}

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...