Submission #1352179

#TimeUsernameProblemLanguageResultExecution timeMemory
1352179fgggHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
0 / 100
3094 ms16096 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
void solve() {
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n);
    for (ll& x : a) cin >> x;
    while (q--) {
        ll l, r, k;
        cin >> l >> r >> k;
        l--, r--;
        vector<ll> b = a;
        ll ans = 1;
        for (ll _ = 0; _ < r - l; _++) {
            ll pmi = l + _;
            for (ll j = l + _; j <= r; j++) {
                if (b[j] < b[pmi]) pmi = j;
            }
            for (ll j = pmi - 1; j >= l; j--) {
                if (b[j] + b[j + 1] <= k) swap(b[j], b[j + 1]);
                else ans = 0;
            }
        }
        cout << ans << '\n';
    }
}
signed main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    ll t = 1;
    //cin >> t;
    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...