| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 889786 | vjudge1 | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e6+10;
int a[N], pref[N];
int ans[N][N];
int main(){
int n, q;
cin >> n >> q;
a[0]=1e9+10;
for(int i=1; i<=n; i++){
cin>>a[i];
}
for(int i=1; i<=n; i++) {
pref[i]=i-1;
while(a[i]>=a[pref[i]]) {
pref[i]=pref[pref[i]];
}
}
for(int i=1; i<=n; i++){
ans[i][i]=0;
for(int j=i+1; j<=n; j++){
ans[i][j]=ans[i][j-1];
if(pref[j]>=i){
ans[i][j]=max(ans[i][j], a[pref[j]] + a[j]);
}
}
}
while(q--){
int l, r, k;
cin >> l >> r >> k;
if(ans[l][r]<=k){
cout<<"1\n";
}
else{
cout<<"0\n";
}
}
}
