답안 #519538

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519538 2022-01-26T15:07:04 Z Dasha_Gnedko Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
2411 ms 104556 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);
            t.upd(b.back().F.F, b.back().F.F, 1, 0, t.pr - 1, b.back().S);
            b.pop_back();
        }

        if (!sz(b))
        {
            b.pb({{i, n - 1}, a[i]});
            t.upd(i, i, 1, 0, t.pr - 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]);
            t.upd(i, i, 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(i, to.F.F, 1, 0, t.pr - 1) <= to.F.S);
    }
    for(int i = 0; i < q; i++)
        cout << ans[i] << endl;
}

Compilation message

sortbooks.cpp: In function 'int32_t main()':
sortbooks.cpp:116:9: warning: variable 'ls' set but not used [-Wunused-but-set-variable]
  116 |     int ls = n - 1;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 13 ms 23816 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 12 ms 23756 KB Output is correct
5 Correct 13 ms 23716 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 17 ms 23884 KB Output is correct
8 Correct 13 ms 23852 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 13 ms 23852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 13 ms 23816 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 12 ms 23756 KB Output is correct
5 Correct 13 ms 23716 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 17 ms 23884 KB Output is correct
8 Correct 13 ms 23852 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 13 ms 23852 KB Output is correct
11 Correct 16 ms 24012 KB Output is correct
12 Correct 21 ms 24124 KB Output is correct
13 Correct 18 ms 24088 KB Output is correct
14 Correct 20 ms 24240 KB Output is correct
15 Correct 21 ms 24216 KB Output is correct
16 Correct 18 ms 24268 KB Output is correct
17 Correct 17 ms 24184 KB Output is correct
18 Correct 18 ms 24236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2294 ms 71920 KB Output is correct
2 Correct 2278 ms 71820 KB Output is correct
3 Correct 2239 ms 71800 KB Output is correct
4 Correct 2331 ms 71820 KB Output is correct
5 Correct 1712 ms 83660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 195 ms 29288 KB Output is correct
2 Correct 173 ms 30788 KB Output is correct
3 Correct 125 ms 32296 KB Output is correct
4 Correct 128 ms 32532 KB Output is correct
5 Correct 174 ms 32528 KB Output is correct
6 Correct 110 ms 31616 KB Output is correct
7 Correct 132 ms 31508 KB Output is correct
8 Correct 129 ms 31288 KB Output is correct
9 Correct 47 ms 27328 KB Output is correct
10 Correct 121 ms 31300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 13 ms 23816 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 12 ms 23756 KB Output is correct
5 Correct 13 ms 23716 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 17 ms 23884 KB Output is correct
8 Correct 13 ms 23852 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 13 ms 23852 KB Output is correct
11 Correct 16 ms 24012 KB Output is correct
12 Correct 21 ms 24124 KB Output is correct
13 Correct 18 ms 24088 KB Output is correct
14 Correct 20 ms 24240 KB Output is correct
15 Correct 21 ms 24216 KB Output is correct
16 Correct 18 ms 24268 KB Output is correct
17 Correct 17 ms 24184 KB Output is correct
18 Correct 18 ms 24236 KB Output is correct
19 Correct 415 ms 40964 KB Output is correct
20 Correct 399 ms 40896 KB Output is correct
21 Correct 361 ms 40448 KB Output is correct
22 Correct 383 ms 40296 KB Output is correct
23 Correct 356 ms 40344 KB Output is correct
24 Correct 257 ms 42564 KB Output is correct
25 Correct 261 ms 42648 KB Output is correct
26 Correct 270 ms 43312 KB Output is correct
27 Correct 282 ms 43200 KB Output is correct
28 Correct 264 ms 43304 KB Output is correct
29 Correct 279 ms 43676 KB Output is correct
30 Correct 292 ms 43740 KB Output is correct
31 Correct 296 ms 43732 KB Output is correct
32 Correct 317 ms 43892 KB Output is correct
33 Correct 286 ms 43748 KB Output is correct
34 Correct 248 ms 41864 KB Output is correct
35 Correct 270 ms 42048 KB Output is correct
36 Correct 227 ms 41656 KB Output is correct
37 Correct 236 ms 41592 KB Output is correct
38 Correct 229 ms 40928 KB Output is correct
39 Correct 308 ms 40716 KB Output is correct
40 Correct 191 ms 37224 KB Output is correct
41 Correct 275 ms 39808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 13 ms 23816 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 12 ms 23756 KB Output is correct
5 Correct 13 ms 23716 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 17 ms 23884 KB Output is correct
8 Correct 13 ms 23852 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 13 ms 23852 KB Output is correct
11 Correct 16 ms 24012 KB Output is correct
12 Correct 21 ms 24124 KB Output is correct
13 Correct 18 ms 24088 KB Output is correct
14 Correct 20 ms 24240 KB Output is correct
15 Correct 21 ms 24216 KB Output is correct
16 Correct 18 ms 24268 KB Output is correct
17 Correct 17 ms 24184 KB Output is correct
18 Correct 18 ms 24236 KB Output is correct
19 Correct 2294 ms 71920 KB Output is correct
20 Correct 2278 ms 71820 KB Output is correct
21 Correct 2239 ms 71800 KB Output is correct
22 Correct 2331 ms 71820 KB Output is correct
23 Correct 1712 ms 83660 KB Output is correct
24 Correct 195 ms 29288 KB Output is correct
25 Correct 173 ms 30788 KB Output is correct
26 Correct 125 ms 32296 KB Output is correct
27 Correct 128 ms 32532 KB Output is correct
28 Correct 174 ms 32528 KB Output is correct
29 Correct 110 ms 31616 KB Output is correct
30 Correct 132 ms 31508 KB Output is correct
31 Correct 129 ms 31288 KB Output is correct
32 Correct 47 ms 27328 KB Output is correct
33 Correct 121 ms 31300 KB Output is correct
34 Correct 415 ms 40964 KB Output is correct
35 Correct 399 ms 40896 KB Output is correct
36 Correct 361 ms 40448 KB Output is correct
37 Correct 383 ms 40296 KB Output is correct
38 Correct 356 ms 40344 KB Output is correct
39 Correct 257 ms 42564 KB Output is correct
40 Correct 261 ms 42648 KB Output is correct
41 Correct 270 ms 43312 KB Output is correct
42 Correct 282 ms 43200 KB Output is correct
43 Correct 264 ms 43304 KB Output is correct
44 Correct 279 ms 43676 KB Output is correct
45 Correct 292 ms 43740 KB Output is correct
46 Correct 296 ms 43732 KB Output is correct
47 Correct 317 ms 43892 KB Output is correct
48 Correct 286 ms 43748 KB Output is correct
49 Correct 248 ms 41864 KB Output is correct
50 Correct 270 ms 42048 KB Output is correct
51 Correct 227 ms 41656 KB Output is correct
52 Correct 236 ms 41592 KB Output is correct
53 Correct 229 ms 40928 KB Output is correct
54 Correct 308 ms 40716 KB Output is correct
55 Correct 191 ms 37224 KB Output is correct
56 Correct 275 ms 39808 KB Output is correct
57 Correct 2411 ms 89840 KB Output is correct
58 Correct 2366 ms 88872 KB Output is correct
59 Correct 2189 ms 86804 KB Output is correct
60 Correct 2201 ms 87132 KB Output is correct
61 Correct 2292 ms 87300 KB Output is correct
62 Correct 2178 ms 87836 KB Output is correct
63 Correct 1222 ms 93332 KB Output is correct
64 Correct 1232 ms 93632 KB Output is correct
65 Correct 1549 ms 100652 KB Output is correct
66 Correct 1610 ms 100884 KB Output is correct
67 Correct 1609 ms 101640 KB Output is correct
68 Correct 1699 ms 103508 KB Output is correct
69 Correct 1678 ms 104076 KB Output is correct
70 Correct 1669 ms 103944 KB Output is correct
71 Correct 1661 ms 104356 KB Output is correct
72 Correct 1664 ms 104556 KB Output is correct
73 Correct 1145 ms 78388 KB Output is correct
74 Correct 1158 ms 78484 KB Output is correct
75 Correct 1144 ms 78376 KB Output is correct
76 Correct 1161 ms 78392 KB Output is correct
77 Correct 1159 ms 78696 KB Output is correct
78 Correct 1596 ms 79696 KB Output is correct
79 Correct 963 ms 64416 KB Output is correct
80 Correct 1519 ms 76212 KB Output is correct