Submission #651225

#TimeUsernameProblemLanguageResultExecution timeMemory
651225becaidoHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
30 / 100
519 ms10212 KiB
#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define Waimai ios::sync_with_stdio(false),cin.tie(0)
#define FOR(x,a,b) for(int x=a,I=b;x<=I;x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 1e6 + 5;

int n, q;
int a[SIZE], to[SIZE];

void solve2() {
    while (q--) {
        int l, r, k;
        cin >> l >> r >> k;
        int mx = 0;
        bool f = 1;
        FOR (i, l, r) {
            if (mx > max (a[i], k - a[i])) {
                f = 0;
                break;
            }
            mx = max (mx, a[i]);
        }
        cout << f << '\n';
    }
}

void solve() {
    cin >> n >> q;
    FOR (i, 1, n) cin >> a[i];
    if (n <= 5000) {
        solve2();
        return;
    }
    int cnt = 0;
    FOR (i, 1, n) {
        FOR (j, i, n) {
            if (j == n || a[j + 1] < a[j]) {
                FOR (k, i, j) to[k] = cnt;
                cnt++;
                i = j;
                break;
            }
        }
    }
    while (q--) {
        int l, r, k;
        cin >> l >> r >> k;
        cout << (to[l] == to[r]) << '\n';
    }
}

int main() {
    Waimai;
    solve();
}
/*
5 2
3 5 1 8 2
1 3 6
2 5 3
*/
#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...