Submission #657917

# Submission time Handle Problem Language Result Execution time Memory
657917 2022-11-11T17:02:44 Z Danilo21 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
819 ms 73548 KB
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))

using namespace std;

const ll LINF = 4e18;

class segtree{

    int n;
    vector<ll> tree;

    ll update(int s, int l, int r, int pos, ll x){
        if (l > pos || r < pos) return tree[s];
        if (l == r) return smax(tree[s], x);
        int m = (l + r)>>1;
        ll a = update(2*s, l, m, pos, x);
        ll b = update(2*s+1, m+1, r, pos, x);
        return smax(tree[s], max(a, b));
    }

    ll query(int s, int l, int r, int ql, int qr) const {
        if (l > qr || r < qr) return -LINF;
        if (l >= ql && r <= qr) return tree[s];
        int m = (l + r)>>1;
        ll a = query(2*s, l, m, ql, qr);
        ll b = query(2*s+1, m+1, r, ql, qr);
        return max(a, b);
    }

public:
    segtree(int n = 0){ Assign(n); }
    void Assign(int s){
        n = highpow(s);
        if (bitcnt(s) > 1) n <<= 1;
        tree.assign(2*n, 0);
    }
    void update(int pos, ll x){ update(1, 0, n-1, pos, x); }
    ll query(int l, int r) const { return query(1, 0, n-1, l, r); }
};

const int mxN = 1e6+10, INF = 2e9;
ll n, m, a[mxN], f[mxN], ans[mxN];
array<ll, 4> q[mxN];
segtree st;

void Solve(){

    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    stack<ll> stk;
    for (int i = 0; i < n; i++){
        while (stk.size() && a[stk.top()] <= a[i]) stk.pop();
        f[i] = (stk.size() ? stk.top() : -1);
        stk.push(i);
    }
    for (int i = 0; i < m; i++){
        cin >> q[i][1] >> q[i][0] >> q[i][2];
        q[i][3] = i;
    }
    sort(q, q+n);
    st.Assign(n);
    for (int i = 0, j = 0; j < m; j++){
        auto [r, l, k, t] = q[j];
        for (; i < n && i <= r; i++)
            if (~f[i])
                st.update(f[i], a[i] + a[f[i]]);
        if (st.query(l, r) <= k) ans[t] = 1;
    }
    for (int i = 0; i < m; i++)
        cout << ans[i] << en;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); cerr.tie(0);
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;
    cerr << "Started!" << endl;

    int t = 1;
    //cin >> t;
    while (t--)
        Solve();

    return 0;
}

Compilation message

sortbooks.cpp: In function 'void Solve()':
sortbooks.cpp:91:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   91 |         auto [r, l, k, t] = q[j];
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 819 ms 73548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 8040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -