Submission #499077

# Submission time Handle Problem Language Result Execution time Memory
499077 2021-12-27T07:57:46 Z Ziyoda Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
943 ms 85060 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ll N = 1e6+1;
ll tr[N], n;
vector<ll>ad[N], a(N), li(N), ri(N), ki(N);

void add(ll q, ll w){
	while(q>0){
		tr[q]=max(tr[q], w);
		q -= q&-q;
	}
}

int sol(ll w){
	ll c=0;
	while(w<=n){
		//cout << tr[w] << ' ';
		c=max(c, tr[w]);
		w += w&-w;
		//cout << c << " ";
	}
	return c;
}

void solve(){
	ll m;
	cin >> n >> m;
	for(int i=1; i<=n; i++)
		cin >> a[i];
	vector<ll>s;
	for(int i=1; i<=m; i++){
		cin >> li[i] >> ri[i] >> ki[i];
		ad[ri[i]].push_back(i);
	}
	vector<bool>y(m+1);
	for(int i=1; i<=n; i++){
		while(!s.empty()){
			//cout << a[s.back()] << ' ';
			if(a[i]>=a[s.back()])
				s.pop_back();
			else
				break;	}
		ll p = (s.empty()? 0:s.back());
		//cout << a[p]+a[i] << endl;
		add(p, a[p]+a[i]);
		for(ll u:ad[i]){
			y[u] = (sol(li[u])<=ki[u]);
			//cout << ri[u] << endl;
		}
		s.push_back(i);	
	}
	//cout << 'u' << endl;
	for(int i=1; i<=m; i++)
		cout << y[i] << "\n";
}

