Submission #503256

# Submission time Handle Problem Language Result Execution time Memory
503256 2022-01-07T15:02:47 Z keta_tsimakuridze Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2005 ms 91792 KB
#include<bits/stdc++.h>
//#define int long long
#define f first
#define s second
#define pii pair<int,int>
using namespace std;
const int N = 1e6 + 5, mod = 1e9 + 7; // !
int t, a[N], tree[4 * N], lazy[4 * N], n, m;
vector<pair<pii,int> > q[N];
void push(int u,int l,int r) {
	tree[u] += lazy[u];
	if(l != r) {
		lazy[2 * u] += lazy[u];
		lazy[2 * u + 1] += lazy[u];
	}
	lazy[u] = 0;
}
void upd(int u,int st, int en, int l,int r,int val) {
	push(u, l, r);
	if(l > en || r < st) return;
	if(st <= l && r <= en) {
		lazy[u] = val; push(u, l, r);
		return;
	}
	int mid = (l + r) / 2;
	upd(2 * u, st, en, l, mid, val); upd(2 * u + 1, st, en, mid + 1, r, val);
	tree[u] = max(tree[2 * u], tree[2 * u + 1]); 
}
int get(int u,int st,int en,int l,int r) {
	push(u, l, r);
	if(l > en || r < st) return 0;
	if(st <= l && r <= en) return tree[u];
	int mid = (l + r) / 2;
	return max(get(2 * u, st, en, l, mid), get(2 * u + 1, st, en, mid + 1, r));
}
main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	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;
		q[l].push_back({{r, k}, i});
	}
	stack<pair<pii, pii> > st;
	vector<int> ans(m + 5);
	for(int i = n; i >= 1; i--) {
		int r = i;
		while(st.size() && st.top().f.f < a[i]) {
			r = st.top().s.s;
			if(st.top().f.s == -1) upd(1, st.top().s.f, st.top().s.s, 1, n, st.top().f.f + a[i]);
			else 
			upd(1, st.top().s.f, st.top().s.s, 1, n, - st.top().f.s + a[i]);
			st.pop();
		}
		if(r > i)
		st.push({{a[i], a[i]}, {i + 1, r}});
		st.push({{a[i], -1}, {i, i}});
		for(int j = 0; j < q[i].size(); j++) {
			ans[q[i][j].s] = (get(1,i,q[i][j].f.f,1,n) <= q[i][j].f.s);
		}
	}
	for(int i = 1; i <= m; i++) cout << ans[i] <<" ";
	
}

Compilation message

