답안 #498445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498445 2021-12-25T08:10:13 Z Mr_Husanboy Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
17 / 100
3000 ms 41204 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 ;
			}
		}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 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 3 ms 204 KB Output is correct
8 Correct 16 ms 204 KB Output is correct
9 Correct 4 ms 204 KB Output is correct
10 Correct 3 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 3 ms 204 KB Output is correct
8 Correct 16 ms 204 KB Output is correct
9 Correct 4 ms 204 KB Output is correct
10 Correct 3 ms 204 KB Output is correct
11 Correct 10 ms 460 KB Output is correct
12 Correct 11 ms 684 KB Output is correct
13 Correct 14 ms 700 KB Output is correct
14 Correct 21 ms 760 KB Output is correct
15 Correct 16 ms 824 KB Output is correct
16 Correct 1632 ms 696 KB Output is correct
17 Correct 674 ms 548 KB Output is correct
18 Correct 235 ms 668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3070 ms 41204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3029 ms 5068 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 3 ms 204 KB Output is correct
8 Correct 16 ms 204 KB Output is correct
9 Correct 4 ms 204 KB Output is correct
10 Correct 3 ms 204 KB Output is correct
11 Correct 10 ms 460 KB Output is correct
12 Correct 11 ms 684 KB Output is correct
13 Correct 14 ms 700 KB Output is correct
14 Correct 21 ms 760 KB Output is correct
15 Correct 16 ms 824 KB Output is correct
16 Correct 1632 ms 696 KB Output is correct
17 Correct 674 ms 548 KB Output is correct
18 Correct 235 ms 668 KB Output is correct
19 Execution timed out 3045 ms 11660 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 3 ms 204 KB Output is correct
8 Correct 16 ms 204 KB Output is correct
9 Correct 4 ms 204 KB Output is correct
10 Correct 3 ms 204 KB Output is correct
11 Correct 10 ms 460 KB Output is correct
12 Correct 11 ms 684 KB Output is correct
13 Correct 14 ms 700 KB Output is correct
14 Correct 21 ms 760 KB Output is correct
15 Correct 16 ms 824 KB Output is correct
16 Correct 1632 ms 696 KB Output is correct
17 Correct 674 ms 548 KB Output is correct
18 Correct 235 ms 668 KB Output is correct
19 Execution timed out 3070 ms 41204 KB Time limit exceeded
20 Halted 0 ms 0 KB -