Submission #1008937

# Submission time Handle Problem Language Result Execution time Memory
1008937 2024-06-27T05:58:12 Z ByeWorld Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1554 ms 174892 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
#define ll long long
// #define int long long
#define pb push_back
#define fi first
#define se second
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
#define ld long double
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii, int> ipii;
const int MAXN = 1e6+10;
const int INF = 1e9+10;
const int LOG = 20;
const int MOD = 1e9+7;
const int SQRT = 450;
const vector<int> NOL = {};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const vector<int> dx = {1, -1, 0, 0};
const vector<int> dy = {0, 0, 1, -1};

int n, m, q;
int a[MAXN];

struct seg {
	int st[4*MAXN];
	int mrg(int x, int y){
		return max(x, y);
	}
	void bd(int id, int l, int r){
		if(l==r){ st[id] = -INF; return; }
		bd(lf, l, md); bd(rg, md+1, r);
		st[id] = -INF; 
	}
	int que(int id, int l, int r, int x, int y){
		if(x<=l && r<=y) return st[id];
		if(r<x || y<l) return -INF;
		return mrg(que(lf, l, md, x, y), que(rg, md+1, r, x, y));
	}
	int upd(int id, int l, int r, int x, int p){
		if(r<x || x<l) return st[id];
		if(l==r && l==x) return st[id] = p;
		return st[id] = mrg(upd(lf,l,md,x,p), upd(rg,md+1,r,x,p));
	}
} A;

