Submission #651300

# Submission time Handle Problem Language Result Execution time Memory
651300 2022-10-18T07:34:24 Z alvingogo Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
13 / 100
636 ms 33696 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
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 BIT{
	int n;
	vector<int> bt;
	void init(int x){
		n=x;
		bt.resize(n+1);
	}
	void update(int x,int y){
		x++;
		for(;x>0;x-=(x&-x)){
			bt[x]=max(bt[x],y);
		}
	}
	int query(int x){
		x++;
		int ans=0;
		for(;x<=n;x+=(x&-x)){
			ans=max(ans,bt[x]);
		}
		return ans;
	}
}bt;
struct QU{
	int l,r,k;
	int id;
};
bool cmp(QU a,QU b){
	return a.r<b.r;
}
int main(){
    AquA;
	int n,m;
	cin >> n >> m;
	bt.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]){
			bt.update(s.back(),v[s.back()]+v[i]);
			s.pop_back();
		}
		s.push_back(i);
		while(r<m && vq[r].r==i){
			if(bt.query(vq[r].l)<=vq[r].k){
				ans[vq[r].id]=1;
			}
			r++;
		}
	}
	for(int i=0;i<m;i++){
		cout << ans[i] << "\n";
	}
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
2 Correct 1 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 612 ms 29640 KB Output is correct
2 Correct 622 ms 29644 KB Output is correct
3 Correct 632 ms 29640 KB Output is correct
4 Correct 636 ms 29632 KB Output is correct
5 Correct 599 ms 33696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 3188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -