Submission #1005495

# Submission time Handle Problem Language Result Execution time Memory
1005495 2024-06-22T13:50:31 Z ByeWorld Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
34 / 100
520 ms 262144 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 = 29;
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 {
	set <int> st[4*MAXN]; int val[4*MAXN], mx[4*MAXN];
	void mrg(int id){
		for(auto in : st[lf]) st[id].insert(in);
		for(auto in : st[rg]) st[id].insert(in);
		val[id] = max(val[lf], val[rg]);

		int le = *(--st[lf].end());
		auto it = st[rg].lower_bound(le);
		if(it != st[rg].begin()){
			it--; 
			val[id] = max(val[id], le + *(it));
		}
		mx[id] = *(--st[id].end());
	}
	void bd(int id, int l, int r){
		if(l==r){ st[id].insert(a[l]); val[id] = -INF; mx[id] = a[l]; return; }
		bd(lf, l, md); bd(rg, md+1, r);
		mrg(id);
	}
	int que(int id, int l, int r, int x, int y){
		if(r<x || y<l) return -INF;
		if(x<=l && r<=y) return mx[id];
		return max(que(lf, l, md, x, y), que(rg, md+1, r, x, y));
	}
	int find(int id, int l, int r, int x, int y){
		if(r<x || y<l) return -INF;
		if(x<=l && r<=y){
			int bef = que(1, 1, n, x, l-1); // mx di sebelum
			int aft = -INF;
			auto it = st[id].lower_bound(bef);
			if(it != st[id].begin()){
				it--; 
				aft = *(it);
			}

			return max(val[id], bef+aft);
		}
		int MX = max(find(lf, l, md, x, y), find(rg, md+1, r, x, y));

		// int bef = que(1, 1, n, x, l-1), aft = -INF;
		// auto it = st[rg].lower_bound(bef);
		// if(it != st[rg].begin()){
		// 	it--; 
		// 	aft = *(it);
		// }
		return MX;
	}
} A;

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	for(int i=1; i<=n; i++) cin >> a[i];
	A.bd(1, 1, n);

	for(int xx=1; xx<=m; xx++){
		int l, r, x; cin >> l >> r >> x;
		cout << (A.find(1, 1, n, l, r) <= x) << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 29 ms 193400 KB Output is correct
2 Correct 27 ms 193360 KB Output is correct
3 Correct 25 ms 193372 KB Output is correct
4 Correct 25 ms 193452 KB Output is correct
5 Correct 27 ms 193372 KB Output is correct
6 Correct 30 ms 193584 KB Output is correct
7 Correct 33 ms 193628 KB Output is correct
8 Correct 31 ms 193624 KB Output is correct
9 Correct 27 ms 193432 KB Output is correct
10 Correct 28 ms 193372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 193400 KB Output is correct
2 Correct 27 ms 193360 KB Output is correct
3 Correct 25 ms 193372 KB Output is correct
4 Correct 25 ms 193452 KB Output is correct
5 Correct 27 ms 193372 KB Output is correct
6 Correct 30 ms 193584 KB Output is correct
7 Correct 33 ms 193628 KB Output is correct
8 Correct 31 ms 193624 KB Output is correct
9 Correct 27 ms 193432 KB Output is correct
10 Correct 28 ms 193372 KB Output is correct
11 Correct 38 ms 194408 KB Output is correct
12 Correct 38 ms 196436 KB Output is correct
13 Correct 41 ms 196520 KB Output is correct
14 Correct 43 ms 196700 KB Output is correct
15 Correct 46 ms 196788 KB Output is correct
16 Correct 40 ms 196592 KB Output is correct
17 Correct 35 ms 195932 KB Output is correct
18 Correct 33 ms 193884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 215 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 520 ms 248056 KB Output is correct
2 Correct 499 ms 247856 KB Output is correct
3 Correct 279 ms 205916 KB Output is correct
4 Correct 268 ms 205904 KB Output is correct
5 Correct 262 ms 205784 KB Output is correct
6 Correct 260 ms 205648 KB Output is correct
7 Correct 255 ms 205436 KB Output is correct
8 Correct 182 ms 204720 KB Output is correct
9 Correct 73 ms 195156 KB Output is correct
10 Correct 193 ms 204628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 193400 KB Output is correct
2 Correct 27 ms 193360 KB Output is correct
3 Correct 25 ms 193372 KB Output is correct
4 Correct 25 ms 193452 KB Output is correct
5 Correct 27 ms 193372 KB Output is correct
6 Correct 30 ms 193584 KB Output is correct
7 Correct 33 ms 193628 KB Output is correct
8 Correct 31 ms 193624 KB Output is correct
9 Correct 27 ms 193432 KB Output is correct
10 Correct 28 ms 193372 KB Output is correct
11 Correct 38 ms 194408 KB Output is correct
12 Correct 38 ms 196436 KB Output is correct
13 Correct 41 ms 196520 KB Output is correct
14 Correct 43 ms 196700 KB Output is correct
15 Correct 46 ms 196788 KB Output is correct
16 Correct 40 ms 196592 KB Output is correct
17 Correct 35 ms 195932 KB Output is correct
18 Correct 33 ms 193884 KB Output is correct
19 Runtime error 122 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 193400 KB Output is correct
2 Correct 27 ms 193360 KB Output is correct
3 Correct 25 ms 193372 KB Output is correct
4 Correct 25 ms 193452 KB Output is correct
5 Correct 27 ms 193372 KB Output is correct
6 Correct 30 ms 193584 KB Output is correct
7 Correct 33 ms 193628 KB Output is correct
8 Correct 31 ms 193624 KB Output is correct
9 Correct 27 ms 193432 KB Output is correct
10 Correct 28 ms 193372 KB Output is correct
11 Correct 38 ms 194408 KB Output is correct
12 Correct 38 ms 196436 KB Output is correct
13 Correct 41 ms 196520 KB Output is correct
14 Correct 43 ms 196700 KB Output is correct
15 Correct 46 ms 196788 KB Output is correct
16 Correct 40 ms 196592 KB Output is correct
17 Correct 35 ms 195932 KB Output is correct
18 Correct 33 ms 193884 KB Output is correct
19 Runtime error 215 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -