Submission #519517

# Submission time Handle Problem Language Result Execution time Memory
519517 2022-01-26T13:21:50 Z Dasha_Gnedko Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
3000 ms 196300 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 < vector < int > > t;
    vector < pair < int, int > > li;
    vector < int > ans;
    int pr = 2;

    void build(int n)
    {
        while (pr < n) pr *= 2;
        t.resize(2 * pr);
        ans.resize(2 * pr, 0);
        for(int i = pr; i < pr + n; i++)
            t[i].pb(a[i - pr]);
        for(int v = pr - 1; v > 0; v--)
        {
            ans[v] = max(ans[v * 2], ans[v * 2 + 1]);
            for(auto to: t[v * 2 + 1])
            {
                if (t[v * 2].back() <= to) break;
                ans[v] = max(ans[v], t[v * 2].back() + to);
            }
            int i = 0, j = 0;
            while (i < sz(t[v * 2]) || j < sz(t[v * 2 + 1]))
            {
                if (j == sz(t[v * 2 + 1]) || (i < sz(t[v * 2]) && t[v * 2][i] <= t[v * 2 + 1][j])) t[v].pb(t[v * 2][i++]);
                else t[v].pb(t[v * 2 + 1][j++]);
            }
        }
    }

    void get_ans(int l, int r, int v, int cl, int cr)
    {
        if (cr < l || r < cl) return;
        if (l <= cl && cr <= r)
        {
            li.pb({v, ans[v]});
            return;
        }
        int mid = (cl + cr) / 2;
        get_ans(l, r, v * 2, cl, mid);
        get_ans(l, r, v * 2 + 1, mid + 1, cr);
    }

    int get(int l, int r)
    {
        li.clear();
        get_ans(l, r, 1, 0, pr - 1);
        int ans = 0;
        for(auto to: li)
            ans = max(ans, to.S);
        int mx = 0;
        for(int i = 0; i < sz(li) - 1; i++)
        {
            int v = li[i].F, u = li[i + 1].F;
            mx = max(mx, t[v].back());
            int l = 0, r = sz(t[u]) - 1;
            while (l <= r)
            {
                int mid = (l + r) / 2;
                if (t[u][mid] >= mx) r = mid - 1;
                else
                {
                    ans = max(ans, mx + t[u][mid]);
                    l = mid + 1;
                }
            }
        }
        return ans;
    }
};

DO t;

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);
    while (q--)
    {
        int l, r, k;
        cin >> l >> r >> k;
        l--; r--;
        cout << (t.get(l, r) <= k) << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 5 ms 1348 KB Output is correct
13 Correct 5 ms 1356 KB Output is correct
14 Correct 8 ms 1464 KB Output is correct
15 Correct 7 ms 1484 KB Output is correct
16 Correct 6 ms 1356 KB Output is correct
17 Correct 6 ms 1100 KB Output is correct
18 Correct 6 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3077 ms 196300 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 195 ms 22064 KB Output is correct
2 Correct 190 ms 22148 KB Output is correct
3 Correct 178 ms 22068 KB Output is correct
4 Correct 172 ms 22024 KB Output is correct
5 Correct 161 ms 22124 KB Output is correct
6 Correct 126 ms 21980 KB Output is correct
7 Correct 123 ms 21876 KB Output is correct
8 Correct 163 ms 21820 KB Output is correct
9 Correct 38 ms 1816 KB Output is correct
10 Correct 137 ms 21752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 5 ms 1348 KB Output is correct
13 Correct 5 ms 1356 KB Output is correct
14 Correct 8 ms 1464 KB Output is correct
15 Correct 7 ms 1484 KB Output is correct
16 Correct 6 ms 1356 KB Output is correct
17 Correct 6 ms 1100 KB Output is correct
18 Correct 6 ms 1356 KB Output is correct
19 Correct 496 ms 46952 KB Output is correct
20 Correct 478 ms 46952 KB Output is correct
21 Correct 375 ms 46808 KB Output is correct
22 Correct 382 ms 46936 KB Output is correct
23 Correct 371 ms 46840 KB Output is correct
24 Correct 305 ms 46868 KB Output is correct
25 Correct 290 ms 46704 KB Output is correct
26 Correct 414 ms 46872 KB Output is correct
27 Correct 401 ms 46896 KB Output is correct
28 Correct 400 ms 46944 KB Output is correct
29 Correct 402 ms 47116 KB Output is correct
30 Correct 397 ms 46948 KB Output is correct
31 Correct 395 ms 46956 KB Output is correct
32 Correct 391 ms 46968 KB Output is correct
33 Correct 417 ms 47092 KB Output is correct
34 Correct 276 ms 46708 KB Output is correct
35 Correct 278 ms 46620 KB Output is correct
36 Correct 311 ms 46392 KB Output is correct
37 Correct 269 ms 46444 KB Output is correct
38 Correct 284 ms 46664 KB Output is correct
39 Correct 376 ms 45556 KB Output is correct
40 Correct 228 ms 28580 KB Output is correct
41 Correct 368 ms 45176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 5 ms 1348 KB Output is correct
13 Correct 5 ms 1356 KB Output is correct
14 Correct 8 ms 1464 KB Output is correct
15 Correct 7 ms 1484 KB Output is correct
16 Correct 6 ms 1356 KB Output is correct
17 Correct 6 ms 1100 KB Output is correct
18 Correct 6 ms 1356 KB Output is correct
19 Execution timed out 3077 ms 196300 KB Time limit exceeded
20 Halted 0 ms 0 KB -