제출 #1324246

#제출 시각아이디문제언어결과실행 시간메모리
1324246seyityunusHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
0 / 100
118 ms17024 KiB
#include "bits/stdc++.h"
using namespace std;

#define ll  long long
#define pb  push_back
#define ppb  pop_back
#define inf  1e18
#define all(v)   v.begin(), v.end()
#define ff  first
#define ss  second
#define sz  size
#define intmx  INT_MAX
#define intmn   INT_MIN

const int N = 100001;
const int K = 20;
int st[N][K];
int stm[N][K];
int lg[N];

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n+1);
    for(int i=1; i<=n; i++) {
        cin >> a[i];
    }
    lg[1]=0;
    for(int i=2; i<=n; i++) {
        lg[i]=lg[i/2]+1;
    }
    for(int i=1; i<=n; i++) {
        st[i][0]=a[i];
    }
    for(int j=1; j<K; j++) {
        for(int i=1; i+(1<<j)-1<=n; i++) {
            st[i][j]=min(st[i][j-1], st[i+(1<<(j-1))][j-1]);
        }
    }
    for(int i=1; i<=n; i++) {
        stm[i][0]=a[i];
    }
    for(int j=1; j<K; j++) {
        for(int i=1; i+(1<<j)-1<=n; i++) {
            stm[i][j]=max(stm[i][j-1], stm[i+(1<<(j-1))][j-1]);
        }
    }
    while(q--) {
        int l, r, k;
        cin >> l >> r >> k;
        int j=lg[r-l+1];
        int mn=min(st[l][j], st[r-(1<<j)+1][j]);
        int mx=max(stm[l][j], stm[r-(1<<j)+1][j]);
        if(mn+mx<=k) cout << 1 << endl;
        else cout << 0 << endl;
    }
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t=1;
    while(t--) {
        solve();
    }
    return 0;
}
#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...