Submission #345492

# Submission time Handle Problem Language Result Execution time Memory
345492 2021-01-07T13:27:09 Z Valera_Grinenko Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1367 ms 89564 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e6 + 42;
int fw[N], w[N];
bool ans[N];
vector<pair<pair<int, int>, int> > q[N];
void upd(int pos, int x) {
  for(; pos > 0; pos -= (pos & -pos)) fw[pos] = max(fw[pos], x);
}
int get(int pos) {
  int res = 0;
  for(; pos < N; pos += (pos & -pos)) res = max(res, fw[pos]);
  return res;
}
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n = 0, m = 0;

  cin >> n >> m;

  for(int i = 1; i <= n; i++) cin >> w[i];

  for(int i = 0; i < m; i++) {
    int l, r, k;
    cin >> l >> r >> k;
    q[r].pb(mp(mp(l, k), i));
  }

  vector<int> av;

  for(int i = 1; i <= n; i++) {
    while(!av.empty() && w[av.back()] <= w[i]) av.pop_back();
    if(!av.empty()) upd(av.back(), w[av.back()] + w[i]);
    av.pb(i);
    for(auto& x : q[i]) {
      ans[x.se] = (get(x.fi.fi) <= x.fi.se);
    }
  }

  for(int i = 0; i < m; i++) cout << ans[i] << '\n';

  return 0;
}
/*
5 2
3 5 1 8 2
1 3 6
2 5 3
*/

Compilation message

