Submission #524548

# Submission time Handle Problem Language Result Execution time Memory
524548 2022-02-09T13:15:37 Z asliddinaif Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
895 ms 67176 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);
#define all(x) (x).begin(), (x).end()
#define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
#define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
#define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--)
#define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
const int maxx = 1e6+6;
int tr[maxx], n, m, a[maxx], ans[maxx], k[maxx], x[maxx], y[maxx];
vector <int> g[maxx];
void ad(int x, int val){
	while(x > 0)
		tr[x] = max(tr[x], val), x -= x & -x;
}

int get(int x){
	int s = 0;
	while(x <= n)
		s = max(tr[x], s), x += x & -x;
	return s;
}
void S()
{
	cin >> n >> m;
	fpp(i,1,n)
		cin >> a[i];
	fpp(i,1,m){
		cin >> x[i] >> y[i] >> k[i];
		g[y[i]].push_back(i);
	}
	vector <int> v;
	fpp(i,1,n){
		while(!v.empty() && a[v.back()] <= a[i])
			v.pop_back();
		int xx = (v.size() == 0 ? 0 : v.back());
		ad(xx, a[xx]+a[i]);
		for(auto it : g[i])
			ans[it] = (get(x[it]) <= k[it]);//, cout << get(x[it]) << " " << i << " " << it << " ";
		v.push_back(i);
	//	cout << a[xx] << "\n";
	}
	fpp(i,1,m)
		cout << ans[i] << "\n";
}
int main()
{
	IOS;
	S();
}

Compilation message

sortbooks.cpp: In function 'void S()':
sortbooks.cpp:7:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
      |                            ^
sortbooks.cpp:27:2: note: in expansion of macro 'fpp'
   27 |  fpp(i,1,n)
      |  ^~~
sortbooks.cpp:7:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
      |                            ^
