Submission #467041

# Submission time Handle Problem Language Result Execution time Memory
467041 2021-08-21T11:54:03 Z hhhhaura Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1346 ms 73608 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

using namespace std;

#define pii pair<int, int>
namespace bit {
	int n;
	vector<int> v;
	void init_(int _n) {
		n = _n;
		v.assign(n + 1, 0);
	}
	int lowbit(int x) {
		return x & (-x);
	}
	void modify(int x, int val) {
		for(int i = x; i <= n; i += lowbit(i)) {
			v[i] = max(v[i], val);
		}
	}
	int query(int x) {
		int ans = 0;
		for(int i = x; i > 0; i -= lowbit(i)) {
			ans = max(ans, v[i]);
		}
		return ans;
	}
};
namespace solver {
	int n, m;
	vector<int> a, ans, r, k;
	vector<vector<int>> q;
	vector<pii> p;
	void init_(int _n, int _m) {
		n = _n, m = _m;
		a.assign(n + 1, 0);
		ans.assign(m + 1, 0);
		r.assign(m + 1, 0);
		k.assign(m + 1, 0);
		q.assign(n + 1, vector<int>());
		p.clear();
		bit::init_(n);
	}
	void solve() {
		vector<int> s;
		rep(i, 1, n) {
			while(s.size() && a[s.back()] <= a[i]) s.pop_back();
			if(s.size()) p.push_back({s.back(), i});
			s.push_back(i);
		}
		sort(all(p));
		int ii = signed(p.size()) - 1;
		rrep(i, 1, n) {
			while(ii >= 0 && p[ii].first >= i) {
				int L = p[ii].first, R = p[ii].second;
				bit::modify(R, a[L] + a[R]);
				ii--;
			}
			for(auto j : q[i]) {
				ans[j] = bit::query(r[j]) <= k[j];
			}
		}
		rep(i, 1 ,m) cout << ans[i] << "\n"; 
	}
};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m;
	cin >> n >> m;
	init_(n, m);
	rep(i, 1, n) cin >> a[i];
	rep(i, 1, m) {
		int l; cin >> l;
		cin >> r[i] >> k[i];
		q[l].push_back(i);
	}
	solve();
	return 0;
}  

Compilation message

