Submission #937526

# Submission time Handle Problem Language Result Execution time Memory
937526 2024-03-04T07:53:53 Z Teemka Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1747 ms 92488 KB
#include "bits/stdc++.h" 
#define F first
#define S second
#define ALL(a) a.begin() , a.end()

#ifndef ONLINE_JUDGE
#define OK  cout << __LINE__ << "| "<< "---------------------------OK-----------------------" << endl;
#define deb(x) cout << __LINE__ << "| "<< #x  << " = " << x << endl;
#else
#define OK  
#define deb(x) 
#endif
 
typedef long double ld;
typedef long long ll;
using namespace std ;
const ll N = 1e6 + 7 ;	
const ll INF = 1e9;
const ll mod = 1e9 + 7 ;
const double eps = 1e-9 ;
const int dx[]  = { 0 , 0 , 1 , -1, 1 , -1 , 1 , -1} , dy[] = {1 , -1 , 0 , 0 , 1 , 1, -1 , -1}  ;
int n , q, a[N] , ans[N];
struct query{
	int l, k , id;
};
vector<query> vec[N];
int t[N];
void upd(int v ,int mx){
	v = N - v;
	while(v < N){
		t[v] = max(t[v] , mx);
		v += v & -v;
	}
}

int get(int v){
	v = N - v;
	int res = 0;
	while(v){
		res = max(res , t[v]);
		v -= v & -v;
	}
	return res;
}
void test_solve(int test_index){
	cin >> n >> q;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for(int i = 1; i<= q;i++){
		int l ,r ,k;
		cin >> l >> r >> k;
		vec[r].push_back({l ,k ,i });
	}
	stack<pair<int,int>> st;
	for(int i = 1; i <=n; i++){
		while(st.size() and st.top().F <= a[i])
			st.pop();
		if(st.size())
			upd(st.top().S , st.top().F + a[i]);
		for(auto[l , k , id] : vec[i]){
			if(get(l) <= k)
				ans[id] = 1;
		}
		st.push({a[i] , i});
	}

	for(int i = 1; i<= q;i++)
		cout << ans[i] << endl;
}

