Submission #348456

# Submission time Handle Problem Language Result Execution time Memory
348456 2021-01-15T03:11:14 Z Kevin_Zhang_TW Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1018 ms 61460 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif

const int MAX_N = 1000010, p = 1e9 + 7;

int n, m, w[MAX_N], mx[MAX_N], res[MAX_N], req[MAX_N];

void update(int i, int v) {
	i = n - i + 1;
	for (;i <= n;i += i&-i) 
		chmax(mx[i], v);
}
int qry(int i) {
	i = n - i + 1;
	int res = 0;
	for (;i;i ^= i&-i)
		chmax(res, mx[i]);
	return res;
}

int dq[MAX_N], dl;

vector<pair<int,int>> allq[MAX_N];

int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);

	cin >> n >> m;

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

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

	for (int i = 1;i <= n;++i) {

		while (dl && w[ dq[dl-1] ] <= w[i]) --dl;

		if (dl)
			update(dq[dl-1], w[i] + w[dq[dl-1]]);

		dq[dl++] = i;

		for (auto [l, id] : allq[i])
			res[id] = qry(l) <= req[id];
	}

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




}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23916 KB Output is correct
2 Correct 14 ms 23788 KB Output is correct
3 Correct 15 ms 23916 KB Output is correct
4 Correct 14 ms 23916 KB Output is correct
5 Correct 14 ms 23916 KB Output is correct
6 Correct 15 ms 23936 KB Output is correct
7 Correct 14 ms 23916 KB Output is correct
8 Correct 15 ms 23916 KB Output is correct
9 Correct 14 ms 23916 KB Output is correct
10 Correct 14 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23916 KB Output is correct
2 Correct 14 ms 23788 KB Output is correct
3 Correct 15 ms 23916 KB Output is correct
4 Correct 14 ms 23916 KB Output is correct
5 Correct 14 ms 23916 KB Output is correct
6 Correct 15 ms 23936 KB Output is correct
7 Correct 14 ms 23916 KB Output is correct
8 Correct 15 ms 23916 KB Output is correct
9 Correct 14 ms 23916 KB Output is correct
10 Correct 14 ms 23916 KB Output is correct
11 Correct 16 ms 23916 KB Output is correct
12 Correct 16 ms 24044 KB Output is correct
13 Correct 17 ms 24172 KB Output is correct
14 Correct 18 ms 24044 KB Output is correct
15 Correct 18 ms 24044 KB Output is correct
16 Correct 17 ms 24044 KB Output is correct
17 Correct 17 ms 24044 KB Output is correct
18 Correct 17 ms 24044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1010 ms 61360 KB Output is correct
2 Correct 1012 ms 61460 KB Output is correct
3 Correct 1010 ms 61296 KB Output is correct
4 Correct 1006 ms 61420 KB Output is correct
5 Correct 931 ms 57452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 27500 KB Output is correct
2 Correct 73 ms 27116 KB Output is correct
3 Correct 84 ms 26988 KB Output is correct
4 Correct 75 ms 27192 KB Output is correct
5 Correct 75 ms 27244 KB Output is correct
6 Correct 60 ms 26348 KB Output is correct
7 Correct 60 ms 26348 KB Output is correct
8 Correct 69 ms 26980 KB Output is correct
9 Correct 53 ms 25828 KB Output is correct
10 Correct 74 ms 27036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23916 KB Output is correct
2 Correct 14 ms 23788 KB Output is correct
3 Correct 15 ms 23916 KB Output is correct
4 Correct 14 ms 23916 KB Output is correct
5 Correct 14 ms 23916 KB Output is correct
6 Correct 15 ms 23936 KB Output is correct
7 Correct 14 ms 23916 KB Output is correct
8 Correct 15 ms 23916 KB Output is correct
9 Correct 14 ms 23916 KB Output is correct
10 Correct 14 ms 23916 KB Output is correct
11 Correct 16 ms 23916 KB Output is correct
12 Correct 16 ms 24044 KB Output is correct
13 Correct 17 ms 24172 KB Output is correct
14 Correct 18 ms 24044 KB Output is correct
15 Correct 18 ms 24044 KB Output is correct
16 Correct 17 ms 24044 KB Output is correct
17 Correct 17 ms 24044 KB Output is correct
18 Correct 17 ms 24044 KB Output is correct
19 Correct 177 ms 31084 KB Output is correct
20 Correct 177 ms 31212 KB Output is correct
21 Correct 150 ms 30060 KB Output is correct
22 Correct 146 ms 30060 KB Output is correct
23 Correct 147 ms 30060 KB Output is correct
24 Correct 138 ms 29164 KB Output is correct
25 Correct 135 ms 29164 KB Output is correct
26 Correct 149 ms 29676 KB Output is correct
27 Correct 155 ms 29676 KB Output is correct
28 Correct 155 ms 29804 KB Output is correct
29 Correct 166 ms 30316 KB Output is correct
30 Correct 167 ms 30480 KB Output is correct
31 Correct 164 ms 30316 KB Output is correct
32 Correct 164 ms 30168 KB Output is correct
33 Correct 167 ms 30316 KB Output is correct
34 Correct 128 ms 28908 KB Output is correct
35 Correct 128 ms 28908 KB Output is correct
36 Correct 127 ms 28908 KB Output is correct
37 Correct 124 ms 28900 KB Output is correct
38 Correct 127 ms 28908 KB Output is correct
39 Correct 150 ms 30308 KB Output is correct
40 Correct 132 ms 29536 KB Output is correct
41 Correct 150 ms 30048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23916 KB Output is correct
2 Correct 14 ms 23788 KB Output is correct
3 Correct 15 ms 23916 KB Output is correct
4 Correct 14 ms 23916 KB Output is correct
5 Correct 14 ms 23916 KB Output is correct
6 Correct 15 ms 23936 KB Output is correct
7 Correct 14 ms 23916 KB Output is correct
8 Correct 15 ms 23916 KB Output is correct
9 Correct 14 ms 23916 KB Output is correct
10 Correct 14 ms 23916 KB Output is correct
11 Correct 16 ms 23916 KB Output is correct
12 Correct 16 ms 24044 KB Output is correct
13 Correct 17 ms 24172 KB Output is correct
14 Correct 18 ms 24044 KB Output is correct
15 Correct 18 ms 24044 KB Output is correct
16 Correct 17 ms 24044 KB Output is correct
17 Correct 17 ms 24044 KB Output is correct
18 Correct 17 ms 24044 KB Output is correct
19 Correct 1010 ms 61360 KB Output is correct
20 Correct 1012 ms 61460 KB Output is correct
21 Correct 1010 ms 61296 KB Output is correct
22 Correct 1006 ms 61420 KB Output is correct
23 Correct 931 ms 57452 KB Output is correct
24 Correct 77 ms 27500 KB Output is correct
25 Correct 73 ms 27116 KB Output is correct
26 Correct 84 ms 26988 KB Output is correct
27 Correct 75 ms 27192 KB Output is correct
28 Correct 75 ms 27244 KB Output is correct
29 Correct 60 ms 26348 KB Output is correct
30 Correct 60 ms 26348 KB Output is correct
31 Correct 69 ms 26980 KB Output is correct
32 Correct 53 ms 25828 KB Output is correct
33 Correct 74 ms 27036 KB Output is correct
34 Correct 177 ms 31084 KB Output is correct
35 Correct 177 ms 31212 KB Output is correct
36 Correct 150 ms 30060 KB Output is correct
37 Correct 146 ms 30060 KB Output is correct
38 Correct 147 ms 30060 KB Output is correct
39 Correct 138 ms 29164 KB Output is correct
40 Correct 135 ms 29164 KB Output is correct
41 Correct 149 ms 29676 KB Output is correct
42 Correct 155 ms 29676 KB Output is correct
43 Correct 155 ms 29804 KB Output is correct
44 Correct 166 ms 30316 KB Output is correct
45 Correct 167 ms 30480 KB Output is correct
46 Correct 164 ms 30316 KB Output is correct
47 Correct 164 ms 30168 KB Output is correct
48 Correct 167 ms 30316 KB Output is correct
49 Correct 128 ms 28908 KB Output is correct
50 Correct 128 ms 28908 KB Output is correct
51 Correct 127 ms 28908 KB Output is correct
52 Correct 124 ms 28900 KB Output is correct
53 Correct 127 ms 28908 KB Output is correct
54 Correct 150 ms 30308 KB Output is correct
55 Correct 132 ms 29536 KB Output is correct
56 Correct 150 ms 30048 KB Output is correct
57 Correct 1018 ms 60268 KB Output is correct
58 Correct 1008 ms 60472 KB Output is correct
59 Correct 948 ms 57520 KB Output is correct
60 Correct 955 ms 57708 KB Output is correct
61 Correct 953 ms 57580 KB Output is correct
62 Correct 951 ms 57580 KB Output is correct
63 Correct 657 ms 50028 KB Output is correct
64 Correct 667 ms 50028 KB Output is correct
65 Correct 869 ms 53356 KB Output is correct
66 Correct 875 ms 53356 KB Output is correct
67 Correct 879 ms 53612 KB Output is correct
68 Correct 943 ms 56428 KB Output is correct
69 Correct 918 ms 56352 KB Output is correct
70 Correct 920 ms 56044 KB Output is correct
71 Correct 916 ms 56044 KB Output is correct
72 Correct 916 ms 56044 KB Output is correct
73 Correct 590 ms 48620 KB Output is correct
74 Correct 616 ms 48492 KB Output is correct
75 Correct 591 ms 48584 KB Output is correct
76 Correct 591 ms 48620 KB Output is correct
77 Correct 593 ms 48364 KB Output is correct
78 Correct 822 ms 55900 KB Output is correct
79 Correct 648 ms 50516 KB Output is correct
80 Correct 815 ms 54996 KB Output is correct