답안 #237441

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
237441 2020-06-06T15:15:43 Z TeaTime Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
777 ms 262144 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <ctime>
#include <set>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define pb push_back
#define all(x) (x).begin(),(x).end()

const ll SIZE = 1e6 + 10, INF = 1e9 * 1e9, MOD = 1e9 + 7;

ll tree[SIZE * 4], bst[SIZE * 4];
vector<ll> mrg[SIZE * 4];
vector<ll> vec;

void build(int v, int l, int r) {
    if (l == r - 1) {
        tree[v] = vec[l];
        mrg[v].pb(vec[l]);
        bst[v] = 0;
    }
    else {
        int mid = (l + r) / 2;
        build(v * 2 + 1, l, mid);
        build(v * 2 + 2, mid, r);
        tree[v] = max(tree[v * 2 + 1], tree[v * 2 + 2]);
        merge(mrg[v * 2 + 1].begin(), mrg[v * 2 + 1].end(), mrg[v * 2 + 2].begin(), mrg[v * 2 + 2].end(), std::back_inserter(mrg[v]));
        bst[v] = max(bst[v * 2 + 1], bst[v * 2 + 2]);
        ll q = 0;
        if (lower_bound(mrg[v * 2 + 2].begin(), mrg[v * 2 + 2].end(), tree[v * 2 + 1]) != mrg[v * 2 + 2].begin()) {
            q = *(--lower_bound(mrg[v * 2 + 2].begin(), mrg[v * 2 + 2].end(), tree[v * 2 + 1])) + tree[v * 2 + 1];
        }
        bst[v] = max(bst[v], q);
    }
}

pair<ll, ll> ask(int v, int l, int r, int askl, int askr, ll curMx = -1) {
    if (l >= askr || r <= askl) return { 0, -1 };

    if (l >= askl && r <= askr) {
        ll q = 0;
        if (lower_bound(mrg[v].begin(), mrg[v].end(), curMx) != mrg[v].begin()) {
            q = *(--lower_bound(mrg[v].begin(), mrg[v].end(), curMx)) + curMx;
        }
        return { max(q, bst[v]), tree[v] };
    }

    int mid = (l + r) / 2;
    pair<ll, ll> q = ask(v * 2 + 1, l, mid, askl, askr, curMx), q2 = ask(v * 2 + 2, mid, r, askl, askr, max(curMx, q.second));
    pair<ll, ll> ans;
    ans.first = max(q.first, q2.first);
    ans.second = max(max(q.second, q2.second), curMx);
    return ans;
}