sortbooks.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      |
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 456 KB Output is correct
12 Correct 3 ms 716 KB Output is correct
13 Correct 3 ms 716 KB Output is correct
14 Correct 5 ms 836 KB Output is correct
15 Correct 4 ms 844 KB Output is correct
16 Correct 4 ms 712 KB Output is correct
17 Correct 3 ms 580 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1263 ms 71500 KB Output is correct
2 Correct 1346 ms 71508 KB Output is correct
3 Correct 1265 ms 71564 KB Output is correct
4 Correct 1211 ms 71560 KB Output is correct
5 Correct 1134 ms 63632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 9668 KB Output is correct
2 Correct 85 ms 8676 KB Output is correct
3 Correct 84 ms 8428 KB Output is correct
4 Correct 83 ms 8696 KB Output is correct
5 Correct 97 ms 8708 KB Output is correct
6 Correct 76 ms 7324 KB Output is correct
7 Correct 59 ms 7388 KB Output is correct
8 Correct 64 ms 8696 KB Output is correct
9 Correct 40 ms 3420 KB Output is correct
10 Correct 65 ms 8256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 456 KB Output is correct
12 Correct 3 ms 716 KB Output is correct
13 Correct 3 ms 716 KB Output is correct
14 Correct 5 ms 836 KB Output is correct
15 Correct 4 ms 844 KB Output is correct
16 Correct 4 ms 712 KB Output is correct
17 Correct 3 ms 580 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
19 Correct 218 ms 21640 KB Output is correct
20 Correct 258 ms 21564 KB Output is correct
21 Correct 181 ms 19092 KB Output is correct
22 Correct 180 ms 19148 KB Output is correct
23 Correct 208 ms 19128 KB Output is correct
24 Correct 143 ms 17120 KB Output is correct
25 Correct 148 ms 17104 KB Output is correct
26 Correct 178 ms 18140 KB Output is correct
27 Correct 152 ms 18144 KB Output is correct
28 Correct 197 ms 18612 KB Output is correct
29 Correct 278 ms 19864 KB Output is correct
30 Correct 194 ms 19860 KB Output is correct
31 Correct 193 ms 19908 KB Output is correct
32 Correct 194 ms 19708 KB Output is correct
33 Correct 182 ms 19792 KB Output is correct
34 Correct 132 ms 16604 KB Output is correct
35 Correct 135 ms 16664 KB Output is correct
36 Correct 132 ms 16452 KB Output is correct
37 Correct 152 ms 16504 KB Output is correct
38 Correct 133 ms 16668 KB Output is correct
39 Correct 159 ms 17684 KB Output is correct
40 Correct 135 ms 14420 KB Output is correct
41 Correct 163 ms 17632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 456 KB Output is correct
12 Correct 3 ms 716 KB Output is correct
13 Correct 3 ms 716 KB Output is correct
14 Correct 5 ms 836 KB Output is correct
15 Correct 4 ms 844 KB Output is correct
16 Correct 4 ms 712 KB Output is correct
17 Correct 3 ms 580 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
19 Correct 1263 ms 71500 KB Output is correct
20 Correct 1346 ms 71508 KB Output is correct
21 Correct 1265 ms 71564 KB Output is correct
22 Correct 1211 ms 71560 KB Output is correct
23 Correct 1134 ms 63632 KB Output is correct
24 Correct 91 ms 9668 KB Output is correct
25 Correct 85 ms 8676 KB Output is correct
26 Correct 84 ms 8428 KB Output is correct
27 Correct 83 ms 8696 KB Output is correct
28 Correct 97 ms 8708 KB Output is correct
29 Correct 76 ms 7324 KB Output is correct
30 Correct 59 ms 7388 KB Output is correct
31 Correct 64 ms 8696 KB Output is correct
32 Correct 40 ms 3420 KB Output is correct
33 Correct 65 ms 8256 KB Output is correct
34 Correct 218 ms 21640 KB Output is correct
35 Correct 258 ms 21564 KB Output is correct
36 Correct 181 ms 19092 KB Output is correct
37 Correct 180 ms 19148 KB Output is correct
38 Correct 208 ms 19128 KB Output is correct
39 Correct 143 ms 17120 KB Output is correct
40 Correct 148 ms 17104 KB Output is correct
41 Correct 178 ms 18140 KB Output is correct
42 Correct 152 ms 18144 KB Output is correct
43 Correct 197 ms 18612 KB Output is correct
44 Correct 278 ms 19864 KB Output is correct
45 Correct 194 ms 19860 KB Output is correct
46 Correct 193 ms 19908 KB Output is correct
47 Correct 194 ms 19708 KB Output is correct
48 Correct 182 ms 19792 KB Output is correct
49 Correct 132 ms 16604 KB Output is correct
50 Correct 135 ms 16664 KB Output is correct
51 Correct 132 ms 16452 KB Output is correct
52 Correct 152 ms 16504 KB Output is correct
53 Correct 133 ms 16668 KB Output is correct
54 Correct 159 ms 17684 KB Output is correct
55 Correct 135 ms 14420 KB Output is correct
56 Correct 163 ms 17632 KB Output is correct
57 Correct 1243 ms 73608 KB Output is correct
58 Correct 1271 ms 73532 KB Output is correct
59 Correct 1197 ms 68064 KB Output is correct
60 Correct 1226 ms 68092 KB Output is correct
61 Correct 1179 ms 68112 KB Output is correct
62 Correct 1194 ms 67908 KB Output is correct
63 Correct 760 ms 51268 KB Output is correct
64 Correct 746 ms 51216 KB Output is correct
65 Correct 1052 ms 59104 KB Output is correct
66 Correct 1059 ms 59044 KB Output is correct
67 Correct 1030 ms 59568 KB Output is correct
68 Correct 1099 ms 65608 KB Output is correct
69 Correct 1108 ms 65572 KB Output is correct
70 Correct 1108 ms 64488 KB Output is correct
71 Correct 1095 ms 64616 KB Output is correct
72 Correct 1108 ms 64472 KB Output is correct
73 Correct 692 ms 51160 KB Output is correct
74 Correct 732 ms 51096 KB Output is correct
75 Correct 730 ms 51072 KB Output is correct
76 Correct 718 ms 51160 KB Output is correct
77 Correct 695 ms 51284 KB Output is correct
78 Correct 946 ms 60568 KB Output is correct
79 Correct 739 ms 42912 KB Output is correct
80 Correct 959 ms 64416 KB Output is correct