Submission #681431

# Submission time Handle Problem Language Result Execution time Memory
681431 2023-01-13T05:24:10 Z acm Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1770 ms 168080 KB
#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define precision     \
  cout.precision(30); \
  cerr.precision(10);
#define ll long long
#define ld long double
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define mp(x, y) make_pair(x, y)
#define all(x) x.begin(), x.end()
#define pc(x) __builtin_popcount(x)
#define pcll(x) __builtin_popcountll(x)
#define F first
#define S second
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
void ioi(string name) {
  freopen((name + ".in").c_str(), "r", stdin);
  freopen((name + ".out").c_str(), "w", stdout);
}
ll n, m, a[1000005], b[1000005], k[1000005], t[4000005];
vector<ll> d, e[1000005];
vector<pair<ll, ll>> q[1000005];
void upd(ll v, ll l, ll r, ll x, ll y) {
  if (l == r) {
    t[v] = y;
    return;
  }
  ll tm = (l + r) / 2;
  if (x <= tm)
    upd(v + v, l, tm, x, y);
  else
    upd(v + v + 1, tm + 1, r, x, y);
  t[v] = max(t[v + v], t[v + v + 1]);
}
ll get(ll v, ll l, ll r, ll x, ll y) {
  if (r < x || y < l) return 0;
  if (x <= l && r <= y) return t[v];
  ll tm = (l + r) / 2;
  return max(get(v + v, l, tm, x, y), get(v + v + 1, tm + 1, r, x, y));
}
int main() {
  speed;
  precision;
  // code
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    while (sz(d) && a[d.back()] <= a[i]) d.pop_back();
    b[i] = (sz(d) ? d.back() : 0);
    e[b[i]].pb(i);
    d.pb(i);
  }
  for (int i = 1; i <= m; i++) {
    ll l, r;
    cin >> l >> r >> k[i];
    q[l].pb(mp(r, i));
  }
  for (int i = n; i >= 1; i--) {
    for (auto x : e[i]) upd(1, 1, n, x, a[x] + a[i]);
    for (auto x : q[i]) b[x.S] = get(1, 1, n, i, x.F) <= k[x.S];
  }
  for (int i = 1; i <= m; i++) cout << b[i] << "\n";
    // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Compilation message

