Submission #493088

# Submission time Handle Problem Language Result Execution time Memory
493088 2021-12-10T04:57:54 Z Khizri Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
93 ms 7456 KB
#include <bits/stdc++.h>
using namespace std;
//------------------------------DEFINE------------------------------
//******************************************************************
#define int long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0)
#define ll long long
#define pb push_back		 
#define F first																 
#define S second 															 
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
#define endl "\n"
//******************************************************************
//----------------------------FUNCTION------------------------------
//******************************************************************
ll gcd(ll a,ll b){
	if(a>b) swap(a,b);
	if(a==0) return a+b;
	return gcd(b%a,a);
}
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
bool is_prime(ll n){
	ll k=sqrt(n);
	if(n==2) return true;
	if(n<2||n%2==0||k*k==n) return false;
	for(int i=3;i<=k;i+=2){
		if(n%i==0){
			return false;
		}
	}
	return true;
}
//*****************************************************************
//--------------------------MAIN-CODE------------------------------
const int mxn=2e5+5;
int t=1,n,q,arr[mxn];
tuple<int,int,int>tree[4*mxn];
tuple<int,int,int>merge(tuple<int,int,int> &a,tuple<int,int,int> &b){
	tuple<int,int,int>ans;
	if(get<0>(a)==-1){
		return b;
	}
	if(get<0>(b)==-1){
		return a;
	}
	get<0>(ans)=min(get<0>(a),get<0>(b));
	get<1>(ans)=max(get<1>(a),get<1>(b));
	int cost=0;
	if(get<0>(b)<get<1>(a)){
		cost=get<0>(b)+get<1>(a);
	}
	get<2>(ans)=max(cost,max(get<2>(a),get<2>(b)));
	return ans;
}
tuple<int,int,int>f_tuple(){
	tuple<int,int,int>ans;
	get<0>(ans)=-1,get<1>(ans)=-1,get<2>(ans)=0;
	return ans;
}
void build(int node,int l,int r){
	if(l==r){
		get<0>(tree[node])=arr[l];
		get<1>(tree[node])=arr[l];
		get<2>(tree[node])=0;
		return;
	}
	int m=(l+r)/2;
	build(2*node,l,m);
	build(2*node+1,m+1,r);
	tree[node]=merge(tree[2*node],tree[2*node+1]);
}
tuple<int,int,int>query(int node,int l,int r,int ql,int qr){
	if(qr<l||r<ql||l>r){
		return f_tuple();
	}
	if(ql<=l&&r<=qr){
		return tree[node];
	}
	int m=(l+r)/2;
	tuple<int,int,int>x=query(2*node,l,m,ql,qr);
	tuple<int,int,int>y=query(2*node+1,m+1,r,ql,qr);
	return merge(x,y);
}
void solve(){
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	build(1,1,n);
	while(q--){
		int l,r,k;
		cin>>l>>r>>k;
		tuple<int,int,int>ans=query(1,1,n,l,r);
		if(get<2>(ans)<=k){
			cout<<1<<endl;
		}
		else{
			cout<<0<<endl;
		}
	}
}
signed main(){
	IOS;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 20 ms 3512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 7456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -