답안 #1097273

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097273 2024-10-06T15:55:11 Z anhthi Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1376 ms 133972 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define ll long long
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define pb push_back
#define max_rng *max_element
#define min_rng *min_element
#define rep(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define forn(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
 
template <class X, class Y>
    inline bool maximize(X &x, Y y) {
        return (x < y ? x = y, true : false);
    }
 
template <class X, class Y>
    inline bool minimize(X &x, Y y) {
        return (x > y ? x = y, true : false);
    }
 
template <class X>
    inline void compress(vector<X> &a) {
        sort(all(a));
        a.resize(unique(all(a)) - a.begin());
    }
 
int ctz(ll x) { return __builtin_ctzll(x); }
int lg(ll x) { return 63 - __builtin_clzll(x); }
int popcount(ll x) { return __builtin_popcount(x); }
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) {
    return l + abs((ll) rng()) % (r - l + 1);
}
 
const ll oo = (ll) 1e17;
const int inf = (ll) 1e9 + 7, mod = (ll) 1e9 + 7;
 
const int N = 1e6 + 5, M = 2e5 + 5, BASE = 307, LOG = 23;
 
void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
void sub(int &x, int y) { x -= y; if (x < 0) x += mod; }

int n, m;
int a[N];

struct Seg {
 
    int n;
    vector<int> st, lz;
 
    Seg(int n) : n(n) {
        st.resize(n << 2);
        lz.resize(n << 2);
    }
 
    void setNode(int i, int x) {
        st[i] += x;
        lz[i] += x;
    }
    void down(int i) {
        if (!lz[i]) return;
        setNode(2 * i, lz[i]);
        setNode(2 * i + 1, lz[i]);
        lz[i] = 0;
        return;
    }
 
    void upd(int i, int l, int r, int u, int v, int x) {
        if (l > v || r < u) return;
        if (l >= u && r <= v) return setNode(i, x);
        down(i);
        int m = (l + r) >> 1;
        upd(2 * i, l, m, u, v, x);
        upd(2 * i + 1, m + 1, r, u, v, x);
        st[i] = max(st[2 * i], st[2 * i + 1]);
    }
 
    void upd(int u, int v, int x) {
        if (u > v) return;
        return upd(1, 1, n, u, v, x);
    }
 
    int get(int i, int l, int r, int u, int v) {
        if (l > v || r < u) return -inf;
        if (l >= u && r <= v) return st[i];
        down(i);
        int m = (l + r) >> 1;
        return max(get(2 * i, l, m, u, v), get(2 * i + 1, m + 1, r, u, v));
    }

    int get(int u, int v) {
        return get(1, 1, n, u, v);
    }
};
bool res[N];
vector<array<ll, 3>> queries[N];

