Submission #497905

# Submission time Handle Problem Language Result Execution time Memory
497905 2021-12-24T04:36:39 Z Ierus Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1617 ms 91416 KB
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define sz(x) (int)x.size()
#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
const int E = 1e6+777;
const long long inf = 1e18+777;
const int N = 1e5+777;
const int MOD = 1e9+7;
const bool I = 1;
int n, que, a[E], t[E<<2], ans[E];
void update(int pos, int val, int v, int tl, int tr){
	if(tl == tr){
		t[v] = max(val, t[v]);
		return;
	}
	int tm = (tl + tr) / 2;
	if(pos <= tm) update(pos, val, v<<1, tl, tm);
	else update(pos, val, v<<1|1, tm+1, tr);
	t[v] = max(t[v<<1], t[v<<1|1]);
}
int get(int l, int r, int v, int tl, int tr){
	if(l <= tl && tr <= r) return t[v];
	if(tl > r || tr < l) return 0;
	int tm = (tl + tr) / 2;
	return max(get(l, r, v<<1, tl, tm), get(l, r, v<<1|1, tm+1, tr));
}
struct D{
	int l, x, i;
};
vector<D> g[E];
signed main(){NFS;
	cin >> n >> que;
	for(int i = 1; i <= n; ++i){
		cin >> a[i];
	}
	for(int l, r, x, i = 1; i <= que; ++i){
		cin >> l >> r >> x;
		g[r].pb({l, x, i});
	}
	deque<pair<int,int>> st;
	for(int i = 1; i <= n; ++i){
		while(!st.empty() && st.back().F <= a[i]) st.pop_back();
		if(!st.empty()) update(st.back().S, st.back().F + a[i], 1, 0, n);
		for(auto to : g[i]){
			int cur = get(to.l, i, 1, 0, n);
			ans[to.i] = (cur <= to.x);
		}
		st.push_back({a[i], i});
	}
	for(int i = 1; i <= que; ++i){
		cout << ans[i] << '\n';
	}
}











# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 13 ms 23808 KB Output is correct
3 Correct 12 ms 23784 KB Output is correct
4 Correct 12 ms 23852 KB Output is correct
5 Correct 13 ms 23832 KB Output is correct
6 Correct 16 ms 23756 KB Output is correct
7 Correct 15 ms 23868 KB Output is correct
8 Correct 15 ms 23792 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 17 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 13 ms 23808 KB Output is correct
3 Correct 12 ms 23784 KB Output is correct
4 Correct 12 ms 23852 KB Output is correct
5 Correct 13 ms 23832 KB Output is correct
6 Correct 16 ms 23756 KB Output is correct
7 Correct 15 ms 23868 KB Output is correct
8 Correct 15 ms 23792 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 17 ms 23756 KB Output is correct
11 Correct 19 ms 23924 KB Output is correct
12 Correct 17 ms 24024 KB Output is correct
13 Correct 14 ms 24076 KB Output is correct
14 Correct 16 ms 24140 KB Output is correct
15 Correct 19 ms 24148 KB Output is correct
16 Correct 22 ms 24140 KB Output is correct
17 Correct 16 ms 24108 KB Output is correct
18 Correct 18 ms 24020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1350 ms 90420 KB Output is correct
2 Correct 1517 ms 90312 KB Output is correct
3 Correct 1452 ms 90284 KB Output is correct
4 Correct 1617 ms 90244 KB Output is correct
5 Correct 1264 ms 74008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 171 ms 30876 KB Output is correct
2 Correct 116 ms 31036 KB Output is correct
3 Correct 108 ms 28816 KB Output is correct
4 Correct 105 ms 28808 KB Output is correct
5 Correct 85 ms 28772 KB Output is correct
6 Correct 86 ms 28868 KB Output is correct
7 Correct 123 ms 28980 KB Output is correct
8 Correct 83 ms 28536 KB Output is correct
9 Correct 46 ms 27644 KB Output is correct
10 Correct 164 ms 28588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 13 ms 23808 KB Output is correct
3 Correct 12 ms 23784 KB Output is correct
4 Correct 12 ms 23852 KB Output is correct
5 Correct 13 ms 23832 KB Output is correct
6 Correct 16 ms 23756 KB Output is correct
7 Correct 15 ms 23868 KB Output is correct
8 Correct 15 ms 23792 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 17 ms 23756 KB Output is correct
11 Correct 19 ms 23924 KB Output is correct
12 Correct 17 ms 24024 KB Output is correct
13 Correct 14 ms 24076 KB Output is correct
14 Correct 16 ms 24140 KB Output is correct
15 Correct 19 ms 24148 KB Output is correct
16 Correct 22 ms 24140 KB Output is correct
17 Correct 16 ms 24108 KB Output is correct
18 Correct 18 ms 24020 KB Output is correct
19 Correct 257 ms 37948 KB Output is correct
20 Correct 320 ms 37956 KB Output is correct
21 Correct 221 ms 38580 KB Output is correct
22 Correct 184 ms 38528 KB Output is correct
23 Correct 187 ms 38460 KB Output is correct
24 Correct 229 ms 34456 KB Output is correct
25 Correct 148 ms 34576 KB Output is correct
26 Correct 175 ms 34148 KB Output is correct
27 Correct 205 ms 34152 KB Output is correct
28 Correct 191 ms 34052 KB Output is correct
29 Correct 230 ms 33892 KB Output is correct
30 Correct 243 ms 33804 KB Output is correct
31 Correct 395 ms 33872 KB Output is correct
32 Correct 313 ms 33848 KB Output is correct
33 Correct 303 ms 33892 KB Output is correct
34 Correct 181 ms 33964 KB Output is correct
35 Correct 159 ms 33940 KB Output is correct
36 Correct 171 ms 33988 KB Output is correct
37 Correct 164 ms 34060 KB Output is correct
38 Correct 176 ms 33984 KB Output is correct
39 Correct 196 ms 34804 KB Output is correct
40 Correct 147 ms 32340 KB Output is correct
41 Correct 204 ms 33232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 13 ms 23808 KB Output is correct
3 Correct 12 ms 23784 KB Output is correct
4 Correct 12 ms 23852 KB Output is correct
5 Correct 13 ms 23832 KB Output is correct
6 Correct 16 ms 23756 KB Output is correct
7 Correct 15 ms 23868 KB Output is correct
8 Correct 15 ms 23792 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 17 ms 23756 KB Output is correct
11 Correct 19 ms 23924 KB Output is correct
12 Correct 17 ms 24024 KB Output is correct
13 Correct 14 ms 24076 KB Output is correct
14 Correct 16 ms 24140 KB Output is correct
15 Correct 19 ms 24148 KB Output is correct
16 Correct 22 ms 24140 KB Output is correct
17 Correct 16 ms 24108 KB Output is correct
18 Correct 18 ms 24020 KB Output is correct
19 Correct 1350 ms 90420 KB Output is correct
20 Correct 1517 ms 90312 KB Output is correct
21 Correct 1452 ms 90284 KB Output is correct
22 Correct 1617 ms 90244 KB Output is correct
23 Correct 1264 ms 74008 KB Output is correct
24 Correct 171 ms 30876 KB Output is correct
25 Correct 116 ms 31036 KB Output is correct
26 Correct 108 ms 28816 KB Output is correct
27 Correct 105 ms 28808 KB Output is correct
28 Correct 85 ms 28772 KB Output is correct
29 Correct 86 ms 28868 KB Output is correct
30 Correct 123 ms 28980 KB Output is correct
31 Correct 83 ms 28536 KB Output is correct
32 Correct 46 ms 27644 KB Output is correct
33 Correct 164 ms 28588 KB Output is correct
34 Correct 257 ms 37948 KB Output is correct
35 Correct 320 ms 37956 KB Output is correct
36 Correct 221 ms 38580 KB Output is correct
37 Correct 184 ms 38528 KB Output is correct
38 Correct 187 ms 38460 KB Output is correct
39 Correct 229 ms 34456 KB Output is correct
40 Correct 148 ms 34576 KB Output is correct
41 Correct 175 ms 34148 KB Output is correct
42 Correct 205 ms 34152 KB Output is correct
43 Correct 191 ms 34052 KB Output is correct
44 Correct 230 ms 33892 KB Output is correct
45 Correct 243 ms 33804 KB Output is correct
46 Correct 395 ms 33872 KB Output is correct
47 Correct 313 ms 33848 KB Output is correct
48 Correct 303 ms 33892 KB Output is correct
49 Correct 181 ms 33964 KB Output is correct
50 Correct 159 ms 33940 KB Output is correct
51 Correct 171 ms 33988 KB Output is correct
52 Correct 164 ms 34060 KB Output is correct
53 Correct 176 ms 33984 KB Output is correct
54 Correct 196 ms 34804 KB Output is correct
55 Correct 147 ms 32340 KB Output is correct
56 Correct 204 ms 33232 KB Output is correct
57 Correct 1420 ms 90472 KB Output is correct
58 Correct 1375 ms 90552 KB Output is correct
59 Correct 1239 ms 91416 KB Output is correct
60 Correct 1446 ms 91328 KB Output is correct
61 Correct 1381 ms 91352 KB Output is correct
62 Correct 1319 ms 91404 KB Output is correct
63 Correct 720 ms 76920 KB Output is correct
64 Correct 816 ms 76988 KB Output is correct
65 Correct 1078 ms 75164 KB Output is correct
66 Correct 1071 ms 75132 KB Output is correct
67 Correct 1103 ms 74956 KB Output is correct
68 Correct 1082 ms 74080 KB Output is correct
69 Correct 1175 ms 74128 KB Output is correct
70 Correct 1178 ms 74284 KB Output is correct
71 Correct 1192 ms 74240 KB Output is correct
72 Correct 1170 ms 74248 KB Output is correct
73 Correct 680 ms 72568 KB Output is correct
74 Correct 669 ms 72392 KB Output is correct
75 Correct 666 ms 72180 KB Output is correct
76 Correct 705 ms 72836 KB Output is correct
77 Correct 703 ms 72440 KB Output is correct
78 Correct 1130 ms 77248 KB Output is correct
79 Correct 728 ms 65632 KB Output is correct
80 Correct 988 ms 70780 KB Output is correct