제출 #286764

#제출 시각아이디문제언어결과실행 시간메모리
286764errorgornHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
3055 ms104560 KiB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,q;
int arr[1000005];
int lp[1000005];

struct node{
	int s,e,m;
	int mn,mx;
	node *l,*r;

	node (int _s,int _e){
		s=_s,e=_e,m=s+e>>1;
		
		if (s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
			
			mn=min(l->mn,r->mn);
			mx=max(l->mx,r->mx);
		}
		else{
			mn=mx=arr[s];
		}
	}
	
	int query_mn(int i,int j){
		if (s==i && e==j) return mn;
		else if (j<=m) return l->query_mn(i,j);
		else if (m<i) return r->query_mn(i,j);
		else return min(l->query_mn(i,m),r->query_mn(m+1,j));
	}
	
	int query_mx(int i,int j){
		if (s==i && e==j) return mx;
		else if (j<=m) return l->query_mx(i,j);
		else if (m<i) return r->query_mx(i,j);
		else return max(l->query_mx(i,m),r->query_mx(m+1,j));
	}
} *root;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n>>q;
	rep(x,0,n) cin>>arr[x];
	
	rep(x,0,n){
		if (x==0 || arr[x-1]>arr[x]) lp[x]=x;
		else lp[x]=lp[x-1];
	}
	
	root=new node(0,1000005);
	
	int a,b,c;
	while (q--){
		cin>>a>>b>>c;
		
		a--,b--;
		
		if (lp[b]<=a){
			cout<<1<<endl;
			continue;
		}
		
		int lo=lp[b]-1,hi=b+1,mi;
		//rep(x,lo,hi) cout<<root->query_mx(a,x-1)<<" "<<arr[x]<<endl;
		
		int w=root->query_mx(a,lo);
		while (hi-lo>1){
			mi=lo+hi>>1;
			
			if (w<arr[mi]) hi=mi;
			else lo=mi;
		}
		
		//cout<<lo<<endl;
		//cout<<root->query_mn(a,lo)<<" "<<root->query_mx(a,lo)<<endl;
		if (root->query_mn(a,lo)+root->query_mx(a,lo)<=c) cout<<1<<endl;
		else cout<<0<<endl;
	}
}

컴파일 시 표준 에러 (stderr) 메시지

sortbooks.cpp: In constructor 'node::node(int, int)':
sortbooks.cpp:38:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |   s=_s,e=_e,m=s+e>>1;
      |               ~^~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:99:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   99 |    mi=lo+hi>>1;
      |       ~~^~~
#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...