int main(void) {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    cin >> n >> m;
    rep(i, n) cin >> a[i];
    rep(i, m) {
        int l, r, k;
        cin >> l >> r >> k;
        queries[l].pb({r, k, i});
    }

    Seg s(n);
    stack<int> st;
    ford(i, n, 1) {
        while (sz(st) && a[st.top()] < a[i]) {
            int cur = st.top();
            st.pop();
            int lst = n;
            if (sz(st)) lst = st.top() - 1;

            s.upd(cur, cur, a[cur]);
            s.upd(cur + 1, lst, -a[cur]);
        }
        int cur = n;
        if (sz(st)) cur = st.top() - 1;
        st.push(i);
        s.upd(i + 1, cur, a[i]);

        for (array<ll, 3> q : queries[i]) {
            res[q[2]] = s.get(i, q[0]) <= q[1];
        }
    }

    rep(i, m) cout << res[i] << '\n';
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 12 ms 23892 KB Output is correct
3 Correct 10 ms 23872 KB Output is correct
4 Correct 10 ms 24152 KB Output is correct
5 Correct 10 ms 23896 KB Output is correct
6 Correct 10 ms 23960 KB Output is correct
7 Correct 10 ms 23792 KB Output is correct
8 Correct 10 ms 23900 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 10 ms 23956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 12 ms 23892 KB Output is correct
3 Correct 10 ms 23872 KB Output is correct
4 Correct 10 ms 24152 KB Output is correct
5 Correct 10 ms 23896 KB Output is correct
6 Correct 10 ms 23960 KB Output is correct
7 Correct 10 ms 23792 KB Output is correct
8 Correct 10 ms 23900 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 10 ms 23956 KB Output is correct
11 Correct 11 ms 24152 KB Output is correct
12 Correct 12 ms 24312 KB Output is correct
13 Correct 13 ms 24156 KB Output is correct
14 Correct 13 ms 24228 KB Output is correct
15 Correct 14 ms 24412 KB Output is correct
16 Correct 12 ms 24408 KB Output is correct
17 Correct 12 ms 24156 KB Output is correct
18 Correct 13 ms 24156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1250 ms 126288 KB Output is correct
2 Correct 1298 ms 127276 KB Output is correct
3 Correct 1317 ms 127144 KB Output is correct
4 Correct 1209 ms 127424 KB Output is correct
5 Correct 826 ms 131408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 32848 KB Output is correct
2 Correct 93 ms 33412 KB Output is correct
3 Correct 74 ms 33348 KB Output is correct
4 Correct 64 ms 33360 KB Output is correct
5 Correct 63 ms 33364 KB Output is correct
6 Correct 53 ms 33108 KB Output is correct
7 Correct 51 ms 32848 KB Output is correct
8 Correct 65 ms 32344 KB Output is correct
9 Correct 33 ms 28428 KB Output is correct
10 Correct 68 ms 32464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 12 ms 23892 KB Output is correct
3 Correct 10 ms 23872 KB Output is correct
4 Correct 10 ms 24152 KB Output is correct
5 Correct 10 ms 23896 KB Output is correct
6 Correct 10 ms 23960 KB Output is correct
7 Correct 10 ms 23792 KB Output is correct
8 Correct 10 ms 23900 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 10 ms 23956 KB Output is correct
11 Correct 11 ms 24152 KB Output is correct
12 Correct 12 ms 24312 KB Output is correct
13 Correct 13 ms 24156 KB Output is correct
14 Correct 13 ms 24228 KB Output is correct
15 Correct 14 ms 24412 KB Output is correct
16 Correct 12 ms 24408 KB Output is correct
17 Correct 12 ms 24156 KB Output is correct
18 Correct 13 ms 24156 KB Output is correct
19 Correct 220 ms 44628 KB Output is correct
20 Correct 237 ms 44416 KB Output is correct
21 Correct 187 ms 45520 KB Output is correct
22 Correct 192 ms 45520 KB Output is correct
23 Correct 182 ms 45372 KB Output is correct
24 Correct 110 ms 46160 KB Output is correct
25 Correct 108 ms 46164 KB Output is correct
26 Correct 123 ms 46060 KB Output is correct
27 Correct 123 ms 45908 KB Output is correct
28 Correct 125 ms 45648 KB Output is correct
29 Correct 144 ms 45364 KB Output is correct
30 Correct 132 ms 45396 KB Output is correct
31 Correct 131 ms 45360 KB Output is correct
32 Correct 134 ms 45460 KB Output is correct
33 Correct 146 ms 45392 KB Output is correct
34 Correct 114 ms 44600 KB Output is correct
35 Correct 111 ms 44536 KB Output is correct
36 Correct 107 ms 44372 KB Output is correct
37 Correct 108 ms 44372 KB Output is correct
38 Correct 109 ms 44608 KB Output is correct
39 Correct 145 ms 43272 KB Output is correct
40 Correct 100 ms 39420 KB Output is correct
41 Correct 145 ms 42448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 12 ms 23892 KB Output is correct
3 Correct 10 ms 23872 KB Output is correct
4 Correct 10 ms 24152 KB Output is correct
5 Correct 10 ms 23896 KB Output is correct
6 Correct 10 ms 23960 KB Output is correct
7 Correct 10 ms 23792 KB Output is correct
8 Correct 10 ms 23900 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 10 ms 23956 KB Output is correct
11 Correct 11 ms 24152 KB Output is correct
12 Correct 12 ms 24312 KB Output is correct
13 Correct 13 ms 24156 KB Output is correct
14 Correct 13 ms 24228 KB Output is correct
15 Correct 14 ms 24412 KB Output is correct
16 Correct 12 ms 24408 KB Output is correct
17 Correct 12 ms 24156 KB Output is correct
18 Correct 13 ms 24156 KB Output is correct
19 Correct 1250 ms 126288 KB Output is correct
20 Correct 1298 ms 127276 KB Output is correct
21 Correct 1317 ms 127144 KB Output is correct
22 Correct 1209 ms 127424 KB Output is correct
23 Correct 826 ms 131408 KB Output is correct
24 Correct 95 ms 32848 KB Output is correct
25 Correct 93 ms 33412 KB Output is correct
26 Correct 74 ms 33348 KB Output is correct
27 Correct 64 ms 33360 KB Output is correct
28 Correct 63 ms 33364 KB Output is correct
29 Correct 53 ms 33108 KB Output is correct
30 Correct 51 ms 32848 KB Output is correct
31 Correct 65 ms 32344 KB Output is correct
32 Correct 33 ms 28428 KB Output is correct
33 Correct 68 ms 32464 KB Output is correct
34 Correct 220 ms 44628 KB Output is correct
35 Correct 237 ms 44416 KB Output is correct
36 Correct 187 ms 45520 KB Output is correct
37 Correct 192 ms 45520 KB Output is correct
38 Correct 182 ms 45372 KB Output is correct
39 Correct 110 ms 46160 KB Output is correct
40 Correct 108 ms 46164 KB Output is correct
41 Correct 123 ms 46060 KB Output is correct
42 Correct 123 ms 45908 KB Output is correct
43 Correct 125 ms 45648 KB Output is correct
44 Correct 144 ms 45364 KB Output is correct
45 Correct 132 ms 45396 KB Output is correct
46 Correct 131 ms 45360 KB Output is correct
47 Correct 134 ms 45460 KB Output is correct
48 Correct 146 ms 45392 KB Output is correct
49 Correct 114 ms 44600 KB Output is correct
50 Correct 111 ms 44536 KB Output is correct
51 Correct 107 ms 44372 KB Output is correct
52 Correct 108 ms 44372 KB Output is correct
53 Correct 109 ms 44608 KB Output is correct
54 Correct 145 ms 43272 KB Output is correct
55 Correct 100 ms 39420 KB Output is correct
56 Correct 145 ms 42448 KB Output is correct
57 Correct 1376 ms 127636 KB Output is correct
58 Correct 1300 ms 127632 KB Output is correct
59 Correct 1150 ms 129488 KB Output is correct
60 Correct 1192 ms 129360 KB Output is correct
61 Correct 1263 ms 129340 KB Output is correct
62 Correct 1185 ms 129336 KB Output is correct
63 Correct 526 ms 128668 KB Output is correct
64 Correct 579 ms 128596 KB Output is correct
65 Correct 755 ms 133972 KB Output is correct
66 Correct 787 ms 133784 KB Output is correct
67 Correct 770 ms 133712 KB Output is correct
68 Correct 874 ms 131920 KB Output is correct
69 Correct 836 ms 131836 KB Output is correct
70 Correct 859 ms 131976 KB Output is correct
71 Correct 870 ms 131884 KB Output is correct
72 Correct 931 ms 131988 KB Output is correct
73 Correct 533 ms 123288 KB Output is correct
74 Correct 543 ms 124168 KB Output is correct
75 Correct 462 ms 123112 KB Output is correct
76 Correct 478 ms 122960 KB Output is correct
77 Correct 483 ms 123108 KB Output is correct
78 Correct 771 ms 123152 KB Output is correct
79 Correct 508 ms 97460 KB Output is correct
80 Correct 833 ms 118264 KB Output is correct