sortbooks.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main(){
      | ^~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for(int j = 0; j < q[i].size(); j++) {
      |                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23884 KB Output is correct
2 Correct 13 ms 23748 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23808 KB Output is correct
5 Correct 12 ms 23804 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 13 ms 23812 KB Output is correct
8 Correct 13 ms 23804 KB Output is correct
9 Correct 13 ms 23824 KB Output is correct
10 Correct 12 ms 23748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23884 KB Output is correct
2 Correct 13 ms 23748 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23808 KB Output is correct
5 Correct 12 ms 23804 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 13 ms 23812 KB Output is correct
8 Correct 13 ms 23804 KB Output is correct
9 Correct 13 ms 23824 KB Output is correct
10 Correct 12 ms 23748 KB Output is correct
11 Correct 15 ms 23896 KB Output is correct
12 Correct 18 ms 24036 KB Output is correct
13 Correct 16 ms 23980 KB Output is correct
14 Correct 18 ms 24076 KB Output is correct
15 Correct 18 ms 24132 KB Output is correct
16 Correct 16 ms 24196 KB Output is correct
17 Correct 15 ms 24096 KB Output is correct
18 Correct 16 ms 24076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1858 ms 72100 KB Output is correct
2 Correct 1852 ms 72492 KB Output is correct
3 Correct 1929 ms 72764 KB Output is correct
4 Correct 1861 ms 72512 KB Output is correct
5 Correct 1482 ms 91064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 29168 KB Output is correct
2 Correct 147 ms 28996 KB Output is correct
3 Correct 99 ms 30664 KB Output is correct
4 Correct 102 ms 30660 KB Output is correct
5 Correct 102 ms 30744 KB Output is correct
6 Correct 91 ms 28236 KB Output is correct
7 Correct 93 ms 28284 KB Output is correct
8 Correct 98 ms 29368 KB Output is correct
9 Correct 56 ms 25984 KB Output is correct
10 Correct 98 ms 29532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23884 KB Output is correct
2 Correct 13 ms 23748 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23808 KB Output is correct
5 Correct 12 ms 23804 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 13 ms 23812 KB Output is correct
8 Correct 13 ms 23804 KB Output is correct
9 Correct 13 ms 23824 KB Output is correct
10 Correct 12 ms 23748 KB Output is correct
11 Correct 15 ms 23896 KB Output is correct
12 Correct 18 ms 24036 KB Output is correct
13 Correct 16 ms 23980 KB Output is correct
14 Correct 18 ms 24076 KB Output is correct
15 Correct 18 ms 24132 KB Output is correct
16 Correct 16 ms 24196 KB Output is correct
17 Correct 15 ms 24096 KB Output is correct
18 Correct 16 ms 24076 KB Output is correct
19 Correct 317 ms 34540 KB Output is correct
20 Correct 308 ms 34500 KB Output is correct
21 Correct 321 ms 34308 KB Output is correct
22 Correct 283 ms 34064 KB Output is correct
23 Correct 287 ms 34096 KB Output is correct
24 Correct 204 ms 33792 KB Output is correct
25 Correct 196 ms 33660 KB Output is correct
26 Correct 217 ms 36268 KB Output is correct
27 Correct 215 ms 36200 KB Output is correct
28 Correct 221 ms 37500 KB Output is correct
29 Correct 230 ms 37908 KB Output is correct
30 Correct 238 ms 37764 KB Output is correct
31 Correct 234 ms 37740 KB Output is correct
32 Correct 247 ms 37736 KB Output is correct
33 Correct 232 ms 37768 KB Output is correct
34 Correct 193 ms 32528 KB Output is correct
35 Correct 184 ms 32532 KB Output is correct
36 Correct 238 ms 32720 KB Output is correct
37 Correct 178 ms 32580 KB Output is correct
38 Correct 189 ms 32544 KB Output is correct
39 Correct 218 ms 36040 KB Output is correct
40 Correct 148 ms 32700 KB Output is correct
41 Correct 229 ms 35096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23884 KB Output is correct
2 Correct 13 ms 23748 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23808 KB Output is correct
5 Correct 12 ms 23804 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 13 ms 23812 KB Output is correct
8 Correct 13 ms 23804 KB Output is correct
9 Correct 13 ms 23824 KB Output is correct
10 Correct 12 ms 23748 KB Output is correct
11 Correct 15 ms 23896 KB Output is correct
12 Correct 18 ms 24036 KB Output is correct
13 Correct 16 ms 23980 KB Output is correct
14 Correct 18 ms 24076 KB Output is correct
15 Correct 18 ms 24132 KB Output is correct
16 Correct 16 ms 24196 KB Output is correct
17 Correct 15 ms 24096 KB Output is correct
18 Correct 16 ms 24076 KB Output is correct
19 Correct 1858 ms 72100 KB Output is correct
20 Correct 1852 ms 72492 KB Output is correct
21 Correct 1929 ms 72764 KB Output is correct
22 Correct 1861 ms 72512 KB Output is correct
23 Correct 1482 ms 91064 KB Output is correct
24 Correct 140 ms 29168 KB Output is correct
25 Correct 147 ms 28996 KB Output is correct
26 Correct 99 ms 30664 KB Output is correct
27 Correct 102 ms 30660 KB Output is correct
28 Correct 102 ms 30744 KB Output is correct
29 Correct 91 ms 28236 KB Output is correct
30 Correct 93 ms 28284 KB Output is correct
31 Correct 98 ms 29368 KB Output is correct
32 Correct 56 ms 25984 KB Output is correct
33 Correct 98 ms 29532 KB Output is correct
34 Correct 317 ms 34540 KB Output is correct
35 Correct 308 ms 34500 KB Output is correct
36 Correct 321 ms 34308 KB Output is correct
37 Correct 283 ms 34064 KB Output is correct
38 Correct 287 ms 34096 KB Output is correct
39 Correct 204 ms 33792 KB Output is correct
40 Correct 196 ms 33660 KB Output is correct
41 Correct 217 ms 36268 KB Output is correct
42 Correct 215 ms 36200 KB Output is correct
43 Correct 221 ms 37500 KB Output is correct
44 Correct 230 ms 37908 KB Output is correct
45 Correct 238 ms 37764 KB Output is correct
46 Correct 234 ms 37740 KB Output is correct
47 Correct 247 ms 37736 KB Output is correct
48 Correct 232 ms 37768 KB Output is correct
49 Correct 193 ms 32528 KB Output is correct
50 Correct 184 ms 32532 KB Output is correct
51 Correct 238 ms 32720 KB Output is correct
52 Correct 178 ms 32580 KB Output is correct
53 Correct 189 ms 32544 KB Output is correct
54 Correct 218 ms 36040 KB Output is correct
55 Correct 148 ms 32700 KB Output is correct
56 Correct 229 ms 35096 KB Output is correct
57 Correct 2005 ms 75704 KB Output is correct
58 Correct 1856 ms 75692 KB Output is correct
59 Correct 1798 ms 73080 KB Output is correct
60 Correct 1789 ms 72996 KB Output is correct
61 Correct 1836 ms 73196 KB Output is correct
62 Correct 1800 ms 72464 KB Output is correct
63 Correct 957 ms 67988 KB Output is correct
64 Correct 979 ms 68100 KB Output is correct
65 Correct 1342 ms 87676 KB Output is correct
66 Correct 1379 ms 89776 KB Output is correct
67 Correct 1418 ms 88748 KB Output is correct
68 Correct 1416 ms 91148 KB Output is correct
69 Correct 1396 ms 91792 KB Output is correct
70 Correct 1346 ms 90744 KB Output is correct
71 Correct 1359 ms 90760 KB Output is correct
72 Correct 1362 ms 91452 KB Output is correct
73 Correct 892 ms 66040 KB Output is correct
74 Correct 948 ms 66800 KB Output is correct
75 Correct 1008 ms 67008 KB Output is correct
76 Correct 1022 ms 64624 KB Output is correct
77 Correct 895 ms 66508 KB Output is correct
78 Correct 1234 ms 82980 KB Output is correct
79 Correct 789 ms 65384 KB Output is correct
80 Correct 1232 ms 79764 KB Output is correct