제출 #340719

#제출 시각아이디문제언어결과실행 시간메모리
340719katearimaHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
3047 ms74944 KiB
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,m, tree[4*N], a[N];
struct book{
	int x, mood, ind;
};
struct books {
	int x, y;
	int sum;
	bool operator<(books const& other) {
        return y < other.y;
    }
};
int ans[N];
vector<book> q[N];
vector<books> v;
stack<int> st;
void update(int i, int x, int y, int k, int val){
	if(y<k || x>k) return; 
	if(k>=x && k<=y) {
		tree[i]=max(tree[i], val);
		if(x==y) return;
	}
	int mid=(x+y)/2;
	update(2*i+1, x,  mid, k, val);
	update(2*i+2, mid+1, y, k,val);
}
int getmax(int i, int x, int y, int l , int r){
	if(r<x || l>y) return 0;
	if(x>=l && y<=r) return tree[i];
	int mid=(x+y)/2;
	return max(getmax(2*i+1,x, mid , l, r), getmax(2*i+2, mid+1, y, l, r));
}
main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n>>m;
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	for(int i=0; i<m; i++){
		int l, r, k;
		cin>>l>>r>>k;
		l--; r--;
		q[r].push_back({l,k,i});
	}
    
	for(int i=n-1; i>=0; i--){
		while(st.size()!=0 && a[st.top()]<a[i]){
			v.push_back({i, st.top(), a[i]+a[st.top()] });
			st.pop();
		}
        if(st.size()==0 || a[i]<a[st.top()]){
    		st.push(i);
		}
	}
	v.push_back({n+1, n+1, n+1});
	//v[v.size()+1].
	sort(v.begin(), v.end());
	
	for(int j=0; j<min(n,v[0].y); j++){
			
		
		for(auto k: q[j]){
			int mx=getmax(0,0,n-1,k.x, j);
			//cout<<i<<" "<<k.x<<" "<<k.mood<<" "<<k.ind<<" "<<mx<<endl;
			if(mx<=k.mood) ans[k.ind]=1;
			else ans[k.ind]=0;
		}
	}

	for(int i=0; i<v.size()-1; i++){
		update(0,0,n-1,v[i].x, v[i].sum);
		for(int j=v[i].y; j<min(n,v[i+1].y); j++){
			
		
		for(auto k: q[j]){
			int mx=getmax(0,0,n-1,k.x, j);
			//cout<<i<<" "<<k.x<<" "<<k.mood<<" "<<k.ind<<" "<<mx<<endl;
			if(mx<=k.mood) ans[k.ind]=1;
			else ans[k.ind]=0;
		}
		}
	}
	for(int i=0; i<m; i++){
		cout<<ans[i]<<endl;
	}
	
}
/*
i wanna win a medal in IZHO
wir werden gegen unser schickas ankampfen
if you watch shingeki no kyojin(AOT) you can take my code
*/

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

sortbooks.cpp:35:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   35 | main(){
      |      ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:72:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<books>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |  for(int i=0; i<v.size()-1; i++){
      |               ~^~~~~~~~~~~
#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...