Submission #1096199

# Submission time Handle Problem Language Result Execution time Memory
1096199 2024-10-04T05:29:33 Z stdfloat Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
2779 ms 262148 KB
    #include <bits/stdc++.h>
    using namespace std;
     
    using ll = long long;
     
    #define sz(v)  (int)(v).size()
    #define all(v) (v).begin(), v.end()
     
    int mx;
     
    vector<int> a, st, vis;
     
    vector<vector<int>> v;
     
    void bld(int nd, int l, int r) {
    	if (l == r) {
    		vis[nd] = 0; st[nd] = a[l]; v[nd] = {a[l]};
    		return;
    	}
     
    	int ch = (nd << 1) + 1, md = l + r >> 1;
    	bld(ch, l, md); bld(ch + 1, md + 1, r);
     
    	st[nd] = max(st[ch], st[ch + 1]);
     
    	v[nd].assign(sz(v[ch]) + sz(v[ch + 1]), 0);
    	merge(all(v[ch]), all(v[ch + 1]), v[nd].begin());
    	
    	int mx = 0;
    	for (int i = l; i <= r; i++) {
    		if (mx > a[i]) vis[nd] = max(vis[nd], mx + a[i]);
    		else mx = a[i];
    	}
    }
     
    bool fnd(int nd, int l, int r, int x, int y, int k) {
    	if (r < x || y < l) return true;
     
    	if (x <= l && r <= y) {
    		bool tr = (max(vis[nd], (mx > v[nd][0] ? mx + *--lower_bound(all(v[nd]), mx) : 0)) <= k);
    		mx = max(mx, st[nd]);
    		return tr;
    	}
     
    	int ch = (nd << 1) + 1, md = l + r >> 1;
    	return (!fnd(ch, l, md, x, y, k) || !fnd(ch + 1, md + 1, r, x, y, k) ? false : true);
    }
     
    int main() {
    	ios::sync_with_stdio(false); cin.tie(nullptr);
     
    	int n, q;
    	cin >> n >> q;
     
    	a.assign(n, 0);
    	for (auto &i : a)
    		cin >> i;
     
    	v.assign(n << 2, {});
    	st = vis = vector<int>(n << 2);
    	bld(0, 0, n - 1);
     
    	while (q--) {
    		int l, r, k;
    		cin >> l >> r >> k; l--; r--;
     
    		mx = 0;
    		cout << fnd(0, 0, n - 1, l, r, k) << endl;
    	}
    }

Compilation message

sortbooks.cpp: In function 'void bld(int, int, int)':
sortbooks.cpp:21:37: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |      int ch = (nd << 1) + 1, md = l + r >> 1;
      |                                   ~~^~~
sortbooks.cpp: In function 'bool fnd(int, int, int, int, int, int)':
sortbooks.cpp:45:37: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |      int ch = (nd << 1) + 1, md = l + r >> 1;
      |                                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 5 ms 1624 KB Output is correct
13 Correct 10 ms 1628 KB Output is correct
14 Correct 8 ms 1760 KB Output is correct
15 Correct 9 ms 1628 KB Output is correct
16 Correct 8 ms 1500 KB Output is correct
17 Correct 8 ms 1372 KB Output is correct
18 Correct 8 ms 1488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2249 ms 262144 KB Output is correct
2 Correct 2286 ms 262144 KB Output is correct
3 Correct 2350 ms 262144 KB Output is correct
4 Correct 2293 ms 262144 KB Output is correct
5 Runtime error 2779 ms 262148 KB Memory limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 195 ms 26704 KB Output is correct
2 Correct 195 ms 26792 KB Output is correct
3 Correct 200 ms 26704 KB Output is correct
4 Correct 205 ms 26704 KB Output is correct
5 Correct 206 ms 27124 KB Output is correct
6 Correct 156 ms 26704 KB Output is correct
7 Correct 164 ms 26708 KB Output is correct
8 Correct 186 ms 26452 KB Output is correct
9 Correct 121 ms 1872 KB Output is correct
10 Correct 167 ms 26448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 5 ms 1624 KB Output is correct
13 Correct 10 ms 1628 KB Output is correct
14 Correct 8 ms 1760 KB Output is correct
15 Correct 9 ms 1628 KB Output is correct
16 Correct 8 ms 1500 KB Output is correct
17 Correct 8 ms 1372 KB Output is correct
18 Correct 8 ms 1488 KB Output is correct
19 Correct 453 ms 55760 KB Output is correct
20 Correct 454 ms 55608 KB Output is correct
21 Correct 400 ms 56400 KB Output is correct
22 Correct 402 ms 56400 KB Output is correct
23 Correct 397 ms 56500 KB Output is correct
24 Correct 397 ms 56332 KB Output is correct
25 Correct 421 ms 56188 KB Output is correct
26 Correct 409 ms 56404 KB Output is correct
27 Correct 446 ms 56480 KB Output is correct
28 Correct 449 ms 56536 KB Output is correct
29 Correct 465 ms 56404 KB Output is correct
30 Correct 471 ms 56396 KB Output is correct
31 Correct 449 ms 56404 KB Output is correct
32 Correct 453 ms 56404 KB Output is correct
33 Correct 452 ms 56644 KB Output is correct
34 Correct 343 ms 56280 KB Output is correct
35 Correct 353 ms 56400 KB Output is correct
36 Correct 347 ms 56436 KB Output is correct
37 Correct 351 ms 56368 KB Output is correct
38 Correct 351 ms 56660 KB Output is correct
39 Correct 393 ms 55472 KB Output is correct
40 Correct 355 ms 37456 KB Output is correct
41 Correct 391 ms 55124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 5 ms 1624 KB Output is correct
13 Correct 10 ms 1628 KB Output is correct
14 Correct 8 ms 1760 KB Output is correct
15 Correct 9 ms 1628 KB Output is correct
16 Correct 8 ms 1500 KB Output is correct
17 Correct 8 ms 1372 KB Output is correct
18 Correct 8 ms 1488 KB Output is correct
19 Correct 2249 ms 262144 KB Output is correct
20 Correct 2286 ms 262144 KB Output is correct
21 Correct 2350 ms 262144 KB Output is correct
22 Correct 2293 ms 262144 KB Output is correct
23 Runtime error 2779 ms 262148 KB Memory limit exceeded
24 Halted 0 ms 0 KB -