Submission #335891

#TimeUsernameProblemLanguageResultExecution timeMemory
335891amunduzbaevHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
17 / 100
2693 ms876 KiB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define int long long
#define ll long long 
#define ld long double 
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define prc(n) fixed << setprecision(n)
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1);
const int inf = 1e9+7;
const int N = 5005;
ll n, m;
ll a[N], def[N], s[N];
 
vector<ll>tree;
void build(int lx, int rx, int x){
	if(lx == rx){
		tree[x] = a[lx];
		return;
	}
	int m = (lx + rx)/2;
	build(lx, m, x*2);
	build(m+1, rx, x*2+1);
	tree[x] = max(tree[x*2], tree[x*2+1]);
}
 
ll find(int l,int r, int lx, int rx, int x){
	if(lx > r || rx < l){
		return 0;
	}
	if(lx >= l && rx <= r){
		return tree[x];
	}
	int m = (lx + rx)/2;
	ll mx = find(l, r, lx, m, x*2);
	mx = max(mx, find(l, r, m+1, rx, x*2+1));
	return mx;
}
 
void solve(){
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
     if(n <= 5005){
          int s = 2;
          while(s < n) s<<=1;
          tree.assign(2*s, 0);
          build(1, s, 1);
          while(m--){
              ll l, r, k;
              cin>>l>>r>>k;
              ll ans = 0;
              for(int i=l; i<=r; i++){
                  ll mx = find(l, i, 1, s, 1);
                  if(mx > a[i])
                      ans = max(ans, mx + a[i]);
              }
              if(ans > k) cout<<0<<'\n';
              else cout<<1<<'\n';
          }
     }else{
      for(int i=2;i<=n;i++){
		s[i] += s[i-1];
		if(a[i] < a[i-1]) s[i]++;
	}
	while(m--){
		ll l, r, k;
		cin>>l>>r>>k;
		if(s[r] - s[l] > 0) cout<<0<<'\n';
		else cout<<1<<'\n';
	} 
     }	
       return;
}
 
signed main(){
	fastios
	int t = 1;
	//cin>>t;
	while(t--) solve();
	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...