제출 #1156506

#제출 시각아이디문제언어결과실행 시간메모리
1156506ghammazhassanHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
30 / 100
1311 ms166508 KiB
// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
using namespace std;
#define int long long
const int N=1e6+5;
const int M=998244353;
const int LOG = 20;
int n , m , k , c , t=1 , q=1 , x , y , p[N];
vector<int>a(N),b(N);
int sg[LOG][N];
void makesg(){
	for (int i=0;i<N;i++){
		sg[0][i]=b[i];
	}
	for (int j=1;j<LOG;j++){
		for (int i=(int)pow(2,j)-1;i<N;i++){
			sg[j][i]=max(sg[j-1][i],sg[j-1][i-(int)pow(2,j-1)]);
		}
	}
}
int lr(int l,int r){
	int x=log2(r-l+1);
	return max(sg[x][r],sg[x][l+(int)pow(2,x)-1]);
}
const int N1=5005;
const int LOG1=13;
int sf[LOG1][N1];
void makesf(){
	for (int i=0;i<N1;i++){
		sf[0][i]=a[i];
	}
	for (int j=1;j<LOG1;j++){
		for (int i=(int)pow(2,j)-1;i<N1;i++){
			sf[j][i]=max(sf[j-1][i],sf[j-1][i-(int)pow(2,j-1)]);
		}
	}
}
int lrf(int l,int r){
	int x=log2(r-l+1);
	return max(sf[x][r],sf[x][l+(int)pow(2,x)-1]);
}
void solve()
{
	cin >> n >> m;
	for (int i=0;i<n;i++){
		cin >> a[i];
	}	
	for (int i=0;i<n-1;i++){
		b[i]=a[i+1]<a[i];
	}
	if (n<=5000 and m<=5000){
		makesf();
		for (int q=0;q<m;q++){
			cin >> x >> y >> c;
			y--;
			x--;
			int f=0;
			for (int i=y;i>x;i--){
				int o=lrf(x,i-1);
				f=max(f,(a[i]+o)*(o>a[i]));
			}
			// cout << f << " ";
			if (f>c){
				cout << 0 << endl;
			}
			else{
				cout << 1 << endl;
			}
		}
		return;
	}
	// for (int i=0;i<n-1;i++){
	// 	cout << b[i] << " ";
	// }
	// cout << endl;
	makesg();
	// cout << lr(2,2) << endl;
	for (int i=0;i<m;i++){
		cin >> x >> y >> c;
		if (x==y){
			cout << 1 << endl;
			continue;
		}
		if (lr(x-1,y-2)){
			cout << 0 << endl;
		}
		else{
			cout << 1 << endl;
		}
	}



}
signed main()
{

    ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE
    cin.tie(0), cout.tie(0);//DO NOT USE IN INTERACTIVE
    cout << fixed<<setprecision(9);
    // int t=1;
    // cin >> t;
    for (int _=1;_<=t;_++){
    	solve();
    	q++;
    }
}
#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...