# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
156000 | 2019-10-02T14:29:25 Z | ASDF123 | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 3000 ms | 27204 KB |
#include <bits/stdc++.h> //#define int long long #define fr first #define sc second #define all(s) s.begin(), s.end() #define szof(s) (int)s.size() using namespace std; const int N = (int)1e6 + 5; const int INF = 1e9 + 7; const int MOD = (int)1e9 + 7; int tests = 1; int n, l, r, k; int a[N]; pair<int, int> tree[N * 4]; int pref[N]; void build(int v = 1, int tl = 1, int tr = N) { if (tl == tr) { tree[v].fr = a[tl]; tree[v].sc = a[tl]; return; } int mid = tl + tr >> 1; build(v + v, tl, mid); build(v + v + 1, mid + 1, tr); tree[v].fr = min(tree[v + v].fr, tree[v + v + 1].fr); tree[v].sc = max(tree[v + v].sc, tree[v + v + 1].sc); } pair<int, int> get(int l, int r, int v = 1, int tl = 1, int tr = N) { if (l <= tl && tr <= r) { return tree[v]; } if (l > tr || tl > r) { return {INF, -INF}; } int mid = tl + tr >> 1; pair<int, int> p1 = get(l, r, v + v, tl, mid); pair<int, int> p2 = get(l, r, v + v + 1, mid + 1, tr); return {min(p1.fr, p2.fr), max(p1.sc, p2.sc)}; } int bad(int l, int r) { return pref[r - 1] - pref[l - 1]; } void solve() { scanf("%d%d%d", &l, &r, &k); if (k < get(l, r).fr) { if (bad(l, r)) { puts("0"); } else { puts("1"); } return; } set <int> st; set <int> ::iterator it; bool ok = true; int mn = INF; for (int i = r; i >= l; i--) { if (i == r) { st.insert(a[i]); mn = min(mn, a[i]); continue; } if (mn < a[i]) { it = st.lower_bound(a[i]); it--; if (*it + a[i] > k) { ok = false; break; } } st.insert(a[i]); mn = min(mn, a[i]); } if (ok) { puts("1"); } else { puts("0"); } } main() { scanf("%d%d", &n, &tests); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } build(); for (int i = 1; i <= n; i++) { pref[i] = pref[i - 1] + (a[i] > a[i + 1]); } // for (int i = 1; i <= n; i++) { // cout << pref[i] << " "; // }cout << endl; // // while (1) { // int l, r; // cin >> l >> r; // cout << get(l, r) << endl; // } while (tests--) { solve(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 16760 KB | Output is correct |
2 | Correct | 24 ms | 16760 KB | Output is correct |
3 | Correct | 24 ms | 16760 KB | Output is correct |
4 | Correct | 24 ms | 16764 KB | Output is correct |
5 | Correct | 24 ms | 16760 KB | Output is correct |
6 | Correct | 25 ms | 16760 KB | Output is correct |
7 | Correct | 24 ms | 16760 KB | Output is correct |
8 | Correct | 34 ms | 16760 KB | Output is correct |
9 | Correct | 27 ms | 16760 KB | Output is correct |
10 | Correct | 25 ms | 16760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 16760 KB | Output is correct |
2 | Correct | 24 ms | 16760 KB | Output is correct |
3 | Correct | 24 ms | 16760 KB | Output is correct |
4 | Correct | 24 ms | 16764 KB | Output is correct |
5 | Correct | 24 ms | 16760 KB | Output is correct |
6 | Correct | 25 ms | 16760 KB | Output is correct |
7 | Correct | 24 ms | 16760 KB | Output is correct |
8 | Correct | 34 ms | 16760 KB | Output is correct |
9 | Correct | 27 ms | 16760 KB | Output is correct |
10 | Correct | 25 ms | 16760 KB | Output is correct |
11 | Correct | 31 ms | 16760 KB | Output is correct |
12 | Correct | 35 ms | 16988 KB | Output is correct |
13 | Correct | 36 ms | 16888 KB | Output is correct |
14 | Correct | 43 ms | 17016 KB | Output is correct |
15 | Correct | 47 ms | 16888 KB | Output is correct |
16 | Correct | 1476 ms | 17080 KB | Output is correct |
17 | Correct | 809 ms | 17140 KB | Output is correct |
18 | Correct | 156 ms | 16896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1476 ms | 26588 KB | Output is correct |
2 | Correct | 1534 ms | 26772 KB | Output is correct |
3 | Correct | 1532 ms | 26584 KB | Output is correct |
4 | Correct | 1524 ms | 26608 KB | Output is correct |
5 | Correct | 1475 ms | 26596 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3038 ms | 17636 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 16760 KB | Output is correct |
2 | Correct | 24 ms | 16760 KB | Output is correct |
3 | Correct | 24 ms | 16760 KB | Output is correct |
4 | Correct | 24 ms | 16764 KB | Output is correct |
5 | Correct | 24 ms | 16760 KB | Output is correct |
6 | Correct | 25 ms | 16760 KB | Output is correct |
7 | Correct | 24 ms | 16760 KB | Output is correct |
8 | Correct | 34 ms | 16760 KB | Output is correct |
9 | Correct | 27 ms | 16760 KB | Output is correct |
10 | Correct | 25 ms | 16760 KB | Output is correct |
11 | Correct | 31 ms | 16760 KB | Output is correct |
12 | Correct | 35 ms | 16988 KB | Output is correct |
13 | Correct | 36 ms | 16888 KB | Output is correct |
14 | Correct | 43 ms | 17016 KB | Output is correct |
15 | Correct | 47 ms | 16888 KB | Output is correct |
16 | Correct | 1476 ms | 17080 KB | Output is correct |
17 | Correct | 809 ms | 17140 KB | Output is correct |
18 | Correct | 156 ms | 16896 KB | Output is correct |
19 | Execution timed out | 3031 ms | 27204 KB | Time limit exceeded |
20 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 16760 KB | Output is correct |
2 | Correct | 24 ms | 16760 KB | Output is correct |
3 | Correct | 24 ms | 16760 KB | Output is correct |
4 | Correct | 24 ms | 16764 KB | Output is correct |
5 | Correct | 24 ms | 16760 KB | Output is correct |
6 | Correct | 25 ms | 16760 KB | Output is correct |
7 | Correct | 24 ms | 16760 KB | Output is correct |
8 | Correct | 34 ms | 16760 KB | Output is correct |
9 | Correct | 27 ms | 16760 KB | Output is correct |
10 | Correct | 25 ms | 16760 KB | Output is correct |
11 | Correct | 31 ms | 16760 KB | Output is correct |
12 | Correct | 35 ms | 16988 KB | Output is correct |
13 | Correct | 36 ms | 16888 KB | Output is correct |
14 | Correct | 43 ms | 17016 KB | Output is correct |
15 | Correct | 47 ms | 16888 KB | Output is correct |
16 | Correct | 1476 ms | 17080 KB | Output is correct |
17 | Correct | 809 ms | 17140 KB | Output is correct |
18 | Correct | 156 ms | 16896 KB | Output is correct |
19 | Correct | 1476 ms | 26588 KB | Output is correct |
20 | Correct | 1534 ms | 26772 KB | Output is correct |
21 | Correct | 1532 ms | 26584 KB | Output is correct |
22 | Correct | 1524 ms | 26608 KB | Output is correct |
23 | Correct | 1475 ms | 26596 KB | Output is correct |
24 | Execution timed out | 3038 ms | 17636 KB | Time limit exceeded |
25 | Halted | 0 ms | 0 KB | - |