Submission #651293

# Submission time Handle Problem Language Result Execution time Memory
651293 2022-10-18T07:17:12 Z alvingogo Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
13 / 100
1152 ms 88556 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
#define int long long
using namespace std;

struct ST{
	vector<int> st;
	void init(int x){
		st.resize(4*x);
	}
	void update(int v,int L,int R,int p,int s){
		if(L==R){
			st[v]=max(st[v],s);
			return;
		}
		int m=(L+R)/2;
		if(p<=m){
			update(2*v+1,L,m,p,s);
		}
		else{
			update(2*v+2,m+1,R,p,s);
		}
		st[v]=max(st[2*v+1],st[2*v+2]);
	}
	int query(int v,int L,int R,int l,int r){
		if(L==l && r==R){
			return st[v];
		}
		int m=(L+R)/2;
		if(r<=m){
			return query(2*v+1,L,m,l,r);
		}
		else if(l>m){
			return query(2*v+2,m+1,R,l,r);
		}
		else{
			return max(query(2*v+1,L,m,l,m),query(2*v+2,m+1,R,m+1,r));
		}
	}
}st;
struct QU{
	int l,r,k;
	int id;
};
bool cmp(QU a,QU b){
	return a.r<b.r;
}
signed main(){
    AquA;
	int n,m;
	cin >> n >> m;
	st.init(n);
	vector<int> v(n);
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	vector<QU> vq(m);
	vector<int> ans(m);
	for(int i=0;i<m;i++){
		cin >> vq[i].l >> vq[i].r >> vq[i].k;
		vq[i].l--;
		vq[i].r--;
		vq[i].id=i;
	}
	sort(vq.begin(),vq.end(),cmp);
	int r=0;
	vector<int> s;
	for(int i=0;i<n;i++){
		while(s.size() && v[s.back()]>v[i]){
			st.update(0,0,n-1,s.back(),v[s.back()]+v[i]);
			s.pop_back();
		}
		s.push_back(i);
		while(r<m && vq[r].r==i){
			ans[vq[r].id]=(st.query(0,0,n-1,vq[r].l,i)<=vq[r].k)?1:0;
			r++;
		}
	}
	for(int i=0;i<m;i++){
		cout << ans[i] << "\n";
	}
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1093 ms 80516 KB Output is correct
2 Correct 1087 ms 80588 KB Output is correct
3 Correct 1084 ms 80588 KB Output is correct
4 Correct 1152 ms 80500 KB Output is correct
5 Correct 1016 ms 88556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 95 ms 8788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -