Submission #1096303

# Submission time Handle Problem Language Result Execution time Memory
1096303 2024-10-04T08:56:44 Z Muhammet Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
2387 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(s) (int)s.size()
#define ff first
#define ss second
#define ll long long

const int N = 1e6 + 5;

int n, m, a[N], mmx;

ll b[N*4], x3;

vector <vector <int>> st;

void bld(int nd, int l, int r){
	if(l == r){
		st[nd].push_back(a[l]);
		return;
	}
	int md = (l + r) / 2;
	bld(nd*2,l,md);
	bld(nd*2+1,md+1,r);
	st[nd].resize(sz(st[nd*2]) + sz(st[nd*2+1]));
	merge(st[nd*2].begin(), st[nd*2].end(), st[nd*2+1].begin(), st[nd*2+1].end(), st[nd].begin());
	int mx = 0;
	for(int i = l; i <= r; i++){
		x3 = mx;
		x3 += a[i];
		if(mx > a[i]) b[nd] = max(b[nd],x3);
		mx = max(mx,a[i]);
	}
	return;
}

ll fnd(int nd, int l, int r, int x, int y){
	if(r < x or l > y) return 0;
	if(l >= x and r <= y){
		int t = lower_bound(st[nd].begin(), st[nd].end(), mmx) - st[nd].begin();
		ll k = 0;
		if(t != 0) k = (mmx + st[nd][t-1]);
		k = max(k,b[nd]);
		mmx = max(mmx,st[nd].back());
		return k;
	}
	int md = (l + r) / 2;
	ll x1 = fnd(nd*2,l,md,x,y);
	ll x2 = fnd(nd*2+1,md+1,r,x,y);
	return max(x1,x2);
}

int main(){
	ios::sync_with_stdio (false); cin.tie(nullptr);
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	st.resize(n*4);
	bld(1,1,n);
	int l, r;
	ll k;
	for(int i = 1; i <= m; i++){
		cin >> l >> r >> k;
		mmx = 0;
		cout << (fnd(1,1,n,l,r) > k ? 0 : 1) << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2524 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2524 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 3 ms 2652 KB Output is correct
12 Correct 4 ms 3420 KB Output is correct
13 Correct 4 ms 3420 KB Output is correct
14 Correct 5 ms 3676 KB Output is correct
15 Correct 5 ms 3700 KB Output is correct
16 Correct 6 ms 3648 KB Output is correct
17 Correct 3 ms 3420 KB Output is correct
18 Correct 3 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2264 ms 262144 KB Output is correct
2 Correct 2172 ms 262144 KB Output is correct
3 Correct 2354 ms 262144 KB Output is correct
4 Correct 2387 ms 262144 KB Output is correct
5 Correct 1906 ms 262144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 26572 KB Output is correct
2 Correct 114 ms 26500 KB Output is correct
3 Correct 112 ms 25428 KB Output is correct
4 Correct 108 ms 25424 KB Output is correct
5 Correct 104 ms 25424 KB Output is correct
6 Correct 88 ms 25320 KB Output is correct
7 Correct 86 ms 25224 KB Output is correct
8 Correct 88 ms 25168 KB Output is correct
9 Correct 37 ms 3932 KB Output is correct
10 Correct 83 ms 25172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2524 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 3 ms 2652 KB Output is correct
12 Correct 4 ms 3420 KB Output is correct
13 Correct 4 ms 3420 KB Output is correct
14 Correct 5 ms 3676 KB Output is correct
15 Correct 5 ms 3700 KB Output is correct
16 Correct 6 ms 3648 KB Output is correct
17 Correct 3 ms 3420 KB Output is correct
18 Correct 3 ms 3420 KB Output is correct
19 Correct 321 ms 54064 KB Output is correct
20 Correct 330 ms 54060 KB Output is correct
21 Correct 277 ms 53708 KB Output is correct
22 Correct 258 ms 53824 KB Output is correct
23 Correct 259 ms 53884 KB Output is correct
24 Correct 208 ms 51540 KB Output is correct
25 Correct 206 ms 51540 KB Output is correct
26 Correct 248 ms 51796 KB Output is correct
27 Correct 267 ms 51900 KB Output is correct
28 Correct 308 ms 51800 KB Output is correct
29 Correct 260 ms 52044 KB Output is correct
30 Correct 278 ms 51992 KB Output is correct
31 Correct 257 ms 52052 KB Output is correct
32 Correct 243 ms 52048 KB Output is correct
33 Correct 272 ms 51856 KB Output is correct
34 Correct 212 ms 51540 KB Output is correct
35 Correct 202 ms 51800 KB Output is correct
36 Correct 188 ms 51280 KB Output is correct
37 Correct 200 ms 51284 KB Output is correct
38 Correct 204 ms 51432 KB Output is correct
39 Correct 232 ms 51280 KB Output is correct
40 Correct 142 ms 34896 KB Output is correct
41 Correct 226 ms 50068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2524 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 3 ms 2652 KB Output is correct
12 Correct 4 ms 3420 KB Output is correct
13 Correct 4 ms 3420 KB Output is correct
14 Correct 5 ms 3676 KB Output is correct
15 Correct 5 ms 3700 KB Output is correct
16 Correct 6 ms 3648 KB Output is correct
17 Correct 3 ms 3420 KB Output is correct
18 Correct 3 ms 3420 KB Output is correct
19 Correct 2264 ms 262144 KB Output is correct
20 Correct 2172 ms 262144 KB Output is correct
21 Correct 2354 ms 262144 KB Output is correct
22 Correct 2387 ms 262144 KB Output is correct
23 Correct 1906 ms 262144 KB Output is correct
24 Correct 129 ms 26572 KB Output is correct
25 Correct 114 ms 26500 KB Output is correct
26 Correct 112 ms 25428 KB Output is correct
27 Correct 108 ms 25424 KB Output is correct
28 Correct 104 ms 25424 KB Output is correct
29 Correct 88 ms 25320 KB Output is correct
30 Correct 86 ms 25224 KB Output is correct
31 Correct 88 ms 25168 KB Output is correct
32 Correct 37 ms 3932 KB Output is correct
33 Correct 83 ms 25172 KB Output is correct
34 Correct 321 ms 54064 KB Output is correct
35 Correct 330 ms 54060 KB Output is correct
36 Correct 277 ms 53708 KB Output is correct
37 Correct 258 ms 53824 KB Output is correct
38 Correct 259 ms 53884 KB Output is correct
39 Correct 208 ms 51540 KB Output is correct
40 Correct 206 ms 51540 KB Output is correct
41 Correct 248 ms 51796 KB Output is correct
42 Correct 267 ms 51900 KB Output is correct
43 Correct 308 ms 51800 KB Output is correct
44 Correct 260 ms 52044 KB Output is correct
45 Correct 278 ms 51992 KB Output is correct
46 Correct 257 ms 52052 KB Output is correct
47 Correct 243 ms 52048 KB Output is correct
48 Correct 272 ms 51856 KB Output is correct
49 Correct 212 ms 51540 KB Output is correct
50 Correct 202 ms 51800 KB Output is correct
51 Correct 188 ms 51280 KB Output is correct
52 Correct 200 ms 51284 KB Output is correct
53 Correct 204 ms 51432 KB Output is correct
54 Correct 232 ms 51280 KB Output is correct
55 Correct 142 ms 34896 KB Output is correct
56 Correct 226 ms 50068 KB Output is correct
57 Correct 2291 ms 262144 KB Output is correct
58 Correct 2288 ms 262144 KB Output is correct
59 Correct 2154 ms 262144 KB Output is correct
60 Correct 2286 ms 262144 KB Output is correct
61 Correct 2153 ms 262144 KB Output is correct
62 Correct 2181 ms 262144 KB Output is correct
63 Correct 1168 ms 261500 KB Output is correct
64 Correct 1201 ms 261528 KB Output is correct
65 Correct 1926 ms 262144 KB Output is correct
66 Correct 1906 ms 262144 KB Output is correct
67 Correct 1913 ms 262144 KB Output is correct
68 Correct 1970 ms 262144 KB Output is correct
69 Correct 1999 ms 262144 KB Output is correct
70 Correct 1981 ms 262144 KB Output is correct
71 Correct 1885 ms 262144 KB Output is correct
72 Correct 1943 ms 262144 KB Output is correct
73 Correct 1094 ms 259664 KB Output is correct
74 Correct 1145 ms 260856 KB Output is correct
75 Correct 1071 ms 259440 KB Output is correct
76 Correct 1101 ms 259664 KB Output is correct
77 Correct 1068 ms 259412 KB Output is correct
78 Correct 1528 ms 259648 KB Output is correct
79 Correct 886 ms 141908 KB Output is correct
80 Correct 1547 ms 254032 KB Output is correct