sortbooks.cpp: In function 'void ioi(std::string)':
sortbooks.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   freopen((name + ".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   freopen((name + ".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47316 KB Output is correct
2 Correct 26 ms 47308 KB Output is correct
3 Correct 25 ms 47316 KB Output is correct
4 Correct 26 ms 47236 KB Output is correct
5 Correct 37 ms 47316 KB Output is correct
6 Correct 24 ms 47340 KB Output is correct
7 Correct 34 ms 47332 KB Output is correct
8 Correct 25 ms 47288 KB Output is correct
9 Correct 25 ms 47328 KB Output is correct
10 Correct 25 ms 47280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47316 KB Output is correct
2 Correct 26 ms 47308 KB Output is correct
3 Correct 25 ms 47316 KB Output is correct
4 Correct 26 ms 47236 KB Output is correct
5 Correct 37 ms 47316 KB Output is correct
6 Correct 24 ms 47340 KB Output is correct
7 Correct 34 ms 47332 KB Output is correct
8 Correct 25 ms 47288 KB Output is correct
9 Correct 25 ms 47328 KB Output is correct
10 Correct 25 ms 47280 KB Output is correct
11 Correct 28 ms 47568 KB Output is correct
12 Correct 27 ms 47768 KB Output is correct
13 Correct 28 ms 47780 KB Output is correct
14 Correct 32 ms 47928 KB Output is correct
15 Correct 37 ms 47928 KB Output is correct
16 Correct 33 ms 47740 KB Output is correct
17 Correct 26 ms 47692 KB Output is correct
18 Correct 27 ms 47716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1521 ms 134636 KB Output is correct
2 Correct 1754 ms 134092 KB Output is correct
3 Correct 1494 ms 134124 KB Output is correct
4 Correct 1505 ms 134080 KB Output is correct
5 Correct 1156 ms 106868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 58364 KB Output is correct
2 Correct 140 ms 58352 KB Output is correct
3 Correct 110 ms 55176 KB Output is correct
4 Correct 101 ms 55192 KB Output is correct
5 Correct 126 ms 55256 KB Output is correct
6 Correct 88 ms 54984 KB Output is correct
7 Correct 108 ms 54912 KB Output is correct
8 Correct 98 ms 56020 KB Output is correct
9 Correct 64 ms 52376 KB Output is correct
10 Correct 104 ms 55716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47316 KB Output is correct
2 Correct 26 ms 47308 KB Output is correct
3 Correct 25 ms 47316 KB Output is correct
4 Correct 26 ms 47236 KB Output is correct
5 Correct 37 ms 47316 KB Output is correct
6 Correct 24 ms 47340 KB Output is correct
7 Correct 34 ms 47332 KB Output is correct
8 Correct 25 ms 47288 KB Output is correct
9 Correct 25 ms 47328 KB Output is correct
10 Correct 25 ms 47280 KB Output is correct
11 Correct 28 ms 47568 KB Output is correct
12 Correct 27 ms 47768 KB Output is correct
13 Correct 28 ms 47780 KB Output is correct
14 Correct 32 ms 47928 KB Output is correct
15 Correct 37 ms 47928 KB Output is correct
16 Correct 33 ms 47740 KB Output is correct
17 Correct 26 ms 47692 KB Output is correct
18 Correct 27 ms 47716 KB Output is correct
19 Correct 324 ms 67132 KB Output is correct
20 Correct 458 ms 72136 KB Output is correct
21 Correct 243 ms 71896 KB Output is correct
22 Correct 262 ms 71760 KB Output is correct
23 Correct 265 ms 71832 KB Output is correct
24 Correct 191 ms 65524 KB Output is correct
25 Correct 184 ms 65476 KB Output is correct
26 Correct 232 ms 65720 KB Output is correct
27 Correct 201 ms 65732 KB Output is correct
28 Correct 204 ms 65712 KB Output is correct
29 Correct 238 ms 65904 KB Output is correct
30 Correct 239 ms 65900 KB Output is correct
31 Correct 216 ms 65884 KB Output is correct
32 Correct 233 ms 65864 KB Output is correct
33 Correct 388 ms 65876 KB Output is correct
34 Correct 205 ms 64712 KB Output is correct
35 Correct 179 ms 64684 KB Output is correct
36 Correct 166 ms 64472 KB Output is correct
37 Correct 165 ms 64484 KB Output is correct
38 Correct 170 ms 64696 KB Output is correct
39 Correct 195 ms 65912 KB Output is correct
40 Correct 160 ms 62012 KB Output is correct
41 Correct 214 ms 65640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47316 KB Output is correct
2 Correct 26 ms 47308 KB Output is correct
3 Correct 25 ms 47316 KB Output is correct
4 Correct 26 ms 47236 KB Output is correct
5 Correct 37 ms 47316 KB Output is correct
6 Correct 24 ms 47340 KB Output is correct
7 Correct 34 ms 47332 KB Output is correct
8 Correct 25 ms 47288 KB Output is correct
9 Correct 25 ms 47328 KB Output is correct
10 Correct 25 ms 47280 KB Output is correct
11 Correct 28 ms 47568 KB Output is correct
12 Correct 27 ms 47768 KB Output is correct
13 Correct 28 ms 47780 KB Output is correct
14 Correct 32 ms 47928 KB Output is correct
15 Correct 37 ms 47928 KB Output is correct
16 Correct 33 ms 47740 KB Output is correct
17 Correct 26 ms 47692 KB Output is correct
18 Correct 27 ms 47716 KB Output is correct
19 Correct 1521 ms 134636 KB Output is correct
20 Correct 1754 ms 134092 KB Output is correct
21 Correct 1494 ms 134124 KB Output is correct
22 Correct 1505 ms 134080 KB Output is correct
23 Correct 1156 ms 106868 KB Output is correct
24 Correct 124 ms 58364 KB Output is correct
25 Correct 140 ms 58352 KB Output is correct
26 Correct 110 ms 55176 KB Output is correct
27 Correct 101 ms 55192 KB Output is correct
28 Correct 126 ms 55256 KB Output is correct
29 Correct 88 ms 54984 KB Output is correct
30 Correct 108 ms 54912 KB Output is correct
31 Correct 98 ms 56020 KB Output is correct
32 Correct 64 ms 52376 KB Output is correct
33 Correct 104 ms 55716 KB Output is correct
34 Correct 324 ms 67132 KB Output is correct
35 Correct 458 ms 72136 KB Output is correct
36 Correct 243 ms 71896 KB Output is correct
37 Correct 262 ms 71760 KB Output is correct
38 Correct 265 ms 71832 KB Output is correct
39 Correct 191 ms 65524 KB Output is correct
40 Correct 184 ms 65476 KB Output is correct
41 Correct 232 ms 65720 KB Output is correct
42 Correct 201 ms 65732 KB Output is correct
43 Correct 204 ms 65712 KB Output is correct
44 Correct 238 ms 65904 KB Output is correct
45 Correct 239 ms 65900 KB Output is correct
46 Correct 216 ms 65884 KB Output is correct
47 Correct 233 ms 65864 KB Output is correct
48 Correct 388 ms 65876 KB Output is correct
49 Correct 205 ms 64712 KB Output is correct
50 Correct 179 ms 64684 KB Output is correct
51 Correct 166 ms 64472 KB Output is correct
52 Correct 165 ms 64484 KB Output is correct
53 Correct 170 ms 64696 KB Output is correct
54 Correct 195 ms 65912 KB Output is correct
55 Correct 160 ms 62012 KB Output is correct
56 Correct 214 ms 65640 KB Output is correct
57 Correct 1565 ms 168080 KB Output is correct
58 Correct 1531 ms 168024 KB Output is correct
59 Correct 1770 ms 167456 KB Output is correct
60 Correct 1721 ms 167564 KB Output is correct
61 Correct 1500 ms 167328 KB Output is correct
62 Correct 1448 ms 167432 KB Output is correct
63 Correct 942 ms 134316 KB Output is correct
64 Correct 998 ms 134368 KB Output is correct
65 Correct 1354 ms 140096 KB Output is correct
66 Correct 1220 ms 140252 KB Output is correct
67 Correct 1253 ms 140144 KB Output is correct
68 Correct 1274 ms 140760 KB Output is correct
69 Correct 1261 ms 140820 KB Output is correct
70 Correct 1220 ms 140580 KB Output is correct
71 Correct 1273 ms 140528 KB Output is correct
72 Correct 1250 ms 140652 KB Output is correct
73 Correct 906 ms 131504 KB Output is correct
74 Correct 932 ms 132476 KB Output is correct
75 Correct 925 ms 131556 KB Output is correct
76 Correct 870 ms 131608 KB Output is correct
77 Correct 867 ms 131732 KB Output is correct
78 Correct 1151 ms 140324 KB Output is correct
79 Correct 777 ms 118580 KB Output is correct
80 Correct 1281 ms 139436 KB Output is correct