Submission #330792

# Submission time Handle Problem Language Result Execution time Memory
330792 2020-11-26T14:59:33 Z vitkishloh228 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
77 / 100
795 ms 262148 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("vpt")
vector<vector<int>> t;
vector<int> mx, ans, a;
void build(int v, int l, int r) {
    if (l == r) {
        t[v] = { a[l] };
        mx[v] = a[l];
        ans[v] = 0;
        return;
    }
    int m = (l + r) >> 1;
    build(2 * v, l, m);
    build(2 * v + 1, m + 1, r);
    t[v].resize(t[2 * v].size() + t[2 * v + 1].size());
    merge(t[2 * v].begin(), t[2 * v].end(), t[2 * v + 1].begin(), t[2 * v + 1].end(), t[v].begin());
    ans[v] = max(ans[2 * v], ans[2 * v + 1]);
    mx[v] = max(mx[2 * v], mx[2 * v + 1]);
    int pos1 = lower_bound(t[2 * v + 1].begin(), t[2 * v + 1].end(), mx[2 * v]) - t[2 * v + 1].begin();
    pos1--;
    if (pos1 >= 0) {
        ans[v] = max(ans[v], mx[2 * v] + t[2 * v + 1][pos1]);
    }
}
void get(int v, int tl, int tr, int l, int r, vector<int>& vert) {
    if (tl > tr || l > r) return;
    if (tl == l && tr == r) {
        vert.push_back(v);
        return;
    }
    int tm = (tl + tr) >> 1;
    get(2 * v, tl, tm, l, min(r, tm), vert);
    get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, vert);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    t.resize(4 * n);
    a.resize(n);
    mx.resize(4 * n);
    ans.resize(4 * n);
    int min1 = 1e9;
    for (int& i : a) {
        cin >> i;
        min1 = min(min1, i);
    }
    int max1 = 0;
    vector<vector<int>> queri(q);
    for (int i = 0; i < q; ++i) {
        int l, r, c;
        cin >> l >> r >> c;
        queri[i] = { l - 1,r - 1,c };
        max1 = max(max1, c);
    }
    if (max1 < min1) {
        vector<int> pr(n + 1);
        for (int i = 0; i < n; ++i) {
            if (i != 0 && a[i] >= a[i - 1]) {
                pr[i + 1] = 1 + pr[i];
            }
            else {
                pr[i + 1] = pr[i];
            }
        }
        for (int j = 0; j < q; ++j) {
            int l, r, c;
            l = queri[j][0];
            r = queri[j][1];
            c = queri[j][2];
            if (c < min1) {
                if (pr[r + 1] - pr[l + 1] == r - l) {
                    cout << "1\n";
                }
                else {
                    cout << "0\n";
                }
                continue;
            }
         
        }
        return 0;
    }
    build(1, 0, n - 1);
    for (int j = 0; j < q; ++j) {
        int l, r, c;
        l = queri[j][0];
        r = queri[j][1];
        c = queri[j][2];
        vector<int> vert;
        get(1, 0, n - 1, l, r, vert);
        int x = 0;
        for (auto v : vert) {
            x = max(x, ans[v]);
        }
        int curmax = t[vert[0]].back();
        for (int i = 1; i < vert.size(); ++i) {
            int v = vert[i];
            int pos1 = lower_bound(t[v].begin(), t[v].end(), curmax) - t[v].begin();
            pos1--;
            if (pos1 >= 0) {
                x = max(x, curmax + t[v][pos1]);
            }
            curmax = max(curmax, t[v].back());
        }
        if (x <= c) {
            cout << "1\n";
        }
        else cout << "0\n";
    }
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:106:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         for (int i = 1; i < vert.size(); ++i) {
      |                         ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 5 ms 876 KB Output is correct
12 Correct 6 ms 1516 KB Output is correct
13 Correct 7 ms 1644 KB Output is correct
14 Correct 10 ms 1772 KB Output is correct
15 Correct 9 ms 1792 KB Output is correct
16 Correct 8 ms 1772 KB Output is correct
17 Correct 6 ms 1644 KB Output is correct
18 Correct 7 ms 1772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 720 ms 190436 KB Output is correct
2 Correct 764 ms 190476 KB Output is correct
3 Correct 728 ms 190604 KB Output is correct
4 Correct 716 ms 190316 KB Output is correct
5 Correct 707 ms 190316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 281 ms 30812 KB Output is correct
2 Correct 288 ms 30700 KB Output is correct
3 Correct 277 ms 30700 KB Output is correct
4 Correct 280 ms 30688 KB Output is correct
5 Correct 279 ms 30700 KB Output is correct
6 Correct 222 ms 30700 KB Output is correct
7 Correct 273 ms 30700 KB Output is correct
8 Correct 213 ms 30700 KB Output is correct
9 Correct 65 ms 6508 KB Output is correct
10 Correct 213 ms 30700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 5 ms 876 KB Output is correct
12 Correct 6 ms 1516 KB Output is correct
13 Correct 7 ms 1644 KB Output is correct
14 Correct 10 ms 1772 KB Output is correct
15 Correct 9 ms 1792 KB Output is correct
16 Correct 8 ms 1772 KB Output is correct
17 Correct 6 ms 1644 KB Output is correct
18 Correct 7 ms 1772 KB Output is correct
19 Correct 653 ms 61548 KB Output is correct
20 Correct 643 ms 61804 KB Output is correct
21 Correct 560 ms 61548 KB Output is correct
22 Correct 563 ms 61548 KB Output is correct
23 Correct 559 ms 61548 KB Output is correct
24 Correct 534 ms 61680 KB Output is correct
25 Correct 524 ms 61548 KB Output is correct
26 Correct 646 ms 61604 KB Output is correct
27 Correct 651 ms 61660 KB Output is correct
28 Correct 680 ms 61804 KB Output is correct
29 Correct 691 ms 61840 KB Output is correct
30 Correct 673 ms 61700 KB Output is correct
31 Correct 694 ms 61556 KB Output is correct
32 Correct 696 ms 61572 KB Output is correct
33 Correct 692 ms 61548 KB Output is correct
34 Correct 501 ms 61548 KB Output is correct
35 Correct 504 ms 61804 KB Output is correct
36 Correct 501 ms 61932 KB Output is correct
37 Correct 497 ms 61696 KB Output is correct
38 Correct 515 ms 61548 KB Output is correct
39 Correct 574 ms 61572 KB Output is correct
40 Correct 370 ms 44396 KB Output is correct
41 Correct 491 ms 61548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 5 ms 876 KB Output is correct
12 Correct 6 ms 1516 KB Output is correct
13 Correct 7 ms 1644 KB Output is correct
14 Correct 10 ms 1772 KB Output is correct
15 Correct 9 ms 1792 KB Output is correct
16 Correct 8 ms 1772 KB Output is correct
17 Correct 6 ms 1644 KB Output is correct
18 Correct 7 ms 1772 KB Output is correct
19 Correct 720 ms 190436 KB Output is correct
20 Correct 764 ms 190476 KB Output is correct
21 Correct 728 ms 190604 KB Output is correct
22 Correct 716 ms 190316 KB Output is correct
23 Correct 707 ms 190316 KB Output is correct
24 Correct 281 ms 30812 KB Output is correct
25 Correct 288 ms 30700 KB Output is correct
26 Correct 277 ms 30700 KB Output is correct
27 Correct 280 ms 30688 KB Output is correct
28 Correct 279 ms 30700 KB Output is correct
29 Correct 222 ms 30700 KB Output is correct
30 Correct 273 ms 30700 KB Output is correct
31 Correct 213 ms 30700 KB Output is correct
32 Correct 65 ms 6508 KB Output is correct
33 Correct 213 ms 30700 KB Output is correct
34 Correct 653 ms 61548 KB Output is correct
35 Correct 643 ms 61804 KB Output is correct
36 Correct 560 ms 61548 KB Output is correct
37 Correct 563 ms 61548 KB Output is correct
38 Correct 559 ms 61548 KB Output is correct
39 Correct 534 ms 61680 KB Output is correct
40 Correct 524 ms 61548 KB Output is correct
41 Correct 646 ms 61604 KB Output is correct
42 Correct 651 ms 61660 KB Output is correct
43 Correct 680 ms 61804 KB Output is correct
44 Correct 691 ms 61840 KB Output is correct
45 Correct 673 ms 61700 KB Output is correct
46 Correct 694 ms 61556 KB Output is correct
47 Correct 696 ms 61572 KB Output is correct
48 Correct 692 ms 61548 KB Output is correct
49 Correct 501 ms 61548 KB Output is correct
50 Correct 504 ms 61804 KB Output is correct
51 Correct 501 ms 61932 KB Output is correct
52 Correct 497 ms 61696 KB Output is correct
53 Correct 515 ms 61548 KB Output is correct
54 Correct 574 ms 61572 KB Output is correct
55 Correct 370 ms 44396 KB Output is correct
56 Correct 491 ms 61548 KB Output is correct
57 Runtime error 795 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
58 Halted 0 ms 0 KB -