답안 #498417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498417 2021-12-25T07:00:54 Z Mr_Husanboy Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
3000 ms 88048 KB
//Author: 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);
#define all(a) a.begin(),a.end()
const double PI=3.1415926535897932384626433832795;
// 0-9 >> 48-57;    A-Z>>65-90   and   a-z>>97-122 respectively;
//int ans[20][200001];
const int N=1e6;
ll tree[N+1]; ll a[N+1];
vector<ll> mintree(N+1,2000000000ll);
map<ll,ll> mp;
int n;



void add(ll k,ll x){
	while(k<=n){
		if(tree[k]<=x){
			tree[k]=x;
		//	tree[k].second=k;
		}
		mintree[k]=min(mintree[k],x);
		k+=k&(-k);
	}
}

void build(){
	for(int i=1;i<=n;i++){
		add(i,a[i]);
	}
}


ll get(int l, int r){
	ll s=0;
	while(r>=l){
		s=max(s,tree[r]);
		r-=r&-r;
	}
	return s;
}
void solve(){
	int l,r;ll k; cin>>l>>r>>k;
	while(l<r){
		ll ans=(get(l,r));
		if(mp[ans]!=r){
			if(get(mp[ans]+1,r)+ans>k){
				cout<<"0\n"; return ;
			}
		}r--;
	}
	cout<<"1\n";
}



int main(){
    int q;
    cin>>n>>q;
    for(int i=1;i<=n;i++) cin>>a[i],mp[a[i]]=i;
    build();
    //for(int i=1;i<=n;i++) cout<<i<<": "<<mintree[i]<<"\n";
    while(q--){
    	solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8132 KB Output is correct
2 Correct 4 ms 8012 KB Output is correct
3 Incorrect 5 ms 8140 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8132 KB Output is correct
2 Correct 4 ms 8012 KB Output is correct
3 Incorrect 5 ms 8140 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3016 ms 88048 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3027 ms 10384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8132 KB Output is correct
2 Correct 4 ms 8012 KB Output is correct
3 Incorrect 5 ms 8140 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8132 KB Output is correct
2 Correct 4 ms 8012 KB Output is correct
3 Incorrect 5 ms 8140 KB Output isn't correct
4 Halted 0 ms 0 KB -