답안 #498453

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498453 2021-12-25T08:18:38 Z Mr_Husanboy Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
3000 ms 41060 KB
// Muallif: Mansuraliyev Husanboy Murotali o'g'li  >> NamPS

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const double PI=3.1415926535897932384626433832795;
// 0-9 >> 48-57;    A-Z>>65-90   and   a-z>>97-122 respectively;

const int N=1e6+1;

ll a[N]; //map<ll,ll> mp;
pair<ll,int> tree[N*2+1];
int n;

void build(int x,int l, int r){
	if(l==r){
		tree[x].first=a[l];
		tree[x].second=l;return;
	}
	int m=(l+r)/2;
	build(x*2,l,m); build(x*2+1,m+1,r);
	if(tree[x*2].first>tree[x*2+1].first){
		tree[x]=tree[x*2];
	}else{
		tree[x]=tree[x*2+1];
	}
	return;
}

pair<ll,int> get(int x, int l, int r, int ll, int rr){
	if(ll>r||rr<l){
		return {-1,-1};
	}
	if(l>=ll&&r<=rr){
		return tree[x];
	}
	int m=(l+r)/2;
	auto as=get(x*2,l,m,ll,rr);
	auto bs=get(x*2+1,m+1,r,ll,rr);
	if(as.first>bs.first){
		return as;
	}
	return bs;
}

void solve(){
	int l,r;ll k; cin>>l>>r>>k;
	while(l<r){
		pair<ll,int> ans=get(1,1,n,l,r);//cout<<ans.second<<"gh ";
		
		if(ans.second!=r){
			pair<ll,int> p=get(1,1,n,ans.second+1,r); //cout<<p.first<<" ";
			if(p.first+ans.first>k){
				cout<<"0\n"; return ;
			}else{
				cout<<"1\n";return;
			}
		}r--;
	}
	cout<<"1\n";
}

int main(){
	int m; cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];//,mp[a[i]]=i;
	build(1,1,n);
	/*for(int i=1;i<=2*n;i++){
		cout<<i<<": "<<tree[i].first<<' '<<tree[i].second<<"\n";
	}*/
	while(m--){
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 2 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 2 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3089 ms 41060 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 291 ms 6724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 2 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 2 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -