Submission #502583

#TimeUsernameProblemLanguageResultExecution timeMemory
502583stanislavpolynHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
17 / 100
3075 ms28496 KiB
#include <bits/stdc++.h>

#define fr(i, a, b) for(int i = (a); i <= (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pw(x) (1LL << (x))

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

template<typename T>
bool umn(T& a, T b) { return (a > b ? (a = b, 1) : 0); }
template<typename T>
bool umx(T& a, T b) { return (a < b ? (a = b, 1) : 0); }

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>
using ve = vector<T>;

const int N = 1e6 + 5;

int n, m;
int a[N];
int nxt[N], prv[N];
ve<array<int, 4>> Q;

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
#else
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif

    cin >> n >> m;

    fr(i, 1, n) cin >> a[i];

    fr(i, 1, n) {
        nxt[i] = -1;
        prv[i] = -1;
    }

    ve<pii> st;
    rf(i, n, 1) {
        while(sz(st) && st.back().fi < a[i]) {
            prv[st.back().se] = i;
            st.pop_back();
        }
        st.pb({a[i], i});
    }

    fr(i, 1, m) {
        int l, r, k;
        cin >> l >> r >> k;
        Q.pb(array<int, 4>{l, r, k, i});
    }

    fr(i, 0, m - 1) {
        int l, r, k, idx;
        l = Q[i][0];
        r = Q[i][1];
        k = Q[i][2];

        int ans = 0;
        fr(j, l, r) {
            if(prv[j] >= l) {
                umx(ans, a[j] + a[prv[j]]);
            }
        }
//        cout << ans << "\n";

        cout << (ans > k ? 0 : 1) << "\n";
    }

    return 0;
}

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:83:22: warning: unused variable 'idx' [-Wunused-variable]
   83 |         int l, r, k, idx;
      |                      ^~~
#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...