Submission #170251

# Submission time Handle Problem Language Result Execution time Memory
170251 2019-12-24T11:14:42 Z Lightning Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1430 ms 87288 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int szT = (1 << 20) - 1;
const int INF = 1e9 + 5;

int n, m, a[szT], t[szT * 3];
vector <pair <int, pii> > que[szT];
stack <int> st;
bool ans[szT];

void upd(int pos, int x) {
	pos += szT;
	t[pos] = max(t[pos], x);
	while((pos /= 2) >= 1) {
		t[pos] = max(t[pos << 1], t[(pos << 1) ^ 1]);
	}
}

int get(int l, int r) {
	int res = 0;
	for(l += szT, r += szT; l <= r; l >>= 1, r >>= 1) {
		if(l & 1) res = max(res, t[l++]);
		if(!(r & 1)) res = max(res, t[r--]);
		if(l > r) break;
	}
	return res;
}

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];	
	}
	for(int i = 1; i <= m; ++i) {
		int l, r, k;
		cin >> l >> r >> k;
		que[r].pb(mkp(l, mkp(k, i)));
	}
	for(int i = 1; i <= n; ++i) {
		while(sz(st) && a[i] >= a[st.top()]) {
			st.pop();
		}
		if(sz(st)) {
			upd(st.top(), a[i] + a[st.top()]);
		} 
//		upd(i, a[i]);
		for(auto it : que[i]) {
			int l = it.F;
			int r = i;
			int k = it.S.F;
			int id = it.S.S;
			if(get(l, r) <= k) {
				ans[id] = 1;
			} else {
				ans[id] = 0;
			}
		}
		st.push(i);
	}
	for(int i = 1; i <= m; ++i) {
		cout << ans[i] <<'\n';
	}
	return 0;
}
/*
	If you only do what you can do, 
	You will never be more than you are now!
	-----------------------------------------	
	We must all suffer from one of two pains: 
	 the pain of discipline 
	 or the pain of regret. 
	The difference is discipline weighs grams 
	 while regret weighs tons.
*/
# Verdict Execution time Memory Grader output
1 Correct 25 ms 25080 KB Output is correct
2 Correct 25 ms 24952 KB Output is correct
3 Correct 25 ms 25084 KB Output is correct
4 Correct 25 ms 25080 KB Output is correct
5 Correct 24 ms 25080 KB Output is correct
6 Correct 25 ms 25080 KB Output is correct
7 Correct 25 ms 25080 KB Output is correct
8 Correct 25 ms 25080 KB Output is correct
9 Correct 25 ms 25084 KB Output is correct
10 Correct 25 ms 25080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 25080 KB Output is correct
2 Correct 25 ms 24952 KB Output is correct
3 Correct 25 ms 25084 KB Output is correct
4 Correct 25 ms 25080 KB Output is correct
5 Correct 24 ms 25080 KB Output is correct
6 Correct 25 ms 25080 KB Output is correct
7 Correct 25 ms 25080 KB Output is correct
8 Correct 25 ms 25080 KB Output is correct
9 Correct 25 ms 25084 KB Output is correct
10 Correct 25 ms 25080 KB Output is correct
11 Correct 27 ms 25208 KB Output is correct
12 Correct 28 ms 25336 KB Output is correct
13 Correct 28 ms 25340 KB Output is correct
14 Correct 29 ms 25336 KB Output is correct
15 Correct 29 ms 25464 KB Output is correct
16 Correct 28 ms 25336 KB Output is correct
17 Correct 28 ms 25336 KB Output is correct
18 Correct 28 ms 25336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1242 ms 62072 KB Output is correct
2 Correct 1300 ms 71900 KB Output is correct
3 Correct 1322 ms 71760 KB Output is correct
4 Correct 1297 ms 71800 KB Output is correct
5 Correct 1273 ms 64020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 29048 KB Output is correct
2 Correct 105 ms 30428 KB Output is correct
3 Correct 103 ms 29688 KB Output is correct
4 Correct 106 ms 29788 KB Output is correct
5 Correct 105 ms 29944 KB Output is correct
6 Correct 86 ms 29196 KB Output is correct
7 Correct 83 ms 29176 KB Output is correct
8 Correct 99 ms 29364 KB Output is correct
9 Correct 68 ms 28228 KB Output is correct
10 Correct 98 ms 29364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 25080 KB Output is correct
2 Correct 25 ms 24952 KB Output is correct
3 Correct 25 ms 25084 KB Output is correct
4 Correct 25 ms 25080 KB Output is correct
5 Correct 24 ms 25080 KB Output is correct
6 Correct 25 ms 25080 KB Output is correct
7 Correct 25 ms 25080 KB Output is correct
8 Correct 25 ms 25080 KB Output is correct
9 Correct 25 ms 25084 KB Output is correct
10 Correct 25 ms 25080 KB Output is correct
11 Correct 27 ms 25208 KB Output is correct
12 Correct 28 ms 25336 KB Output is correct
13 Correct 28 ms 25340 KB Output is correct
14 Correct 29 ms 25336 KB Output is correct
15 Correct 29 ms 25464 KB Output is correct
16 Correct 28 ms 25336 KB Output is correct
17 Correct 28 ms 25336 KB Output is correct
18 Correct 28 ms 25336 KB Output is correct
19 Correct 246 ms 38868 KB Output is correct
20 Correct 248 ms 38904 KB Output is correct
21 Correct 215 ms 38300 KB Output is correct
22 Correct 209 ms 38232 KB Output is correct
23 Correct 207 ms 38136 KB Output is correct
24 Correct 182 ms 36472 KB Output is correct
25 Correct 183 ms 36416 KB Output is correct
26 Correct 203 ms 36800 KB Output is correct
27 Correct 207 ms 36892 KB Output is correct
28 Correct 222 ms 36784 KB Output is correct
29 Correct 226 ms 37236 KB Output is correct
30 Correct 226 ms 37328 KB Output is correct
31 Correct 229 ms 37240 KB Output is correct
32 Correct 223 ms 37240 KB Output is correct
33 Correct 229 ms 37164 KB Output is correct
34 Correct 166 ms 36260 KB Output is correct
35 Correct 166 ms 35960 KB Output is correct
36 Correct 166 ms 35788 KB Output is correct
37 Correct 172 ms 35876 KB Output is correct
38 Correct 166 ms 35912 KB Output is correct
39 Correct 204 ms 35968 KB Output is correct
40 Correct 173 ms 34240 KB Output is correct
41 Correct 199 ms 35140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 25080 KB Output is correct
2 Correct 25 ms 24952 KB Output is correct
3 Correct 25 ms 25084 KB Output is correct
4 Correct 25 ms 25080 KB Output is correct
5 Correct 24 ms 25080 KB Output is correct
6 Correct 25 ms 25080 KB Output is correct
7 Correct 25 ms 25080 KB Output is correct
8 Correct 25 ms 25080 KB Output is correct
9 Correct 25 ms 25084 KB Output is correct
10 Correct 25 ms 25080 KB Output is correct
11 Correct 27 ms 25208 KB Output is correct
12 Correct 28 ms 25336 KB Output is correct
13 Correct 28 ms 25340 KB Output is correct
14 Correct 29 ms 25336 KB Output is correct
15 Correct 29 ms 25464 KB Output is correct
16 Correct 28 ms 25336 KB Output is correct
17 Correct 28 ms 25336 KB Output is correct
18 Correct 28 ms 25336 KB Output is correct
19 Correct 1242 ms 62072 KB Output is correct
20 Correct 1300 ms 71900 KB Output is correct
21 Correct 1322 ms 71760 KB Output is correct
22 Correct 1297 ms 71800 KB Output is correct
23 Correct 1273 ms 64020 KB Output is correct
24 Correct 114 ms 29048 KB Output is correct
25 Correct 105 ms 30428 KB Output is correct
26 Correct 103 ms 29688 KB Output is correct
27 Correct 106 ms 29788 KB Output is correct
28 Correct 105 ms 29944 KB Output is correct
29 Correct 86 ms 29196 KB Output is correct
30 Correct 83 ms 29176 KB Output is correct
31 Correct 99 ms 29364 KB Output is correct
32 Correct 68 ms 28228 KB Output is correct
33 Correct 98 ms 29364 KB Output is correct
34 Correct 246 ms 38868 KB Output is correct
35 Correct 248 ms 38904 KB Output is correct
36 Correct 215 ms 38300 KB Output is correct
37 Correct 209 ms 38232 KB Output is correct
38 Correct 207 ms 38136 KB Output is correct
39 Correct 182 ms 36472 KB Output is correct
40 Correct 183 ms 36416 KB Output is correct
41 Correct 203 ms 36800 KB Output is correct
42 Correct 207 ms 36892 KB Output is correct
43 Correct 222 ms 36784 KB Output is correct
44 Correct 226 ms 37236 KB Output is correct
45 Correct 226 ms 37328 KB Output is correct
46 Correct 229 ms 37240 KB Output is correct
47 Correct 223 ms 37240 KB Output is correct
48 Correct 229 ms 37164 KB Output is correct
49 Correct 166 ms 36260 KB Output is correct
50 Correct 166 ms 35960 KB Output is correct
51 Correct 166 ms 35788 KB Output is correct
52 Correct 172 ms 35876 KB Output is correct
53 Correct 166 ms 35912 KB Output is correct
54 Correct 204 ms 35968 KB Output is correct
55 Correct 173 ms 34240 KB Output is correct
56 Correct 199 ms 35140 KB Output is correct
57 Correct 1246 ms 71460 KB Output is correct
58 Correct 1251 ms 86732 KB Output is correct
59 Correct 1190 ms 87288 KB Output is correct
60 Correct 1222 ms 82096 KB Output is correct
61 Correct 1187 ms 79256 KB Output is correct
62 Correct 1430 ms 73604 KB Output is correct
63 Correct 836 ms 59640 KB Output is correct
64 Correct 814 ms 64240 KB Output is correct
65 Correct 1104 ms 65268 KB Output is correct
66 Correct 1100 ms 67904 KB Output is correct
67 Correct 1099 ms 66296 KB Output is correct
68 Correct 1164 ms 68856 KB Output is correct
69 Correct 1140 ms 65920 KB Output is correct
70 Correct 1195 ms 64164 KB Output is correct
71 Correct 1145 ms 69312 KB Output is correct
72 Correct 1146 ms 78704 KB Output is correct
73 Correct 726 ms 68536 KB Output is correct
74 Correct 731 ms 66036 KB Output is correct
75 Correct 725 ms 68460 KB Output is correct
76 Correct 722 ms 59292 KB Output is correct
77 Correct 725 ms 64512 KB Output is correct
78 Correct 1034 ms 75004 KB Output is correct
79 Correct 810 ms 62508 KB Output is correct
80 Correct 989 ms 67588 KB Output is correct