Submission #1014683

# Submission time Handle Problem Language Result Execution time Memory
1014683 2024-07-05T09:22:37 Z jcelin Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
833 ms 98296 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<pll> vpll;

#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define all(x) (x).begin(), (x).end()

const int mod = 1e9 + 7; //998244353;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;
const int logo = 20;
const int MAXN = 1e6 + 7;
const int off = 1 << logo;
const int trsz = off << 1;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};

int arr[MAXN];

struct tournament{
	int seg[trsz];
	
	void update(int x, int vl){
		x += off;
		seg[x] = max(seg[x], vl);
		for(x /= 2; x; x /= 2) seg[x] = max(seg[x], vl);
	}
	
	int query(int l, int r){
		int ret = 0;
		for(l += off, r += off; l < r; l >>= 1, r >>= 1){
			if(l & 1) ret = max(ret, seg[l++]);
			if(r & 1) ret = max(ret, seg[--r]);
		}
		return ret;
	}
}t;

vii st, qs[MAXN];
int ans[MAXN], lim[MAXN];

void solve(){
	int n, m;
	cin >> n >> m;
	for(int i=1; i<=n; i++) cin >> arr[i];
	st.PB({0, inf});
	for(int i=0; i<m; i++){
		int l, r;
		cin >> l >> r >> lim[i];
		qs[r].PB({l, i});
	}
	
	
	for(int i=1; i<=n; i++){
		while(st.back().Y <= arr[i]) st.PPB();
		t.update(st.back().X, st.back().Y + arr[i]);
		st.PB({i, arr[i]});
		for(auto &x : qs[i]){
			ans[x.Y] = (lim[x.Y] >= t.query(x.X, i + 1));
		}
	}
	
	
	for(int i=0; i<m; i++) cout << ans[i] << "\n";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int tt = 1;
	//cin >> tt;
	while(tt--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23900 KB Output is correct
2 Correct 13 ms 23888 KB Output is correct
3 Correct 16 ms 23900 KB Output is correct
4 Correct 11 ms 23896 KB Output is correct
5 Correct 12 ms 23900 KB Output is correct
6 Correct 11 ms 23832 KB Output is correct
7 Correct 12 ms 23896 KB Output is correct
8 Correct 13 ms 23900 KB Output is correct
9 Correct 12 ms 23900 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23900 KB Output is correct
2 Correct 13 ms 23888 KB Output is correct
3 Correct 16 ms 23900 KB Output is correct
4 Correct 11 ms 23896 KB Output is correct
5 Correct 12 ms 23900 KB Output is correct
6 Correct 11 ms 23832 KB Output is correct
7 Correct 12 ms 23896 KB Output is correct
8 Correct 13 ms 23900 KB Output is correct
9 Correct 12 ms 23900 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 11 ms 24156 KB Output is correct
12 Correct 12 ms 24156 KB Output is correct
13 Correct 12 ms 24152 KB Output is correct
14 Correct 12 ms 24156 KB Output is correct
15 Correct 12 ms 24180 KB Output is correct
16 Correct 13 ms 24084 KB Output is correct
17 Correct 16 ms 24200 KB Output is correct
18 Correct 14 ms 24156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 705 ms 97120 KB Output is correct
2 Correct 728 ms 98084 KB Output is correct
3 Correct 767 ms 98004 KB Output is correct
4 Correct 735 ms 98296 KB Output is correct
5 Correct 678 ms 90452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 30068 KB Output is correct
2 Correct 58 ms 29520 KB Output is correct
3 Correct 55 ms 28880 KB Output is correct
4 Correct 59 ms 29104 KB Output is correct
5 Correct 58 ms 29144 KB Output is correct
6 Correct 52 ms 28240 KB Output is correct
7 Correct 45 ms 28240 KB Output is correct
8 Correct 52 ms 28788 KB Output is correct
9 Correct 31 ms 27080 KB Output is correct
10 Correct 51 ms 28616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23900 KB Output is correct
2 Correct 13 ms 23888 KB Output is correct
3 Correct 16 ms 23900 KB Output is correct
4 Correct 11 ms 23896 KB Output is correct
5 Correct 12 ms 23900 KB Output is correct
6 Correct 11 ms 23832 KB Output is correct
7 Correct 12 ms 23896 KB Output is correct
8 Correct 13 ms 23900 KB Output is correct
9 Correct 12 ms 23900 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 11 ms 24156 KB Output is correct
12 Correct 12 ms 24156 KB Output is correct
13 Correct 12 ms 24152 KB Output is correct
14 Correct 12 ms 24156 KB Output is correct
15 Correct 12 ms 24180 KB Output is correct
16 Correct 13 ms 24084 KB Output is correct
17 Correct 16 ms 24200 KB Output is correct
18 Correct 14 ms 24156 KB Output is correct
19 Correct 140 ms 38500 KB Output is correct
20 Correct 119 ms 38648 KB Output is correct
21 Correct 105 ms 37168 KB Output is correct
22 Correct 104 ms 37280 KB Output is correct
23 Correct 110 ms 37324 KB Output is correct
24 Correct 102 ms 35440 KB Output is correct
25 Correct 93 ms 35408 KB Output is correct
26 Correct 98 ms 36176 KB Output is correct
27 Correct 93 ms 36232 KB Output is correct
28 Correct 108 ms 36460 KB Output is correct
29 Correct 103 ms 37104 KB Output is correct
30 Correct 104 ms 36948 KB Output is correct
31 Correct 114 ms 36972 KB Output is correct
32 Correct 111 ms 37012 KB Output is correct
33 Correct 118 ms 36904 KB Output is correct
34 Correct 91 ms 35112 KB Output is correct
35 Correct 107 ms 35284 KB Output is correct
36 Correct 90 ms 35036 KB Output is correct
37 Correct 94 ms 34960 KB Output is correct
38 Correct 95 ms 35156 KB Output is correct
39 Correct 115 ms 35788 KB Output is correct
40 Correct 81 ms 33992 KB Output is correct
41 Correct 97 ms 35012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23900 KB Output is correct
2 Correct 13 ms 23888 KB Output is correct
3 Correct 16 ms 23900 KB Output is correct
4 Correct 11 ms 23896 KB Output is correct
5 Correct 12 ms 23900 KB Output is correct
6 Correct 11 ms 23832 KB Output is correct
7 Correct 12 ms 23896 KB Output is correct
8 Correct 13 ms 23900 KB Output is correct
9 Correct 12 ms 23900 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 11 ms 24156 KB Output is correct
12 Correct 12 ms 24156 KB Output is correct
13 Correct 12 ms 24152 KB Output is correct
14 Correct 12 ms 24156 KB Output is correct
15 Correct 12 ms 24180 KB Output is correct
16 Correct 13 ms 24084 KB Output is correct
17 Correct 16 ms 24200 KB Output is correct
18 Correct 14 ms 24156 KB Output is correct
19 Correct 705 ms 97120 KB Output is correct
20 Correct 728 ms 98084 KB Output is correct
21 Correct 767 ms 98004 KB Output is correct
22 Correct 735 ms 98296 KB Output is correct
23 Correct 678 ms 90452 KB Output is correct
24 Correct 64 ms 30068 KB Output is correct
25 Correct 58 ms 29520 KB Output is correct
26 Correct 55 ms 28880 KB Output is correct
27 Correct 59 ms 29104 KB Output is correct
28 Correct 58 ms 29144 KB Output is correct
29 Correct 52 ms 28240 KB Output is correct
30 Correct 45 ms 28240 KB Output is correct
31 Correct 52 ms 28788 KB Output is correct
32 Correct 31 ms 27080 KB Output is correct
33 Correct 51 ms 28616 KB Output is correct
34 Correct 140 ms 38500 KB Output is correct
35 Correct 119 ms 38648 KB Output is correct
36 Correct 105 ms 37168 KB Output is correct
37 Correct 104 ms 37280 KB Output is correct
38 Correct 110 ms 37324 KB Output is correct
39 Correct 102 ms 35440 KB Output is correct
40 Correct 93 ms 35408 KB Output is correct
41 Correct 98 ms 36176 KB Output is correct
42 Correct 93 ms 36232 KB Output is correct
43 Correct 108 ms 36460 KB Output is correct
44 Correct 103 ms 37104 KB Output is correct
45 Correct 104 ms 36948 KB Output is correct
46 Correct 114 ms 36972 KB Output is correct
47 Correct 111 ms 37012 KB Output is correct
48 Correct 118 ms 36904 KB Output is correct
49 Correct 91 ms 35112 KB Output is correct
50 Correct 107 ms 35284 KB Output is correct
51 Correct 90 ms 35036 KB Output is correct
52 Correct 94 ms 34960 KB Output is correct
53 Correct 95 ms 35156 KB Output is correct
54 Correct 115 ms 35788 KB Output is correct
55 Correct 81 ms 33992 KB Output is correct
56 Correct 97 ms 35012 KB Output is correct
57 Correct 762 ms 97624 KB Output is correct
58 Correct 755 ms 97712 KB Output is correct
59 Correct 709 ms 94864 KB Output is correct
60 Correct 753 ms 95056 KB Output is correct
61 Correct 676 ms 95040 KB Output is correct
62 Correct 648 ms 94812 KB Output is correct
63 Correct 451 ms 81772 KB Output is correct
64 Correct 444 ms 81552 KB Output is correct
65 Correct 603 ms 86864 KB Output is correct
66 Correct 575 ms 86744 KB Output is correct
67 Correct 607 ms 87140 KB Output is correct
68 Correct 730 ms 89680 KB Output is correct
69 Correct 785 ms 89828 KB Output is correct
70 Correct 735 ms 89472 KB Output is correct
71 Correct 833 ms 89460 KB Output is correct
72 Correct 763 ms 89292 KB Output is correct
73 Correct 429 ms 78652 KB Output is correct
74 Correct 442 ms 79332 KB Output is correct
75 Correct 373 ms 78604 KB Output is correct
76 Correct 446 ms 78636 KB Output is correct
77 Correct 412 ms 78332 KB Output is correct
78 Correct 639 ms 84676 KB Output is correct
79 Correct 488 ms 73048 KB Output is correct
80 Correct 626 ms 79612 KB Output is correct