Submission #340170

#TimeUsernameProblemLanguageResultExecution timeMemory
340170katearimaHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
3068 ms23424 KiB
#include <bits/stdc++.h>
using namespace std;
const int N=1000005;
int n,m, a[N], tree[2*N+1], mxswap[2*N+1], ans, high;
struct books {
	int x, y;
	int sum;
};
stack<int> st;
vector<books> v;
void update (int i, int x, int y, int l, int r, int k){
    if(l>=x && r<=y) {
        tree[i]=max(tree[i], k);
        int mid=(x+y)/2;
        update(2*i+1, x, mid , l , r, k);
        update(2*i+2, mid+1, y, l, r, k);
    }
    else return;
}
int getmax(int i, int x, int y, int l , int r){
	if(y<l || x>r) 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(){
	cin>>n>>m;
	for(int i=0; i<n; i++){
		cin>>a[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);
		}
	}
	for(int i=0; i<v.size(); i++){
        update(0,0,n-1,v[i].x, v[i].y, v[i].sum);
	}
	for(int i=0; i<m; i++){
        int l , r,k;
        cin>>l>>r>>k;
        l--; r--;
        if(k>=getmax(0,0,n-1,l, r)) cout<<"1"<<endl;
        else cout<<"0"<<endl;
        //cout<<getmax(0,0,n-1,l, r);
	}


}

Compilation message (stderr)

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