Submission #172879

# Submission time Handle Problem Language Result Execution time Memory
172879 2020-01-02T17:31:35 Z limq Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
873 ms 60408 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree <pair <int, int>, null_type, less <pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define size(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define low_b lower_bound

#define endl "\n"
//#define int long long

using namespace std;

void dout() {
    cerr << endl;
}
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 1000003;
int n, m, a[N], l[N];
bool ans[N];

struct qu {
    int l, r, k, ind;
    qu(int l = 0, int r = 0, int k = 0, int ind = 0) {
        this -> l = l;
        this -> r = r;
        this -> k = k;
        this -> ind = ind;
    }
    bool operator < (const qu & q) const {
        return r < q.r;
    }
};

vector <qu> v;
set <pii> t;

void add(int x) {
    if (x == 0) {
        return;
    }
    int val = a[x] + a[l[x]];
    auto it = t.insert({l[x], val}).fi;
    if (next(it) != t.end() && (*next(it)).se > val) {
        t.erase(it);
        return;
    }
    while (it != t.begin() && (*prev(it)).se < val) {
        t.erase(prev(it));
    }
}

int getmax(int x) {
    if (t.empty()) {
        return 0;
    }
    auto it = t.lower_bound({x, 0});
    if (it == t.end()) {
        return 0;
    }
    return (*it).se;
}

void solve(int tc) {
    // check for (int i = 0; i < n; j++)
    cin >> n >> m;

    stack <int> st;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        while (!st.empty() && a[st.top()] <= a[i]) {
            st.pop();
        }
        if (!st.empty()) {
            l[i] = st.top();
        }
        st.push(i);
    }

    int tl, tr, tk;
    for (int i = 1; i <= m; i++) {
        cin >> tl >> tr >> tk;
        v.pb(qu(tl, tr, tk, i));
    }

    sort(all(v));
    int j = 1;
    for (int i = 0; i < m; i++) {
        while (j <= v[i].r) {
            add(j);
            j++;
        }
        if (getmax(v[i].l) > v[i].k) {
            ans[v[i].ind] = true;
        }
    }

    for (int i = 1; i <= m; i++) {
        if (ans[i]) {
            cout << "0\n";
        }   else {
            cout << "1\n";
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int tc = 1;
//    cin >> tc;
    for (int i = 0; i < tc; i++) {
        solve(i);
//        cleanup();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 5 ms 636 KB Output is correct
14 Correct 6 ms 760 KB Output is correct
15 Correct 6 ms 760 KB Output is correct
16 Correct 5 ms 760 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
18 Correct 5 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 831 ms 55764 KB Output is correct
2 Correct 847 ms 59816 KB Output is correct
3 Correct 846 ms 59792 KB Output is correct
4 Correct 839 ms 59840 KB Output is correct
5 Correct 759 ms 55032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 4968 KB Output is correct
2 Correct 71 ms 5068 KB Output is correct
3 Correct 59 ms 4712 KB Output is correct
4 Correct 58 ms 4684 KB Output is correct
5 Correct 61 ms 4760 KB Output is correct
6 Correct 55 ms 4584 KB Output is correct
7 Correct 58 ms 4712 KB Output is correct
8 Correct 56 ms 4712 KB Output is correct
9 Correct 44 ms 3668 KB Output is correct
10 Correct 55 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 5 ms 636 KB Output is correct
14 Correct 6 ms 760 KB Output is correct
15 Correct 6 ms 760 KB Output is correct
16 Correct 5 ms 760 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
18 Correct 5 ms 636 KB Output is correct
19 Correct 170 ms 12128 KB Output is correct
20 Correct 173 ms 12352 KB Output is correct
21 Correct 164 ms 12392 KB Output is correct
22 Correct 163 ms 12356 KB Output is correct
23 Correct 163 ms 12256 KB Output is correct
24 Correct 145 ms 11088 KB Output is correct
25 Correct 144 ms 11100 KB Output is correct
26 Correct 151 ms 11448 KB Output is correct
27 Correct 150 ms 11476 KB Output is correct
28 Correct 151 ms 11404 KB Output is correct
29 Correct 155 ms 11616 KB Output is correct
30 Correct 156 ms 11360 KB Output is correct
31 Correct 155 ms 11628 KB Output is correct
32 Correct 153 ms 11456 KB Output is correct
33 Correct 155 ms 11512 KB Output is correct
34 Correct 140 ms 11252 KB Output is correct
35 Correct 144 ms 11232 KB Output is correct
36 Correct 140 ms 11000 KB Output is correct
37 Correct 139 ms 10984 KB Output is correct
38 Correct 142 ms 11360 KB Output is correct
39 Correct 142 ms 10504 KB Output is correct
40 Correct 121 ms 9320 KB Output is correct
41 Correct 122 ms 10208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 5 ms 636 KB Output is correct
14 Correct 6 ms 760 KB Output is correct
15 Correct 6 ms 760 KB Output is correct
16 Correct 5 ms 760 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
18 Correct 5 ms 636 KB Output is correct
19 Correct 831 ms 55764 KB Output is correct
20 Correct 847 ms 59816 KB Output is correct
21 Correct 846 ms 59792 KB Output is correct
22 Correct 839 ms 59840 KB Output is correct
23 Correct 759 ms 55032 KB Output is correct
24 Correct 74 ms 4968 KB Output is correct
25 Correct 71 ms 5068 KB Output is correct
26 Correct 59 ms 4712 KB Output is correct
27 Correct 58 ms 4684 KB Output is correct
28 Correct 61 ms 4760 KB Output is correct
29 Correct 55 ms 4584 KB Output is correct
30 Correct 58 ms 4712 KB Output is correct
31 Correct 56 ms 4712 KB Output is correct
32 Correct 44 ms 3668 KB Output is correct
33 Correct 55 ms 4716 KB Output is correct
34 Correct 170 ms 12128 KB Output is correct
35 Correct 173 ms 12352 KB Output is correct
36 Correct 164 ms 12392 KB Output is correct
37 Correct 163 ms 12356 KB Output is correct
38 Correct 163 ms 12256 KB Output is correct
39 Correct 145 ms 11088 KB Output is correct
40 Correct 144 ms 11100 KB Output is correct
41 Correct 151 ms 11448 KB Output is correct
42 Correct 150 ms 11476 KB Output is correct
43 Correct 151 ms 11404 KB Output is correct
44 Correct 155 ms 11616 KB Output is correct
45 Correct 156 ms 11360 KB Output is correct
46 Correct 155 ms 11628 KB Output is correct
47 Correct 153 ms 11456 KB Output is correct
48 Correct 155 ms 11512 KB Output is correct
49 Correct 140 ms 11252 KB Output is correct
50 Correct 144 ms 11232 KB Output is correct
51 Correct 140 ms 11000 KB Output is correct
52 Correct 139 ms 10984 KB Output is correct
53 Correct 142 ms 11360 KB Output is correct
54 Correct 142 ms 10504 KB Output is correct
55 Correct 121 ms 9320 KB Output is correct
56 Correct 122 ms 10208 KB Output is correct
57 Correct 864 ms 59532 KB Output is correct
58 Correct 873 ms 60240 KB Output is correct
59 Correct 842 ms 60408 KB Output is correct
60 Correct 850 ms 60408 KB Output is correct
61 Correct 870 ms 45988 KB Output is correct
62 Correct 846 ms 60240 KB Output is correct
63 Correct 717 ms 53752 KB Output is correct
64 Correct 721 ms 53592 KB Output is correct
65 Correct 766 ms 55488 KB Output is correct
66 Correct 766 ms 55236 KB Output is correct
67 Correct 763 ms 55404 KB Output is correct
68 Correct 765 ms 55664 KB Output is correct
69 Correct 777 ms 39472 KB Output is correct
70 Correct 769 ms 44556 KB Output is correct
71 Correct 766 ms 55668 KB Output is correct
72 Correct 776 ms 55388 KB Output is correct
73 Correct 686 ms 52524 KB Output is correct
74 Correct 693 ms 43388 KB Output is correct
75 Correct 688 ms 52908 KB Output is correct
76 Correct 690 ms 53176 KB Output is correct
77 Correct 688 ms 42180 KB Output is correct
78 Correct 733 ms 51704 KB Output is correct
79 Correct 584 ms 44244 KB Output is correct
80 Correct 625 ms 50040 KB Output is correct