signed main(){
	ios_base::sync_with_stdio(false) ;
    cin.tie(0) ;
    cout.tie(0); 
	int test = 1;
	//cin >> test ;
	for(int i = 1 ;  i <= test ; i++){
 //		cout << "Case " << i << ": " ; 
		test_solve(i) ;
	}
  	return 0;	
}        
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29020 KB Output is correct
2 Correct 6 ms 29020 KB Output is correct
3 Correct 8 ms 29020 KB Output is correct
4 Correct 6 ms 29020 KB Output is correct
5 Correct 6 ms 29016 KB Output is correct
6 Correct 6 ms 29020 KB Output is correct
7 Correct 7 ms 29196 KB Output is correct
8 Correct 7 ms 29020 KB Output is correct
9 Correct 7 ms 29016 KB Output is correct
10 Correct 7 ms 29020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29020 KB Output is correct
2 Correct 6 ms 29020 KB Output is correct
3 Correct 8 ms 29020 KB Output is correct
4 Correct 6 ms 29020 KB Output is correct
5 Correct 6 ms 29016 KB Output is correct
6 Correct 6 ms 29020 KB Output is correct
7 Correct 7 ms 29196 KB Output is correct
8 Correct 7 ms 29020 KB Output is correct
9 Correct 7 ms 29016 KB Output is correct
10 Correct 7 ms 29020 KB Output is correct
11 Correct 10 ms 29276 KB Output is correct
12 Correct 10 ms 29276 KB Output is correct
13 Correct 11 ms 29196 KB Output is correct
14 Correct 13 ms 29276 KB Output is correct
15 Correct 13 ms 29396 KB Output is correct
16 Correct 13 ms 29276 KB Output is correct
17 Correct 13 ms 29276 KB Output is correct
18 Correct 13 ms 29204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1725 ms 83496 KB Output is correct
2 Correct 1694 ms 84416 KB Output is correct
3 Correct 1727 ms 84064 KB Output is correct
4 Correct 1747 ms 84856 KB Output is correct
5 Correct 1744 ms 87772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 33360 KB Output is correct
2 Correct 149 ms 33184 KB Output is correct
3 Correct 147 ms 33360 KB Output is correct
4 Correct 148 ms 33360 KB Output is correct
5 Correct 150 ms 33364 KB Output is correct
6 Correct 138 ms 32856 KB Output is correct
7 Correct 140 ms 32976 KB Output is correct
8 Correct 146 ms 32908 KB Output is correct
9 Correct 140 ms 32028 KB Output is correct
10 Correct 147 ms 33176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29020 KB Output is correct
2 Correct 6 ms 29020 KB Output is correct
3 Correct 8 ms 29020 KB Output is correct
4 Correct 6 ms 29020 KB Output is correct
5 Correct 6 ms 29016 KB Output is correct
6 Correct 6 ms 29020 KB Output is correct
7 Correct 7 ms 29196 KB Output is correct
8 Correct 7 ms 29020 KB Output is correct
9 Correct 7 ms 29016 KB Output is correct
10 Correct 7 ms 29020 KB Output is correct
11 Correct 10 ms 29276 KB Output is correct
12 Correct 10 ms 29276 KB Output is correct
13 Correct 11 ms 29196 KB Output is correct
14 Correct 13 ms 29276 KB Output is correct
15 Correct 13 ms 29396 KB Output is correct
16 Correct 13 ms 29276 KB Output is correct
17 Correct 13 ms 29276 KB Output is correct
18 Correct 13 ms 29204 KB Output is correct
19 Correct 336 ms 40276 KB Output is correct
20 Correct 323 ms 40216 KB Output is correct
21 Correct 307 ms 39508 KB Output is correct
22 Correct 306 ms 39664 KB Output is correct
23 Correct 340 ms 39504 KB Output is correct
24 Correct 299 ms 39544 KB Output is correct
25 Correct 293 ms 39592 KB Output is correct
26 Correct 304 ms 39924 KB Output is correct
27 Correct 301 ms 39764 KB Output is correct
28 Correct 310 ms 39888 KB Output is correct
29 Correct 313 ms 40404 KB Output is correct
30 Correct 319 ms 40572 KB Output is correct
31 Correct 304 ms 40336 KB Output is correct
32 Correct 307 ms 40596 KB Output is correct
33 Correct 321 ms 40248 KB Output is correct
34 Correct 342 ms 38992 KB Output is correct
35 Correct 283 ms 39004 KB Output is correct
36 Correct 287 ms 39036 KB Output is correct
37 Correct 286 ms 38928 KB Output is correct
38 Correct 324 ms 39168 KB Output is correct
39 Correct 350 ms 38412 KB Output is correct
40 Correct 291 ms 37720 KB Output is correct
41 Correct 292 ms 38408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29020 KB Output is correct
2 Correct 6 ms 29020 KB Output is correct
3 Correct 8 ms 29020 KB Output is correct
4 Correct 6 ms 29020 KB Output is correct
5 Correct 6 ms 29016 KB Output is correct
6 Correct 6 ms 29020 KB Output is correct
7 Correct 7 ms 29196 KB Output is correct
8 Correct 7 ms 29020 KB Output is correct
9 Correct 7 ms 29016 KB Output is correct
10 Correct 7 ms 29020 KB Output is correct
11 Correct 10 ms 29276 KB Output is correct
12 Correct 10 ms 29276 KB Output is correct
13 Correct 11 ms 29196 KB Output is correct
14 Correct 13 ms 29276 KB Output is correct
15 Correct 13 ms 29396 KB Output is correct
16 Correct 13 ms 29276 KB Output is correct
17 Correct 13 ms 29276 KB Output is correct
18 Correct 13 ms 29204 KB Output is correct
19 Correct 1725 ms 83496 KB Output is correct
20 Correct 1694 ms 84416 KB Output is correct
21 Correct 1727 ms 84064 KB Output is correct
22 Correct 1747 ms 84856 KB Output is correct
23 Correct 1744 ms 87772 KB Output is correct
24 Correct 149 ms 33360 KB Output is correct
25 Correct 149 ms 33184 KB Output is correct
26 Correct 147 ms 33360 KB Output is correct
27 Correct 148 ms 33360 KB Output is correct
28 Correct 150 ms 33364 KB Output is correct
29 Correct 138 ms 32856 KB Output is correct
30 Correct 140 ms 32976 KB Output is correct
31 Correct 146 ms 32908 KB Output is correct
32 Correct 140 ms 32028 KB Output is correct
33 Correct 147 ms 33176 KB Output is correct
34 Correct 336 ms 40276 KB Output is correct
35 Correct 323 ms 40216 KB Output is correct
36 Correct 307 ms 39508 KB Output is correct
37 Correct 306 ms 39664 KB Output is correct
38 Correct 340 ms 39504 KB Output is correct
39 Correct 299 ms 39544 KB Output is correct
40 Correct 293 ms 39592 KB Output is correct
41 Correct 304 ms 39924 KB Output is correct
42 Correct 301 ms 39764 KB Output is correct
43 Correct 310 ms 39888 KB Output is correct
44 Correct 313 ms 40404 KB Output is correct
45 Correct 319 ms 40572 KB Output is correct
46 Correct 304 ms 40336 KB Output is correct
47 Correct 307 ms 40596 KB Output is correct
48 Correct 321 ms 40248 KB Output is correct
49 Correct 342 ms 38992 KB Output is correct
50 Correct 283 ms 39004 KB Output is correct
51 Correct 287 ms 39036 KB Output is correct
52 Correct 286 ms 38928 KB Output is correct
53 Correct 324 ms 39168 KB Output is correct
54 Correct 350 ms 38412 KB Output is correct
55 Correct 291 ms 37720 KB Output is correct
56 Correct 292 ms 38408 KB Output is correct
57 Correct 1724 ms 92488 KB Output is correct
58 Correct 1727 ms 92444 KB Output is correct
59 Correct 1716 ms 90772 KB Output is correct
60 Correct 1718 ms 90804 KB Output is correct
61 Correct 1625 ms 90636 KB Output is correct
62 Correct 1665 ms 91208 KB Output is correct
63 Correct 1421 ms 85428 KB Output is correct
64 Correct 1526 ms 85248 KB Output is correct
65 Correct 1542 ms 88372 KB Output is correct
66 Correct 1582 ms 88500 KB Output is correct
67 Correct 1690 ms 88944 KB Output is correct
68 Correct 1720 ms 90340 KB Output is correct
69 Correct 1731 ms 89892 KB Output is correct
70 Correct 1728 ms 89756 KB Output is correct
71 Correct 1708 ms 89900 KB Output is correct
72 Correct 1690 ms 89816 KB Output is correct
73 Correct 1414 ms 81356 KB Output is correct
74 Correct 1390 ms 82396 KB Output is correct
75 Correct 1459 ms 81460 KB Output is correct
76 Correct 1441 ms 81596 KB Output is correct
77 Correct 1399 ms 81480 KB Output is correct
78 Correct 1631 ms 83016 KB Output is correct
79 Correct 1469 ms 75060 KB Output is correct
80 Correct 1616 ms 79724 KB Output is correct