Submission #1092990

# Submission time Handle Problem Language Result Execution time Memory
1092990 2024-09-25T15:28:49 Z Nurislam Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1028 ms 149080 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long


template <class F, class _S>
bool chmin(F &u, const _S &v){
	bool flag = false;
	if ( u > v ){
		u = v; flag |= true;
	}
	return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
	bool flag = false;
	if ( u < v ){
		u = v; flag |= true;
	}
	return flag;
}

const int N = 1e6+50, inf = 1e18+200;
//int mod = 998244353;
//int mod = 1000000007;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(l, r) uniform_int_distribution <int> (l, r)(rng)

struct segtree{
	vector<int> t;
	segtree(){
		t.resize(N*4);
	};
	void upd(int ps, int vl, int i = 1, int l = 1, int r = N){
		if(l == r){
			t[i] = vl;
			return;
		}
		int m = (l+r)>>1;
		if(ps <= m)upd(ps, vl, i*2, l, m);
		else upd(ps, vl, i*2+1, m+1, r);
		t[i] = max(t[i*2], t[i*2+1]);
	};
	int get(int tl, int tr, int i = 1, int l = 1, int r = N){
		if(l > tr || r < tl)return 0;
		if(tl <= l && r <= tr)return t[i];
		int m = (l+r)>>1;
		return max(	get(tl, tr, i*2, l, m), get(tl, tr, i*2+1, m+1, r));
	};
}t;

