제출 #898364

#제출 시각아이디문제언어결과실행 시간메모리
898364penguin133Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
1437 ms217428 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pair<int, int> > 
#define fi first
#define se second
int n,m,q;
stack<int>st;
struct node{
	int s,e,m,val;
	node *l, *r;
	node(int _s, int _e){
		s = _s, e = _e, m = (s + e)/2;
		val = 0;
		if(s != e)l = new node(s, m), r = new node(m+1, e);
	}
	void upd(int p, int v){
		if(s == e)val = max(val, v);
		else{
			if(p <= m)l->upd(p, v);
			else r->upd(p, v);
			val = max(l->val, r->val);
		}
	}
	int query(int a, int b){
		if(s == a && e == b)return val;
		else if(b <= m)return l->query(a, b);
		else if(a > m)return r->query(a, b);
		else return max(l->query(a, m), r->query(m+1, b));
	}
}*root;
int A[1000005], ans[1000005];
vector<pii> Q[1000005];
void solve(){
	cin >> n >> q;
	for(int i=1;i<=n;i++)cin >> A[i];
	for(int i=1;i<=q;i++){
		int x,y,z;
		cin >> x >> y >> z;
		Q[y].push_back({x, {z, i}});
	}
	root = new node(1, n);
	for(int i=1;i<=n;i++){
		while(!st.empty() && A[st.top()] <= A[i])st.pop();
		if(!st.empty()){
			int x = st.top();
			root->upd(x, A[st.top()] + A[i]);		
		}
		for(auto j : Q[i]){
			int x = j.fi, y = j.se.fi, z = j.se.se;
			ans[z] = (root->query(x, i) <= y);
		}
		st.push(i);
	}
	for(int i=1;i<=q;i++)cout << ans[i] << "\n";
}
 
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}

컴파일 시 표준 에러 (stderr) 메시지

sortbooks.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...