int sp[MAXN][LOG+5];
vector <ipii> que;
vector <int> vec;
int QUE(int l, int r){
	if(l > r) return -INF;
	int lg = log2(r-l+1);
	return max(sp[l][lg], sp[r-(1<<lg)+1][lg]);
}
int k[MAXN], ans[MAXN];
signed main(){
	// ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	for(int i=n; i>=1; i--){
		cin >> a[i];
		sp[i][0] = a[i];
	}
	for(int j=1; j<LOG; j++) 
		for(int i=1; i<=n; i++)
			if(i+(1<<j)-1 <= n) sp[i][j] = max(sp[i][j-1], sp[i+(1<<(j-1))][j-1]);
	A.bd(1, 1, n);

	for(int i=1; i<=m; i++){
		int l, r; cin >> l >> r >> k[i];
		l = n-l+1; r = n-r+1;
		que.pb({{l, r}, i});
	}
	sort(que.begin(), que.end());
	vec.pb(0); a[0] = INF; int las = 0;
	for(auto [rl, idx] : que){
		int L = rl.se, R = rl.fi;
		while(las < R){
			++las;
			while(a[vec.back()] < a[las]){
				A.upd(1, 1, n, (int)vec.size()-1, -INF); 
				vec.pop_back();
			}
			int ba = vec.back();
			vec.pb(las);
			A.upd(1, 1, n, (int)vec.size()-1, QUE(ba+1, las-1) + a[las]);
			//lasnya kasi value ini, max in
		}
		// cout << L << ' ' << R << "LR\n";
		// for(auto in : vec) cout << in << ' ';
		// cout << " stac\n";
		// for(int i=1; i<=5; i++){
		// 	cout << i << ' ' << A.que(1, 1, n, i, i) << " i\n";
		// }

		int l=1, r=(int)vec.size()-1, mid=0, cnt=0;
		while(l<=r){
			mid = md;
			if(L <= vec[mid]){
				cnt = mid; r = mid-1;
 			} else l = mid+1;
		}
		// cout << cnt << " cnt\n";
		int ret = A.que(1, 1, n, cnt+1, (int)vec.size()-1);
		// cout << ret << " ret\n";
		ret = max(ret, QUE(L, vec[cnt]-1) + a[vec[cnt]]);
		// cout << QUE(L, vec[cnt]-1) << ' '<< a[vec[cnt]] << " que\n";
		ans[idx] = ret;
		// cout << "\n\n";
	}
	for(int i=1; i<=m; i++){
		// cout << i << ' ' << ans[i] << " ans\n";
		cout << (ans[i] <= k[i]) << '\n';
	}
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:78:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   78 |  for(auto [rl, idx] : que){
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 2 ms 8536 KB Output is correct
7 Correct 1 ms 8660 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 2 ms 8536 KB Output is correct
7 Correct 1 ms 8660 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 5 ms 8660 KB Output is correct
13 Correct 5 ms 8796 KB Output is correct
14 Correct 6 ms 8912 KB Output is correct
15 Correct 7 ms 8912 KB Output is correct
16 Correct 5 ms 8912 KB Output is correct
17 Correct 5 ms 8796 KB Output is correct
18 Correct 5 ms 8700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1351 ms 165236 KB Output is correct
2 Correct 1344 ms 166124 KB Output is correct
3 Correct 1417 ms 166016 KB Output is correct
4 Correct 1399 ms 166320 KB Output is correct
5 Correct 1554 ms 173996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 26428 KB Output is correct
2 Correct 103 ms 26560 KB Output is correct
3 Correct 128 ms 27332 KB Output is correct
4 Correct 111 ms 27332 KB Output is correct
5 Correct 113 ms 27332 KB Output is correct
6 Correct 99 ms 27056 KB Output is correct
7 Correct 101 ms 27072 KB Output is correct
8 Correct 101 ms 26568 KB Output is correct
9 Correct 64 ms 15552 KB Output is correct
10 Correct 105 ms 26560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 2 ms 8536 KB Output is correct
7 Correct 1 ms 8660 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 5 ms 8660 KB Output is correct
13 Correct 5 ms 8796 KB Output is correct
14 Correct 6 ms 8912 KB Output is correct
15 Correct 7 ms 8912 KB Output is correct
16 Correct 5 ms 8912 KB Output is correct
17 Correct 5 ms 8796 KB Output is correct
18 Correct 5 ms 8700 KB Output is correct
19 Correct 287 ms 45500 KB Output is correct
20 Correct 270 ms 44732 KB Output is correct
21 Correct 269 ms 44728 KB Output is correct
22 Correct 260 ms 44580 KB Output is correct
23 Correct 250 ms 44732 KB Output is correct
24 Correct 271 ms 46896 KB Output is correct
25 Correct 266 ms 46144 KB Output is correct
26 Correct 280 ms 46520 KB Output is correct
27 Correct 267 ms 46524 KB Output is correct
28 Correct 279 ms 46520 KB Output is correct
29 Correct 276 ms 46520 KB Output is correct
30 Correct 289 ms 46524 KB Output is correct
31 Correct 267 ms 46524 KB Output is correct
32 Correct 275 ms 46392 KB Output is correct
33 Correct 281 ms 46520 KB Output is correct
34 Correct 256 ms 46324 KB Output is correct
35 Correct 236 ms 46012 KB Output is correct
36 Correct 237 ms 46016 KB Output is correct
37 Correct 243 ms 45880 KB Output is correct
38 Correct 246 ms 46016 KB Output is correct
39 Correct 241 ms 44716 KB Output is correct
40 Correct 199 ms 33640 KB Output is correct
41 Correct 211 ms 43708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 2 ms 8536 KB Output is correct
7 Correct 1 ms 8660 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 5 ms 8660 KB Output is correct
13 Correct 5 ms 8796 KB Output is correct
14 Correct 6 ms 8912 KB Output is correct
15 Correct 7 ms 8912 KB Output is correct
16 Correct 5 ms 8912 KB Output is correct
17 Correct 5 ms 8796 KB Output is correct
18 Correct 5 ms 8700 KB Output is correct
19 Correct 1351 ms 165236 KB Output is correct
20 Correct 1344 ms 166124 KB Output is correct
21 Correct 1417 ms 166016 KB Output is correct
22 Correct 1399 ms 166320 KB Output is correct
23 Correct 1554 ms 173996 KB Output is correct
24 Correct 113 ms 26428 KB Output is correct
25 Correct 103 ms 26560 KB Output is correct
26 Correct 128 ms 27332 KB Output is correct
27 Correct 111 ms 27332 KB Output is correct
28 Correct 113 ms 27332 KB Output is correct
29 Correct 99 ms 27056 KB Output is correct
30 Correct 101 ms 27072 KB Output is correct
31 Correct 101 ms 26568 KB Output is correct
32 Correct 64 ms 15552 KB Output is correct
33 Correct 105 ms 26560 KB Output is correct
34 Correct 287 ms 45500 KB Output is correct
35 Correct 270 ms 44732 KB Output is correct
36 Correct 269 ms 44728 KB Output is correct
37 Correct 260 ms 44580 KB Output is correct
38 Correct 250 ms 44732 KB Output is correct
39 Correct 271 ms 46896 KB Output is correct
40 Correct 266 ms 46144 KB Output is correct
41 Correct 280 ms 46520 KB Output is correct
42 Correct 267 ms 46524 KB Output is correct
43 Correct 279 ms 46520 KB Output is correct
44 Correct 276 ms 46520 KB Output is correct
45 Correct 289 ms 46524 KB Output is correct
46 Correct 267 ms 46524 KB Output is correct
47 Correct 275 ms 46392 KB Output is correct
48 Correct 281 ms 46520 KB Output is correct
49 Correct 256 ms 46324 KB Output is correct
50 Correct 236 ms 46012 KB Output is correct
51 Correct 237 ms 46016 KB Output is correct
52 Correct 243 ms 45880 KB Output is correct
53 Correct 246 ms 46016 KB Output is correct
54 Correct 241 ms 44716 KB Output is correct
55 Correct 199 ms 33640 KB Output is correct
56 Correct 211 ms 43708 KB Output is correct
57 Correct 1368 ms 166984 KB Output is correct
58 Correct 1347 ms 166828 KB Output is correct
59 Correct 1298 ms 166788 KB Output is correct
60 Correct 1367 ms 166828 KB Output is correct
61 Correct 1344 ms 166832 KB Output is correct
62 Correct 1310 ms 166828 KB Output is correct
63 Correct 1223 ms 173232 KB Output is correct
64 Correct 1236 ms 172740 KB Output is correct
65 Correct 1346 ms 174768 KB Output is correct
66 Correct 1353 ms 174548 KB Output is correct
67 Correct 1378 ms 174788 KB Output is correct
68 Correct 1387 ms 174892 KB Output is correct
69 Correct 1436 ms 174644 KB Output is correct
70 Correct 1391 ms 174776 KB Output is correct
71 Correct 1435 ms 174764 KB Output is correct
72 Correct 1413 ms 174680 KB Output is correct
73 Correct 1154 ms 171180 KB Output is correct
74 Correct 1153 ms 172196 KB Output is correct
75 Correct 1137 ms 171424 KB Output is correct
76 Correct 1140 ms 171348 KB Output is correct
77 Correct 1154 ms 171172 KB Output is correct
78 Correct 1334 ms 167276 KB Output is correct
79 Correct 989 ms 108452 KB Output is correct
80 Correct 1164 ms 161848 KB Output is correct