답안 #1040445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1040445 2024-08-01T04:21:50 Z Yang8on Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
816 ms 161108 KB
#include <bits/stdc++.h>
#define Y8o "Hedgehog Daniyar and Algorithms"
#define maxn (int) 1e6 + 5
#define ll long long
#define pii pair<ll, ll>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r

//#define f first
//#define s second

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
    if(fopen(Y8o".inp", "r"))
    {
        freopen(Y8o".inp", "r", stdin);
//        freopen(Y8o".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}
void ctime() {
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}


int n, Q, a[maxn], ans[maxn];
int L[maxn][20], Log[maxn], pre[maxn];
vector<int> cur[maxn];
struct dl { int l, r, k, id; } qr[maxn];

int get(int i, int j) {
    int kc = Log[j - i + 1];
    return max( L[i][kc], L[j - (1 << kc) + 1][kc] );
}

int st[4 * maxn];
struct SEGMENTREE {
    void build(int id = 1, int l = 1, int r = n) {
        if(l == r) {
            if(pre[l] != 0) st[id] = a[pre[l]] + a[l];
            return ;
        }
        int mid = (l + r) >> 1;
        build(_left), build(_right);
        st[id] = max(st[id * 2], st[id * 2 + 1]);
    }
    void update(int i, int id = 1, int l = 1, int r = n) {
        if(i < l || r < i) return ;
        if(l == r) return st[id] = 0, void();
        int mid = (l + r) >> 1;
        update(i, _left), update(i, _right);
        st[id] = max(st[id * 2], st[id * 2 + 1]);
    }
    int get(int u, int v, int id = 1, int l = 1, int r = n) {
        if(v < l || r < u) return 0;
        if(u <= l && r <= v) return st[id];
        int mid = (l + r) >> 1;
        return max( get(u, v, _left), get(u, v, _right) );
    }
} ST;

void solve()
{
    cin >> n >> Q;
    for(int i = 1; i <= n; i ++) cin >> a[i], L[i][0] = a[i], Log[i] = __lg(i);

    for(int i = 1; i <= Log[n]; i ++) {
        for(int j = 1; j + (1 << i) - 1 <= n; j ++) {
            L[j][i] = max(L[j][i - 1], L[j + (1 << (i - 1))][i - 1]);
        }
    }

    for(int i = 1; i <= n; i ++) {
        int l = 1, r = i;
        while(l <= r) {
            int mid = (l + r) >> 1;
            if(get(mid, i) > a[i]) l = mid + 1;
            else r = mid - 1;
        }
        pre[i] = r;
        cur[r].push_back(i);
    }

    ST.build();

    for(int i =1 ; i <= Q; i ++) {
        int l, r, k; cin >> l >> r >> k;
        qr[i] = {l, r, k, i};
    }

    sort(qr + 1, qr + Q + 1, [](dl x, dl y) {
        return x.l < y.l;
    });

    int j = 1;
    for(int i = 1; i <= Q; i ++) {
        int l = qr[i].l, r = qr[i].r, k = qr[i].k, id = qr[i].id;
        while(j < l) {
            for(int pos : cur[j]) ST.update(pos);
            j ++;
        }
        ans[id] = ST.get(l, r) <= k;
    }

    for(int i = 1; i <= Q; i ++) cout << ans[i] << '\n';
}


int main()
{
    iof();

    int nTest = 1;
//    cin >> nTest;

    while(nTest --) {
        solve();
    }

    ctime();
    return 0;
}

Compilation message

sortbooks.cpp: In function 'void iof()':
sortbooks.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 35416 KB Output is correct
2 Correct 4 ms 35164 KB Output is correct
3 Correct 5 ms 35164 KB Output is correct
4 Correct 4 ms 35164 KB Output is correct
5 Correct 4 ms 35164 KB Output is correct
6 Correct 5 ms 35160 KB Output is correct
7 Correct 5 ms 35164 KB Output is correct
8 Correct 5 ms 35268 KB Output is correct
9 Correct 5 ms 35160 KB Output is correct
10 Correct 5 ms 35164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 35416 KB Output is correct
2 Correct 4 ms 35164 KB Output is correct
3 Correct 5 ms 35164 KB Output is correct
4 Correct 4 ms 35164 KB Output is correct
5 Correct 4 ms 35164 KB Output is correct
6 Correct 5 ms 35160 KB Output is correct
7 Correct 5 ms 35164 KB Output is correct
8 Correct 5 ms 35268 KB Output is correct
9 Correct 5 ms 35160 KB Output is correct
10 Correct 5 ms 35164 KB Output is correct
11 Correct 5 ms 35164 KB Output is correct
12 Correct 6 ms 35420 KB Output is correct
13 Correct 6 ms 35420 KB Output is correct
14 Correct 7 ms 35292 KB Output is correct
15 Correct 7 ms 35420 KB Output is correct
16 Correct 6 ms 35464 KB Output is correct
17 Correct 6 ms 35420 KB Output is correct
18 Correct 6 ms 35420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 792 ms 159776 KB Output is correct
2 Correct 755 ms 161108 KB Output is correct
3 Correct 726 ms 159824 KB Output is correct
4 Correct 816 ms 159828 KB Output is correct
5 Correct 578 ms 144836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 49440 KB Output is correct
2 Correct 55 ms 49440 KB Output is correct
3 Correct 47 ms 46804 KB Output is correct
4 Correct 49 ms 46804 KB Output is correct
5 Correct 48 ms 46644 KB Output is correct
6 Correct 43 ms 46800 KB Output is correct
7 Correct 42 ms 46700 KB Output is correct
8 Correct 70 ms 47056 KB Output is correct
9 Correct 39 ms 37460 KB Output is correct
10 Correct 49 ms 46920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 35416 KB Output is correct
2 Correct 4 ms 35164 KB Output is correct
3 Correct 5 ms 35164 KB Output is correct
4 Correct 4 ms 35164 KB Output is correct
5 Correct 4 ms 35164 KB Output is correct
6 Correct 5 ms 35160 KB Output is correct
7 Correct 5 ms 35164 KB Output is correct
8 Correct 5 ms 35268 KB Output is correct
9 Correct 5 ms 35160 KB Output is correct
10 Correct 5 ms 35164 KB Output is correct
11 Correct 5 ms 35164 KB Output is correct
12 Correct 6 ms 35420 KB Output is correct
13 Correct 6 ms 35420 KB Output is correct
14 Correct 7 ms 35292 KB Output is correct
15 Correct 7 ms 35420 KB Output is correct
16 Correct 6 ms 35464 KB Output is correct
17 Correct 6 ms 35420 KB Output is correct
18 Correct 6 ms 35420 KB Output is correct
19 Correct 133 ms 63436 KB Output is correct
20 Correct 128 ms 63568 KB Output is correct
21 Correct 122 ms 63520 KB Output is correct
22 Correct 115 ms 63524 KB Output is correct
23 Correct 115 ms 63440 KB Output is correct
24 Correct 108 ms 60060 KB Output is correct
25 Correct 98 ms 60108 KB Output is correct
26 Correct 108 ms 60100 KB Output is correct
27 Correct 117 ms 60060 KB Output is correct
28 Correct 110 ms 60056 KB Output is correct
29 Correct 109 ms 60128 KB Output is correct
30 Correct 112 ms 60076 KB Output is correct
31 Correct 112 ms 60068 KB Output is correct
32 Correct 111 ms 60112 KB Output is correct
33 Correct 111 ms 60072 KB Output is correct
34 Correct 101 ms 60128 KB Output is correct
35 Correct 99 ms 60048 KB Output is correct
36 Correct 92 ms 60124 KB Output is correct
37 Correct 94 ms 60080 KB Output is correct
38 Correct 95 ms 60104 KB Output is correct
39 Correct 101 ms 61328 KB Output is correct
40 Correct 76 ms 51236 KB Output is correct
41 Correct 102 ms 60820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 35416 KB Output is correct
2 Correct 4 ms 35164 KB Output is correct
3 Correct 5 ms 35164 KB Output is correct
4 Correct 4 ms 35164 KB Output is correct
5 Correct 4 ms 35164 KB Output is correct
6 Correct 5 ms 35160 KB Output is correct
7 Correct 5 ms 35164 KB Output is correct
8 Correct 5 ms 35268 KB Output is correct
9 Correct 5 ms 35160 KB Output is correct
10 Correct 5 ms 35164 KB Output is correct
11 Correct 5 ms 35164 KB Output is correct
12 Correct 6 ms 35420 KB Output is correct
13 Correct 6 ms 35420 KB Output is correct
14 Correct 7 ms 35292 KB Output is correct
15 Correct 7 ms 35420 KB Output is correct
16 Correct 6 ms 35464 KB Output is correct
17 Correct 6 ms 35420 KB Output is correct
18 Correct 6 ms 35420 KB Output is correct
19 Correct 792 ms 159776 KB Output is correct
20 Correct 755 ms 161108 KB Output is correct
21 Correct 726 ms 159824 KB Output is correct
22 Correct 816 ms 159828 KB Output is correct
23 Correct 578 ms 144836 KB Output is correct
24 Correct 59 ms 49440 KB Output is correct
25 Correct 55 ms 49440 KB Output is correct
26 Correct 47 ms 46804 KB Output is correct
27 Correct 49 ms 46804 KB Output is correct
28 Correct 48 ms 46644 KB Output is correct
29 Correct 43 ms 46800 KB Output is correct
30 Correct 42 ms 46700 KB Output is correct
31 Correct 70 ms 47056 KB Output is correct
32 Correct 39 ms 37460 KB Output is correct
33 Correct 49 ms 46920 KB Output is correct
34 Correct 133 ms 63436 KB Output is correct
35 Correct 128 ms 63568 KB Output is correct
36 Correct 122 ms 63520 KB Output is correct
37 Correct 115 ms 63524 KB Output is correct
38 Correct 115 ms 63440 KB Output is correct
39 Correct 108 ms 60060 KB Output is correct
40 Correct 98 ms 60108 KB Output is correct
41 Correct 108 ms 60100 KB Output is correct
42 Correct 117 ms 60060 KB Output is correct
43 Correct 110 ms 60056 KB Output is correct
44 Correct 109 ms 60128 KB Output is correct
45 Correct 112 ms 60076 KB Output is correct
46 Correct 112 ms 60068 KB Output is correct
47 Correct 111 ms 60112 KB Output is correct
48 Correct 111 ms 60072 KB Output is correct
49 Correct 101 ms 60128 KB Output is correct
50 Correct 99 ms 60048 KB Output is correct
51 Correct 92 ms 60124 KB Output is correct
52 Correct 94 ms 60080 KB Output is correct
53 Correct 95 ms 60104 KB Output is correct
54 Correct 101 ms 61328 KB Output is correct
55 Correct 76 ms 51236 KB Output is correct
56 Correct 102 ms 60820 KB Output is correct
57 Correct 745 ms 161008 KB Output is correct
58 Correct 723 ms 161080 KB Output is correct
59 Correct 691 ms 161048 KB Output is correct
60 Correct 679 ms 161108 KB Output is correct
61 Correct 664 ms 161100 KB Output is correct
62 Correct 697 ms 161032 KB Output is correct
63 Correct 537 ms 144588 KB Output is correct
64 Correct 542 ms 144800 KB Output is correct
65 Correct 564 ms 144612 KB Output is correct
66 Correct 598 ms 144588 KB Output is correct
67 Correct 565 ms 144676 KB Output is correct
68 Correct 592 ms 144576 KB Output is correct
69 Correct 589 ms 144600 KB Output is correct
70 Correct 555 ms 144836 KB Output is correct
71 Correct 571 ms 144684 KB Output is correct
72 Correct 586 ms 144860 KB Output is correct
73 Correct 484 ms 144832 KB Output is correct
74 Correct 484 ms 144832 KB Output is correct
75 Correct 472 ms 144684 KB Output is correct
76 Correct 490 ms 144808 KB Output is correct
77 Correct 479 ms 144832 KB Output is correct
78 Correct 529 ms 152268 KB Output is correct
79 Correct 362 ms 105892 KB Output is correct
80 Correct 527 ms 148752 KB Output is correct