void solve(){
	
	
	int n, m;
	cin >> n >> m;
	vector<int> a(n+1, 0);
	for(int i = 1; i <= n; i++)cin >> a[i];
	vector<array<int,3>> q(m);
	for(auto &[l, r, k]:q)cin >> l >> r >> k;
	vector<vector<int>> g(n+1);
	for(int i = 0; i < m; i++){
		auto [l,r,k] = q[i];
		g[r].pb(i);
	}
	vector<int> ans(m);
	stack<int> st;
	for(int i = 1; i <= n; i++){
		while(st.size() && a[st.top()] <= a[i])st.pop();
		if(st.size()){
			t.upd(st.top(), a[st.top()]+a[i]);
		}
		for(auto id:g[i]){
			auto [l, r, k] = q[id];
			//cout << t.get(l, r) << '\n';
			ans[id] = t.get(l, r) <= k;
		}
		st.push(i);
	}
	for(auto i:ans)cout << i << '\n';
}

 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int tt = 1;
	//cin >> tt;
	while(tt--){
		solve();
	}
}
 
 
 
 
 
 
 
 
 
 
 
 
 
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31576 KB Output is correct
2 Correct 13 ms 31752 KB Output is correct
3 Correct 14 ms 31576 KB Output is correct
4 Correct 12 ms 31744 KB Output is correct
5 Correct 13 ms 31576 KB Output is correct
6 Correct 14 ms 31804 KB Output is correct
7 Correct 15 ms 31832 KB Output is correct
8 Correct 12 ms 31580 KB Output is correct
9 Correct 13 ms 31580 KB Output is correct
10 Correct 13 ms 31580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31576 KB Output is correct
2 Correct 13 ms 31752 KB Output is correct
3 Correct 14 ms 31576 KB Output is correct
4 Correct 12 ms 31744 KB Output is correct
5 Correct 13 ms 31576 KB Output is correct
6 Correct 14 ms 31804 KB Output is correct
7 Correct 15 ms 31832 KB Output is correct
8 Correct 12 ms 31580 KB Output is correct
9 Correct 13 ms 31580 KB Output is correct
10 Correct 13 ms 31580 KB Output is correct
11 Correct 15 ms 31832 KB Output is correct
12 Correct 17 ms 32032 KB Output is correct
13 Correct 15 ms 32092 KB Output is correct
14 Correct 19 ms 32348 KB Output is correct
15 Correct 16 ms 32308 KB Output is correct
16 Correct 17 ms 32048 KB Output is correct
17 Correct 16 ms 32092 KB Output is correct
18 Correct 16 ms 32048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1012 ms 148004 KB Output is correct
2 Correct 1028 ms 149076 KB Output is correct
3 Correct 976 ms 148820 KB Output is correct
4 Correct 975 ms 148944 KB Output is correct
5 Correct 917 ms 149080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 42064 KB Output is correct
2 Correct 68 ms 41368 KB Output is correct
3 Correct 86 ms 41764 KB Output is correct
4 Correct 69 ms 41808 KB Output is correct
5 Correct 72 ms 42012 KB Output is correct
6 Correct 57 ms 41040 KB Output is correct
7 Correct 59 ms 41016 KB Output is correct
8 Correct 67 ms 41408 KB Output is correct
9 Correct 41 ms 37428 KB Output is correct
10 Correct 60 ms 41572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31576 KB Output is correct
2 Correct 13 ms 31752 KB Output is correct
3 Correct 14 ms 31576 KB Output is correct
4 Correct 12 ms 31744 KB Output is correct
5 Correct 13 ms 31576 KB Output is correct
6 Correct 14 ms 31804 KB Output is correct
7 Correct 15 ms 31832 KB Output is correct
8 Correct 12 ms 31580 KB Output is correct
9 Correct 13 ms 31580 KB Output is correct
10 Correct 13 ms 31580 KB Output is correct
11 Correct 15 ms 31832 KB Output is correct
12 Correct 17 ms 32032 KB Output is correct
13 Correct 15 ms 32092 KB Output is correct
14 Correct 19 ms 32348 KB Output is correct
15 Correct 16 ms 32308 KB Output is correct
16 Correct 17 ms 32048 KB Output is correct
17 Correct 16 ms 32092 KB Output is correct
18 Correct 16 ms 32048 KB Output is correct
19 Correct 156 ms 54828 KB Output is correct
20 Correct 152 ms 54868 KB Output is correct
21 Correct 131 ms 53588 KB Output is correct
22 Correct 132 ms 53584 KB Output is correct
23 Correct 134 ms 53584 KB Output is correct
24 Correct 114 ms 53328 KB Output is correct
25 Correct 115 ms 53416 KB Output is correct
26 Correct 134 ms 54100 KB Output is correct
27 Correct 132 ms 54068 KB Output is correct
28 Correct 137 ms 54232 KB Output is correct
29 Correct 140 ms 54868 KB Output is correct
30 Correct 139 ms 54864 KB Output is correct
31 Correct 141 ms 54868 KB Output is correct
32 Correct 139 ms 54864 KB Output is correct
33 Correct 144 ms 54772 KB Output is correct
34 Correct 115 ms 53012 KB Output is correct
35 Correct 110 ms 53072 KB Output is correct
36 Correct 115 ms 52724 KB Output is correct
37 Correct 109 ms 52820 KB Output is correct
38 Correct 112 ms 53080 KB Output is correct
39 Correct 128 ms 53196 KB Output is correct
40 Correct 104 ms 49864 KB Output is correct
41 Correct 118 ms 52708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31576 KB Output is correct
2 Correct 13 ms 31752 KB Output is correct
3 Correct 14 ms 31576 KB Output is correct
4 Correct 12 ms 31744 KB Output is correct
5 Correct 13 ms 31576 KB Output is correct
6 Correct 14 ms 31804 KB Output is correct
7 Correct 15 ms 31832 KB Output is correct
8 Correct 12 ms 31580 KB Output is correct
9 Correct 13 ms 31580 KB Output is correct
10 Correct 13 ms 31580 KB Output is correct
11 Correct 15 ms 31832 KB Output is correct
12 Correct 17 ms 32032 KB Output is correct
13 Correct 15 ms 32092 KB Output is correct
14 Correct 19 ms 32348 KB Output is correct
15 Correct 16 ms 32308 KB Output is correct
16 Correct 17 ms 32048 KB Output is correct
17 Correct 16 ms 32092 KB Output is correct
18 Correct 16 ms 32048 KB Output is correct
19 Correct 1012 ms 148004 KB Output is correct
20 Correct 1028 ms 149076 KB Output is correct
21 Correct 976 ms 148820 KB Output is correct
22 Correct 975 ms 148944 KB Output is correct
23 Correct 917 ms 149080 KB Output is correct
24 Correct 73 ms 42064 KB Output is correct
25 Correct 68 ms 41368 KB Output is correct
26 Correct 86 ms 41764 KB Output is correct
27 Correct 69 ms 41808 KB Output is correct
28 Correct 72 ms 42012 KB Output is correct
29 Correct 57 ms 41040 KB Output is correct
30 Correct 59 ms 41016 KB Output is correct
31 Correct 67 ms 41408 KB Output is correct
32 Correct 41 ms 37428 KB Output is correct
33 Correct 60 ms 41572 KB Output is correct
34 Correct 156 ms 54828 KB Output is correct
35 Correct 152 ms 54868 KB Output is correct
36 Correct 131 ms 53588 KB Output is correct
37 Correct 132 ms 53584 KB Output is correct
38 Correct 134 ms 53584 KB Output is correct
39 Correct 114 ms 53328 KB Output is correct
40 Correct 115 ms 53416 KB Output is correct
41 Correct 134 ms 54100 KB Output is correct
42 Correct 132 ms 54068 KB Output is correct
43 Correct 137 ms 54232 KB Output is correct
44 Correct 140 ms 54868 KB Output is correct
45 Correct 139 ms 54864 KB Output is correct
46 Correct 141 ms 54868 KB Output is correct
47 Correct 139 ms 54864 KB Output is correct
48 Correct 144 ms 54772 KB Output is correct
49 Correct 115 ms 53012 KB Output is correct
50 Correct 110 ms 53072 KB Output is correct
51 Correct 115 ms 52724 KB Output is correct
52 Correct 109 ms 52820 KB Output is correct
53 Correct 112 ms 53080 KB Output is correct
54 Correct 128 ms 53196 KB Output is correct
55 Correct 104 ms 49864 KB Output is correct
56 Correct 118 ms 52708 KB Output is correct
57 Correct 980 ms 148564 KB Output is correct
58 Correct 986 ms 148564 KB Output is correct
59 Correct 852 ms 145880 KB Output is correct
60 Correct 884 ms 145872 KB Output is correct
61 Correct 875 ms 145756 KB Output is correct
62 Correct 864 ms 145632 KB Output is correct
63 Correct 616 ms 140368 KB Output is correct
64 Correct 589 ms 140308 KB Output is correct
65 Correct 778 ms 145492 KB Output is correct
66 Correct 762 ms 145344 KB Output is correct
67 Correct 793 ms 145616 KB Output is correct
68 Correct 887 ms 148504 KB Output is correct
69 Correct 905 ms 148312 KB Output is correct
70 Correct 878 ms 148064 KB Output is correct
71 Correct 891 ms 148048 KB Output is correct
72 Correct 882 ms 147900 KB Output is correct
73 Correct 563 ms 137296 KB Output is correct
74 Correct 612 ms 137880 KB Output is correct
75 Correct 563 ms 137296 KB Output is correct
76 Correct 581 ms 137300 KB Output is correct
77 Correct 555 ms 136976 KB Output is correct
78 Correct 766 ms 140544 KB Output is correct
79 Correct 577 ms 118676 KB Output is correct
80 Correct 757 ms 137944 KB Output is correct