Submission #519537

# Submission time Handle Problem Language Result Execution time Memory
519537 2022-01-26T15:03:31 Z Dasha_Gnedko Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
13 / 100
1698 ms 88444 KB
#include <bits/stdc++.h>

//#include <ext/pb_ds/detail/standard_policies.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

using namespace std;

//using namespace __gnu_pbds;
//template <typename T> using ordered_set = tree <T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 gen(time(0));

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define sz(a) int32_t(a.size())
#define endl '\n'
//#define int long long

const int N = 1e6 + 100;
const int M = 31;
const int mod = 998244353;
const int inf = 2e9 + 100;

int a[N];

struct DO
{
    vector < int > t, add;
    int pr = 2;

    void build(int n)
    {
        while (pr < n) pr *= 2;
        t.resize(2 * pr, 0);
        add.resize(2 * pr, 0);
        for(int i = pr; i < pr + n; i++)
            t[i] = a[i - pr];
        for(int v = pr - 1; v > 0; v--)
            t[v] = max(t[v * 2], t[v * 2 + 1]);
    }

    void push(int v)
    {
        t[v * 2] += add[v]; t[v * 2 + 1] += add[v];
        add[v * 2] += add[v]; add[v * 2 + 1] += add[v];
        add[v] = 0;
    }

    void upd(int l, int r, int v, int cl, int cr, int zn)
    {
        if (l > r) return;
        if (cr < l || r < cl) return;
        if (cl != cr) push(v);
        if (l <= cl && cr <= r)
        {
            t[v] += zn;
            add[v] += zn;
            return;
        }
        int mid = (cl + cr) / 2;
        upd(l, r, v * 2, cl, mid, zn);
        upd(l, r, v * 2 + 1, mid + 1, cr, zn);
        t[v] = max(t[v * 2], t[v * 2 + 1]);
    }

    int get(int l, int r, int v, int cl, int cr)
    {
        if (cr < l || r < cl) return 0;
        if (cl != cr) push(v);
        if (l <= cl && cr <= r) return t[v];
        int mid = (cl + cr) / 2;
        return max(get(l, r, v * 2, cl, mid), get(l, r, v * 2 + 1, mid + 1, cr));
    }
};

DO t;
vector < pair < pair < int, int >, int > > ask[N];
int ans[N];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // LOCAL

    int n, q;
    cin >> n >> q;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    t.build(n);
    for(int i = 0; i < q; i++)
    {
        int l, r, k;
        cin >> l >> r >> k;
        l--; r--;
        ask[l].pb({{r, k}, i});
    }
    vector < pair < pair < int, int >, int > > b;
    int ls = n - 1;
    for(int i = n - 1; i >= 0; i--)
    {
        if (i + 1 < n && a[i + 1] < a[i]) ls = i;
        while (sz(b) && b.back().S < a[i])
        {
            t.upd(b.back().F.F + 1, b.back().F.S, 1, 0, t.pr - 1, -b.back().S);
            b.pop_back();
        }

        if (!sz(b))
        {
            b.pb({{i, n - 1}, a[i]});
            t.upd(i + 1, n - 1, 1, 0, t.pr - 1, a[i]);
        }
        else
        {
            t.upd(i + 1, b.back().F.F - 1, 1, 0, t.pr - 1, a[i]);
            b.pb({{i, b.back().F.F - 1}, a[i]});
        }
        for(auto to: ask[i])
            ans[to.S] = (t.get(ls + 1, to.F.F, 1, 0, t.pr - 1) <= to.F.S);
    }
    for(int i = 0; i < q; i++)
        cout << ans[i] << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23776 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Incorrect 13 ms 23820 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23776 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Incorrect 13 ms 23820 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1663 ms 73016 KB Output is correct
2 Correct 1651 ms 76540 KB Output is correct
3 Correct 1698 ms 76412 KB Output is correct
4 Correct 1649 ms 76572 KB Output is correct
5 Correct 765 ms 88444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 137 ms 30344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23776 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Incorrect 13 ms 23820 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23776 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Incorrect 13 ms 23820 KB Output isn't correct
4 Halted 0 ms 0 KB -