int main()
{
	IOS;
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 55116 KB Output is correct
2 Correct 30 ms 55056 KB Output is correct
3 Correct 23 ms 55048 KB Output is correct
4 Correct 25 ms 55056 KB Output is correct
5 Correct 26 ms 55084 KB Output is correct
6 Correct 25 ms 55124 KB Output is correct
7 Correct 28 ms 55044 KB Output is correct
8 Correct 23 ms 55156 KB Output is correct
9 Correct 26 ms 55016 KB Output is correct
10 Correct 23 ms 55032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 55116 KB Output is correct
2 Correct 30 ms 55056 KB Output is correct
3 Correct 23 ms 55048 KB Output is correct
4 Correct 25 ms 55056 KB Output is correct
5 Correct 26 ms 55084 KB Output is correct
6 Correct 25 ms 55124 KB Output is correct
7 Correct 28 ms 55044 KB Output is correct
8 Correct 23 ms 55156 KB Output is correct
9 Correct 26 ms 55016 KB Output is correct
10 Correct 23 ms 55032 KB Output is correct
11 Correct 26 ms 55116 KB Output is correct
12 Correct 25 ms 55164 KB Output is correct
13 Correct 25 ms 55220 KB Output is correct
14 Correct 26 ms 55196 KB Output is correct
15 Correct 27 ms 55184 KB Output is correct
16 Correct 26 ms 55256 KB Output is correct
17 Correct 29 ms 55244 KB Output is correct
18 Correct 27 ms 55172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 943 ms 84968 KB Output is correct
2 Correct 937 ms 84956 KB Output is correct
3 Correct 933 ms 84816 KB Output is correct
4 Correct 912 ms 85060 KB Output is correct
5 Correct 866 ms 77100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 57936 KB Output is correct
2 Correct 73 ms 57488 KB Output is correct
3 Correct 70 ms 57028 KB Output is correct
4 Correct 74 ms 57136 KB Output is correct
5 Correct 74 ms 57184 KB Output is correct
6 Correct 62 ms 56376 KB Output is correct
7 Correct 72 ms 56468 KB Output is correct
8 Correct 70 ms 57088 KB Output is correct
9 Correct 55 ms 56252 KB Output is correct
10 Correct 68 ms 57056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 55116 KB Output is correct
2 Correct 30 ms 55056 KB Output is correct
3 Correct 23 ms 55048 KB Output is correct
4 Correct 25 ms 55056 KB Output is correct
5 Correct 26 ms 55084 KB Output is correct
6 Correct 25 ms 55124 KB Output is correct
7 Correct 28 ms 55044 KB Output is correct
8 Correct 23 ms 55156 KB Output is correct
9 Correct 26 ms 55016 KB Output is correct
10 Correct 23 ms 55032 KB Output is correct
11 Correct 26 ms 55116 KB Output is correct
12 Correct 25 ms 55164 KB Output is correct
13 Correct 25 ms 55220 KB Output is correct
14 Correct 26 ms 55196 KB Output is correct
15 Correct 27 ms 55184 KB Output is correct
16 Correct 26 ms 55256 KB Output is correct
17 Correct 29 ms 55244 KB Output is correct
18 Correct 27 ms 55172 KB Output is correct
19 Correct 154 ms 60780 KB Output is correct
20 Correct 171 ms 60816 KB Output is correct
21 Correct 133 ms 59720 KB Output is correct
22 Correct 130 ms 59636 KB Output is correct
23 Correct 152 ms 59612 KB Output is correct
24 Correct 129 ms 57956 KB Output is correct
25 Correct 124 ms 58080 KB Output is correct
26 Correct 137 ms 58464 KB Output is correct
27 Correct 142 ms 58452 KB Output is correct
28 Correct 140 ms 58724 KB Output is correct
29 Correct 148 ms 59204 KB Output is correct
30 Correct 155 ms 59220 KB Output is correct
31 Correct 141 ms 59204 KB Output is correct
32 Correct 150 ms 59188 KB Output is correct
33 Correct 157 ms 59204 KB Output is correct
34 Correct 119 ms 57696 KB Output is correct
35 Correct 126 ms 57796 KB Output is correct
36 Correct 117 ms 57756 KB Output is correct
37 Correct 114 ms 57752 KB Output is correct
38 Correct 118 ms 57824 KB Output is correct
39 Correct 144 ms 59452 KB Output is correct
40 Correct 119 ms 58532 KB Output is correct
41 Correct 131 ms 59000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 55116 KB Output is correct
2 Correct 30 ms 55056 KB Output is correct
3 Correct 23 ms 55048 KB Output is correct
4 Correct 25 ms 55056 KB Output is correct
5 Correct 26 ms 55084 KB Output is correct
6 Correct 25 ms 55124 KB Output is correct
7 Correct 28 ms 55044 KB Output is correct
8 Correct 23 ms 55156 KB Output is correct
9 Correct 26 ms 55016 KB Output is correct
10 Correct 23 ms 55032 KB Output is correct
11 Correct 26 ms 55116 KB Output is correct
12 Correct 25 ms 55164 KB Output is correct
13 Correct 25 ms 55220 KB Output is correct
14 Correct 26 ms 55196 KB Output is correct
15 Correct 27 ms 55184 KB Output is correct
16 Correct 26 ms 55256 KB Output is correct
17 Correct 29 ms 55244 KB Output is correct
18 Correct 27 ms 55172 KB Output is correct
19 Correct 943 ms 84968 KB Output is correct
20 Correct 937 ms 84956 KB Output is correct
21 Correct 933 ms 84816 KB Output is correct
22 Correct 912 ms 85060 KB Output is correct
23 Correct 866 ms 77100 KB Output is correct
24 Correct 74 ms 57936 KB Output is correct
25 Correct 73 ms 57488 KB Output is correct
26 Correct 70 ms 57028 KB Output is correct
27 Correct 74 ms 57136 KB Output is correct
28 Correct 74 ms 57184 KB Output is correct
29 Correct 62 ms 56376 KB Output is correct
30 Correct 72 ms 56468 KB Output is correct
31 Correct 70 ms 57088 KB Output is correct
32 Correct 55 ms 56252 KB Output is correct
33 Correct 68 ms 57056 KB Output is correct
34 Correct 154 ms 60780 KB Output is correct
35 Correct 171 ms 60816 KB Output is correct
36 Correct 133 ms 59720 KB Output is correct
37 Correct 130 ms 59636 KB Output is correct
38 Correct 152 ms 59612 KB Output is correct
39 Correct 129 ms 57956 KB Output is correct
40 Correct 124 ms 58080 KB Output is correct
41 Correct 137 ms 58464 KB Output is correct
42 Correct 142 ms 58452 KB Output is correct
43 Correct 140 ms 58724 KB Output is correct
44 Correct 148 ms 59204 KB Output is correct
45 Correct 155 ms 59220 KB Output is correct
46 Correct 141 ms 59204 KB Output is correct
47 Correct 150 ms 59188 KB Output is correct
48 Correct 157 ms 59204 KB Output is correct
49 Correct 119 ms 57696 KB Output is correct
50 Correct 126 ms 57796 KB Output is correct
51 Correct 117 ms 57756 KB Output is correct
52 Correct 114 ms 57752 KB Output is correct
53 Correct 118 ms 57824 KB Output is correct
54 Correct 144 ms 59452 KB Output is correct
55 Correct 119 ms 58532 KB Output is correct
56 Correct 131 ms 59000 KB Output is correct
57 Correct 932 ms 83836 KB Output is correct
58 Correct 901 ms 83688 KB Output is correct
59 Correct 839 ms 81048 KB Output is correct
60 Correct 831 ms 81016 KB Output is correct
61 Correct 861 ms 81016 KB Output is correct
62 Correct 836 ms 81040 KB Output is correct
63 Correct 570 ms 69600 KB Output is correct
64 Correct 577 ms 69604 KB Output is correct
65 Correct 767 ms 72976 KB Output is correct
66 Correct 837 ms 72928 KB Output is correct
67 Correct 823 ms 73156 KB Output is correct
68 Correct 831 ms 76088 KB Output is correct
69 Correct 817 ms 75920 KB Output is correct
70 Correct 798 ms 75360 KB Output is correct
71 Correct 790 ms 75360 KB Output is correct
72 Correct 801 ms 75348 KB Output is correct
73 Correct 535 ms 68216 KB Output is correct
74 Correct 575 ms 67900 KB Output is correct
75 Correct 534 ms 68040 KB Output is correct
76 Correct 542 ms 68188 KB Output is correct
77 Correct 531 ms 67800 KB Output is correct
78 Correct 712 ms 76868 KB Output is correct
79 Correct 566 ms 71964 KB Output is correct
80 Correct 708 ms 74544 KB Output is correct