int main() {
    fastInp;

    ll n, m;
    cin >> n >> m;
    vec.resize(n);
    for (int i = 0; i < n; i++) cin >> vec[i];
    build(0, 0, n);

    while (m--) {
        ll l, r, k;
        cin >> l >> r >> k;
        if ((ask(0, 0, n, l - 1, r).first <= k)) {
            cout << "1\n";
        }
        else {
            cout << "0\n";
        }
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 94328 KB Output is correct
2 Correct 60 ms 94328 KB Output is correct
3 Correct 61 ms 94328 KB Output is correct
4 Correct 62 ms 94332 KB Output is correct
5 Correct 62 ms 94328 KB Output is correct
6 Correct 61 ms 94328 KB Output is correct
7 Correct 60 ms 94328 KB Output is correct
8 Correct 60 ms 94456 KB Output is correct
9 Correct 60 ms 94328 KB Output is correct
10 Correct 59 ms 94328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 94328 KB Output is correct
2 Correct 60 ms 94328 KB Output is correct
3 Correct 61 ms 94328 KB Output is correct
4 Correct 62 ms 94332 KB Output is correct
5 Correct 62 ms 94328 KB Output is correct
6 Correct 61 ms 94328 KB Output is correct
7 Correct 60 ms 94328 KB Output is correct
8 Correct 60 ms 94456 KB Output is correct
9 Correct 60 ms 94328 KB Output is correct
10 Correct 59 ms 94328 KB Output is correct
11 Correct 63 ms 94588 KB Output is correct
12 Correct 65 ms 95736 KB Output is correct
13 Correct 65 ms 95608 KB Output is correct
14 Correct 68 ms 95740 KB Output is correct
15 Correct 71 ms 95864 KB Output is correct
16 Correct 67 ms 95736 KB Output is correct
17 Correct 64 ms 95224 KB Output is correct
18 Correct 65 ms 95612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 504 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 352 ms 120432 KB Output is correct
2 Correct 321 ms 122348 KB Output is correct
3 Correct 271 ms 122348 KB Output is correct
4 Correct 290 ms 122480 KB Output is correct
5 Correct 272 ms 122348 KB Output is correct
6 Correct 214 ms 122220 KB Output is correct
7 Correct 220 ms 122348 KB Output is correct
8 Correct 264 ms 122072 KB Output is correct
9 Correct 100 ms 95868 KB Output is correct
10 Correct 259 ms 122204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 94328 KB Output is correct
2 Correct 60 ms 94328 KB Output is correct
3 Correct 61 ms 94328 KB Output is correct
4 Correct 62 ms 94332 KB Output is correct
5 Correct 62 ms 94328 KB Output is correct
6 Correct 61 ms 94328 KB Output is correct
7 Correct 60 ms 94328 KB Output is correct
8 Correct 60 ms 94456 KB Output is correct
9 Correct 60 ms 94328 KB Output is correct
10 Correct 59 ms 94328 KB Output is correct
11 Correct 63 ms 94588 KB Output is correct
12 Correct 65 ms 95736 KB Output is correct
13 Correct 65 ms 95608 KB Output is correct
14 Correct 68 ms 95740 KB Output is correct
15 Correct 71 ms 95864 KB Output is correct
16 Correct 67 ms 95736 KB Output is correct
17 Correct 64 ms 95224 KB Output is correct
18 Correct 65 ms 95612 KB Output is correct
19 Correct 777 ms 154728 KB Output is correct
20 Correct 758 ms 154700 KB Output is correct
21 Correct 636 ms 154448 KB Output is correct
22 Correct 638 ms 154472 KB Output is correct
23 Correct 666 ms 154644 KB Output is correct
24 Correct 447 ms 154344 KB Output is correct
25 Correct 449 ms 154344 KB Output is correct
26 Correct 556 ms 154600 KB Output is correct
27 Correct 555 ms 154600 KB Output is correct
28 Correct 583 ms 154740 KB Output is correct
29 Correct 600 ms 154728 KB Output is correct
30 Correct 596 ms 154692 KB Output is correct
31 Correct 599 ms 154752 KB Output is correct
32 Correct 577 ms 154600 KB Output is correct
33 Correct 584 ms 154600 KB Output is correct
34 Correct 402 ms 154304 KB Output is correct
35 Correct 403 ms 154216 KB Output is correct
36 Correct 418 ms 154224 KB Output is correct
37 Correct 418 ms 154088 KB Output is correct
38 Correct 422 ms 154216 KB Output is correct
39 Correct 540 ms 153168 KB Output is correct
40 Correct 361 ms 128492 KB Output is correct
41 Correct 516 ms 152808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 94328 KB Output is correct
2 Correct 60 ms 94328 KB Output is correct
3 Correct 61 ms 94328 KB Output is correct
4 Correct 62 ms 94332 KB Output is correct
5 Correct 62 ms 94328 KB Output is correct
6 Correct 61 ms 94328 KB Output is correct
7 Correct 60 ms 94328 KB Output is correct
8 Correct 60 ms 94456 KB Output is correct
9 Correct 60 ms 94328 KB Output is correct
10 Correct 59 ms 94328 KB Output is correct
11 Correct 63 ms 94588 KB Output is correct
12 Correct 65 ms 95736 KB Output is correct
13 Correct 65 ms 95608 KB Output is correct
14 Correct 68 ms 95740 KB Output is correct
15 Correct 71 ms 95864 KB Output is correct
16 Correct 67 ms 95736 KB Output is correct
17 Correct 64 ms 95224 KB Output is correct
18 Correct 65 ms 95612 KB Output is correct
19 Runtime error 504 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Halted 0 ms 0 KB -