sortbooks.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 28 ms 23788 KB Output is correct
3 Correct 17 ms 23908 KB Output is correct
4 Correct 18 ms 23916 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 20 ms 23916 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 16 ms 23916 KB Output is correct
9 Correct 16 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 28 ms 23788 KB Output is correct
3 Correct 17 ms 23908 KB Output is correct
4 Correct 18 ms 23916 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 20 ms 23916 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 16 ms 23916 KB Output is correct
9 Correct 16 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
11 Correct 17 ms 24044 KB Output is correct
12 Correct 24 ms 24044 KB Output is correct
13 Correct 21 ms 24044 KB Output is correct
14 Correct 21 ms 24172 KB Output is correct
15 Correct 21 ms 24172 KB Output is correct
16 Correct 20 ms 24044 KB Output is correct
17 Correct 22 ms 24044 KB Output is correct
18 Correct 25 ms 24044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1242 ms 56640 KB Output is correct
2 Correct 1367 ms 69100 KB Output is correct
3 Correct 1151 ms 69136 KB Output is correct
4 Correct 1127 ms 69228 KB Output is correct
5 Correct 960 ms 65308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 28988 KB Output is correct
2 Correct 88 ms 28740 KB Output is correct
3 Correct 96 ms 28576 KB Output is correct
4 Correct 100 ms 28652 KB Output is correct
5 Correct 81 ms 28616 KB Output is correct
6 Correct 69 ms 28140 KB Output is correct
7 Correct 76 ms 28196 KB Output is correct
8 Correct 85 ms 28200 KB Output is correct
9 Correct 86 ms 26916 KB Output is correct
10 Correct 87 ms 28180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 28 ms 23788 KB Output is correct
3 Correct 17 ms 23908 KB Output is correct
4 Correct 18 ms 23916 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 20 ms 23916 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 16 ms 23916 KB Output is correct
9 Correct 16 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
11 Correct 17 ms 24044 KB Output is correct
12 Correct 24 ms 24044 KB Output is correct
13 Correct 21 ms 24044 KB Output is correct
14 Correct 21 ms 24172 KB Output is correct
15 Correct 21 ms 24172 KB Output is correct
16 Correct 20 ms 24044 KB Output is correct
17 Correct 22 ms 24044 KB Output is correct
18 Correct 25 ms 24044 KB Output is correct
19 Correct 208 ms 36900 KB Output is correct
20 Correct 217 ms 36844 KB Output is correct
21 Correct 190 ms 36204 KB Output is correct
22 Correct 206 ms 36208 KB Output is correct
23 Correct 167 ms 36204 KB Output is correct
24 Correct 182 ms 35168 KB Output is correct
25 Correct 150 ms 35436 KB Output is correct
26 Correct 193 ms 35604 KB Output is correct
27 Correct 174 ms 35564 KB Output is correct
28 Correct 203 ms 35820 KB Output is correct
29 Correct 194 ms 36204 KB Output is correct
30 Correct 174 ms 36076 KB Output is correct
31 Correct 170 ms 36076 KB Output is correct
32 Correct 190 ms 36076 KB Output is correct
33 Correct 176 ms 36076 KB Output is correct
34 Correct 155 ms 34884 KB Output is correct
35 Correct 171 ms 34780 KB Output is correct
36 Correct 211 ms 34768 KB Output is correct
37 Correct 154 ms 34668 KB Output is correct
38 Correct 153 ms 34796 KB Output is correct
39 Correct 212 ms 34596 KB Output is correct
40 Correct 168 ms 33112 KB Output is correct
41 Correct 166 ms 34080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 28 ms 23788 KB Output is correct
3 Correct 17 ms 23908 KB Output is correct
4 Correct 18 ms 23916 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 20 ms 23916 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 16 ms 23916 KB Output is correct
9 Correct 16 ms 23916 KB Output is correct
10 Correct 16 ms 23916 KB Output is correct
11 Correct 17 ms 24044 KB Output is correct
12 Correct 24 ms 24044 KB Output is correct
13 Correct 21 ms 24044 KB Output is correct
14 Correct 21 ms 24172 KB Output is correct
15 Correct 21 ms 24172 KB Output is correct
16 Correct 20 ms 24044 KB Output is correct
17 Correct 22 ms 24044 KB Output is correct
18 Correct 25 ms 24044 KB Output is correct
19 Correct 1242 ms 56640 KB Output is correct
20 Correct 1367 ms 69100 KB Output is correct
21 Correct 1151 ms 69136 KB Output is correct
22 Correct 1127 ms 69228 KB Output is correct
23 Correct 960 ms 65308 KB Output is correct
24 Correct 103 ms 28988 KB Output is correct
25 Correct 88 ms 28740 KB Output is correct
26 Correct 96 ms 28576 KB Output is correct
27 Correct 100 ms 28652 KB Output is correct
28 Correct 81 ms 28616 KB Output is correct
29 Correct 69 ms 28140 KB Output is correct
30 Correct 76 ms 28196 KB Output is correct
31 Correct 85 ms 28200 KB Output is correct
32 Correct 86 ms 26916 KB Output is correct
33 Correct 87 ms 28180 KB Output is correct
34 Correct 208 ms 36900 KB Output is correct
35 Correct 217 ms 36844 KB Output is correct
36 Correct 190 ms 36204 KB Output is correct
37 Correct 206 ms 36208 KB Output is correct
38 Correct 167 ms 36204 KB Output is correct
39 Correct 182 ms 35168 KB Output is correct
40 Correct 150 ms 35436 KB Output is correct
41 Correct 193 ms 35604 KB Output is correct
42 Correct 174 ms 35564 KB Output is correct
43 Correct 203 ms 35820 KB Output is correct
44 Correct 194 ms 36204 KB Output is correct
45 Correct 174 ms 36076 KB Output is correct
46 Correct 170 ms 36076 KB Output is correct
47 Correct 190 ms 36076 KB Output is correct
48 Correct 176 ms 36076 KB Output is correct
49 Correct 155 ms 34884 KB Output is correct
50 Correct 171 ms 34780 KB Output is correct
51 Correct 211 ms 34768 KB Output is correct
52 Correct 154 ms 34668 KB Output is correct
53 Correct 153 ms 34796 KB Output is correct
54 Correct 212 ms 34596 KB Output is correct
55 Correct 168 ms 33112 KB Output is correct
56 Correct 166 ms 34080 KB Output is correct
57 Correct 1054 ms 59452 KB Output is correct
58 Correct 1148 ms 89564 KB Output is correct
59 Correct 1000 ms 87868 KB Output is correct
60 Correct 1133 ms 88168 KB Output is correct
61 Correct 1190 ms 87916 KB Output is correct
62 Correct 1031 ms 87796 KB Output is correct
63 Correct 919 ms 80760 KB Output is correct
64 Correct 752 ms 80632 KB Output is correct
65 Correct 957 ms 83808 KB Output is correct
66 Correct 1004 ms 83728 KB Output is correct
67 Correct 991 ms 83872 KB Output is correct
68 Correct 979 ms 85604 KB Output is correct
69 Correct 996 ms 85460 KB Output is correct
70 Correct 974 ms 85340 KB Output is correct
71 Correct 1213 ms 85256 KB Output is correct
72 Correct 988 ms 85172 KB Output is correct
73 Correct 657 ms 76640 KB Output is correct
74 Correct 684 ms 77776 KB Output is correct
75 Correct 738 ms 76968 KB Output is correct
76 Correct 695 ms 76824 KB Output is correct
77 Correct 685 ms 76604 KB Output is correct
78 Correct 1045 ms 78940 KB Output is correct
79 Correct 800 ms 68620 KB Output is correct
80 Correct 942 ms 74768 KB Output is correct