sortbooks.cpp:29:2: note: in expansion of macro 'fpp'
   29 |  fpp(i,1,m){
      |  ^~~
sortbooks.cpp:7:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
      |                            ^
sortbooks.cpp:34:2: note: in expansion of macro 'fpp'
   34 |  fpp(i,1,n){
      |  ^~~
sortbooks.cpp:7:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
      |                            ^
sortbooks.cpp:44:2: note: in expansion of macro 'fpp'
   44 |  fpp(i,1,m)
      |  ^~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23756 KB Output is correct
2 Correct 12 ms 23804 KB Output is correct
3 Correct 12 ms 23756 KB Output is correct
4 Correct 12 ms 23732 KB Output is correct
5 Correct 14 ms 23944 KB Output is correct
6 Correct 14 ms 23784 KB Output is correct
7 Correct 13 ms 23832 KB Output is correct
8 Correct 12 ms 23756 KB Output is correct
9 Correct 12 ms 23776 KB Output is correct
10 Correct 12 ms 23860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23756 KB Output is correct
2 Correct 12 ms 23804 KB Output is correct
3 Correct 12 ms 23756 KB Output is correct
4 Correct 12 ms 23732 KB Output is correct
5 Correct 14 ms 23944 KB Output is correct
6 Correct 14 ms 23784 KB Output is correct
7 Correct 13 ms 23832 KB Output is correct
8 Correct 12 ms 23756 KB Output is correct
9 Correct 12 ms 23776 KB Output is correct
10 Correct 12 ms 23860 KB Output is correct
11 Correct 14 ms 23860 KB Output is correct
12 Correct 17 ms 23868 KB Output is correct
13 Correct 14 ms 23896 KB Output is correct
14 Correct 15 ms 23976 KB Output is correct
15 Correct 15 ms 24012 KB Output is correct
16 Correct 14 ms 24012 KB Output is correct
17 Correct 14 ms 23960 KB Output is correct
18 Correct 14 ms 23996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 858 ms 67152 KB Output is correct
2 Correct 857 ms 67128 KB Output is correct
3 Correct 895 ms 67176 KB Output is correct
4 Correct 849 ms 67152 KB Output is correct
5 Correct 815 ms 63500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 28000 KB Output is correct
2 Correct 58 ms 27280 KB Output is correct
3 Correct 58 ms 27380 KB Output is correct
4 Correct 57 ms 27488 KB Output is correct
5 Correct 57 ms 27516 KB Output is correct
6 Correct 53 ms 26620 KB Output is correct
7 Correct 51 ms 26588 KB Output is correct
8 Correct 61 ms 27528 KB Output is correct
9 Correct 41 ms 26052 KB Output is correct
10 Correct 55 ms 27452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23756 KB Output is correct
2 Correct 12 ms 23804 KB Output is correct
3 Correct 12 ms 23756 KB Output is correct
4 Correct 12 ms 23732 KB Output is correct
5 Correct 14 ms 23944 KB Output is correct
6 Correct 14 ms 23784 KB Output is correct
7 Correct 13 ms 23832 KB Output is correct
8 Correct 12 ms 23756 KB Output is correct
9 Correct 12 ms 23776 KB Output is correct
10 Correct 12 ms 23860 KB Output is correct
11 Correct 14 ms 23860 KB Output is correct
12 Correct 17 ms 23868 KB Output is correct
13 Correct 14 ms 23896 KB Output is correct
14 Correct 15 ms 23976 KB Output is correct
15 Correct 15 ms 24012 KB Output is correct
16 Correct 14 ms 24012 KB Output is correct
17 Correct 14 ms 23960 KB Output is correct
18 Correct 14 ms 23996 KB Output is correct
19 Correct 138 ms 32120 KB Output is correct
20 Correct 134 ms 32048 KB Output is correct
21 Correct 121 ms 30404 KB Output is correct
22 Correct 117 ms 30348 KB Output is correct
23 Correct 136 ms 30336 KB Output is correct
24 Correct 111 ms 29384 KB Output is correct
25 Correct 115 ms 29520 KB Output is correct
26 Correct 118 ms 30116 KB Output is correct
27 Correct 123 ms 30192 KB Output is correct
28 Correct 130 ms 30432 KB Output is correct
29 Correct 148 ms 31384 KB Output is correct
30 Correct 141 ms 31288 KB Output is correct
31 Correct 145 ms 31384 KB Output is correct
32 Correct 130 ms 31308 KB Output is correct
33 Correct 128 ms 31300 KB Output is correct
34 Correct 106 ms 29292 KB Output is correct
35 Correct 106 ms 29296 KB Output is correct
36 Correct 104 ms 29252 KB Output is correct
37 Correct 105 ms 29252 KB Output is correct
38 Correct 106 ms 29264 KB Output is correct
39 Correct 121 ms 31292 KB Output is correct
40 Correct 116 ms 30372 KB Output is correct
41 Correct 118 ms 31072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23756 KB Output is correct
2 Correct 12 ms 23804 KB Output is correct
3 Correct 12 ms 23756 KB Output is correct
4 Correct 12 ms 23732 KB Output is correct
5 Correct 14 ms 23944 KB Output is correct
6 Correct 14 ms 23784 KB Output is correct
7 Correct 13 ms 23832 KB Output is correct
8 Correct 12 ms 23756 KB Output is correct
9 Correct 12 ms 23776 KB Output is correct
10 Correct 12 ms 23860 KB Output is correct
11 Correct 14 ms 23860 KB Output is correct
12 Correct 17 ms 23868 KB Output is correct
13 Correct 14 ms 23896 KB Output is correct
14 Correct 15 ms 23976 KB Output is correct
15 Correct 15 ms 24012 KB Output is correct
16 Correct 14 ms 24012 KB Output is correct
17 Correct 14 ms 23960 KB Output is correct
18 Correct 14 ms 23996 KB Output is correct
19 Correct 858 ms 67152 KB Output is correct
20 Correct 857 ms 67128 KB Output is correct
21 Correct 895 ms 67176 KB Output is correct
22 Correct 849 ms 67152 KB Output is correct
23 Correct 815 ms 63500 KB Output is correct
24 Correct 60 ms 28000 KB Output is correct
25 Correct 58 ms 27280 KB Output is correct
26 Correct 58 ms 27380 KB Output is correct
27 Correct 57 ms 27488 KB Output is correct
28 Correct 57 ms 27516 KB Output is correct
29 Correct 53 ms 26620 KB Output is correct
30 Correct 51 ms 26588 KB Output is correct
31 Correct 61 ms 27528 KB Output is correct
32 Correct 41 ms 26052 KB Output is correct
33 Correct 55 ms 27452 KB Output is correct
34 Correct 138 ms 32120 KB Output is correct
35 Correct 134 ms 32048 KB Output is correct
36 Correct 121 ms 30404 KB Output is correct
37 Correct 117 ms 30348 KB Output is correct
38 Correct 136 ms 30336 KB Output is correct
39 Correct 111 ms 29384 KB Output is correct
40 Correct 115 ms 29520 KB Output is correct
41 Correct 118 ms 30116 KB Output is correct
42 Correct 123 ms 30192 KB Output is correct
43 Correct 130 ms 30432 KB Output is correct
44 Correct 148 ms 31384 KB Output is correct
45 Correct 141 ms 31288 KB Output is correct
46 Correct 145 ms 31384 KB Output is correct
47 Correct 130 ms 31308 KB Output is correct
48 Correct 128 ms 31300 KB Output is correct
49 Correct 106 ms 29292 KB Output is correct
50 Correct 106 ms 29296 KB Output is correct
51 Correct 104 ms 29252 KB Output is correct
52 Correct 105 ms 29252 KB Output is correct
53 Correct 106 ms 29264 KB Output is correct
54 Correct 121 ms 31292 KB Output is correct
55 Correct 116 ms 30372 KB Output is correct
56 Correct 118 ms 31072 KB Output is correct
57 Correct 848 ms 66132 KB Output is correct
58 Correct 880 ms 66060 KB Output is correct
59 Correct 776 ms 62008 KB Output is correct
60 Correct 779 ms 62032 KB Output is correct
61 Correct 818 ms 61840 KB Output is correct
62 Correct 777 ms 61856 KB Output is correct
63 Correct 535 ms 52224 KB Output is correct
64 Correct 543 ms 52264 KB Output is correct
65 Correct 724 ms 57492 KB Output is correct
66 Correct 732 ms 57484 KB Output is correct
67 Correct 717 ms 57748 KB Output is correct
68 Correct 783 ms 62020 KB Output is correct
69 Correct 787 ms 62200 KB Output is correct
70 Correct 807 ms 61336 KB Output is correct
71 Correct 780 ms 61396 KB Output is correct
72 Correct 780 ms 61304 KB Output is correct
73 Correct 517 ms 51788 KB Output is correct
74 Correct 547 ms 51564 KB Output is correct
75 Correct 510 ms 51636 KB Output is correct
76 Correct 517 ms 51760 KB Output is correct
77 Correct 521 ms 51688 KB Output is correct
78 Correct 692 ms 61580 KB Output is correct
79 Correct 546 ms 56112 KB Output is correct
80 Correct 686 ms 60892 KB Output is correct