Submission #651302

# Submission time Handle Problem Language Result Execution time Memory
651302 2022-10-18T07:38:20 Z alvingogo Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
659 ms 32364 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;

struct BIT{
	int n;
	vector<int> bt;
	void init(int x){
		n=x;
		bt.resize(n+1);
	}
	void update(int x,int y){
		x++;
		for(;x>0;x-=(x&-x)){
			bt[x]=max(bt[x],y);
		}
	}
	int query(int x){
		x++;
		int ans=0;
		for(;x<=n;x+=(x&-x)){
			ans=max(ans,bt[x]);
		}
		return ans;
	}
}bt;
struct QU{
	int l,r,k;
	int id;
};
bool cmp(QU a,QU b){
	return a.r<b.r;
}
int main(){
    AquA;
	int n,m;
	cin >> n >> m;
	bt.init(n);
	vector<int> v(n);
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	vector<QU> vq(m);
	vector<int> ans(m);
	for(int i=0;i<m;i++){
		cin >> vq[i].l >> vq[i].r >> vq[i].k;
		vq[i].l--;
		vq[i].r--;
		vq[i].id=i;
	}
	sort(vq.begin(),vq.end(),cmp);
	int r=0;
	vector<int> s;
	for(int i=0;i<n;i++){
		while(s.size() && v[s.back()]<=v[i]){
			s.pop_back();
		}
		if(s.size()){
			bt.update(s.back(),v[s.back()]+v[i]);
		}
		s.push_back(i);
		while(r<m && vq[r].r==i){
			if(bt.query(vq[r].l)<=vq[r].k){
				ans[vq[r].id]=1;
			}
			r++;
		}
	}
	for(int i=0;i<m;i++){
		cout << ans[i] << "\n";
	}
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 3 ms 456 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 4 ms 608 KB Output is correct
15 Correct 4 ms 596 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 3 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 598 ms 29688 KB Output is correct
2 Correct 609 ms 29620 KB Output is correct
3 Correct 611 ms 29636 KB Output is correct
4 Correct 644 ms 29640 KB Output is correct
5 Correct 583 ms 29636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 3240 KB Output is correct
2 Correct 51 ms 4556 KB Output is correct
3 Correct 50 ms 4608 KB Output is correct
4 Correct 51 ms 4556 KB Output is correct
5 Correct 53 ms 4656 KB Output is correct
6 Correct 46 ms 4536 KB Output is correct
7 Correct 51 ms 4536 KB Output is correct
8 Correct 49 ms 4720 KB Output is correct
9 Correct 36 ms 3676 KB Output is correct
10 Correct 48 ms 4656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 3 ms 456 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 4 ms 608 KB Output is correct
15 Correct 4 ms 596 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 3 ms 436 KB Output is correct
19 Correct 125 ms 9004 KB Output is correct
20 Correct 145 ms 9000 KB Output is correct
21 Correct 128 ms 7512 KB Output is correct
22 Correct 121 ms 7500 KB Output is correct
23 Correct 127 ms 7616 KB Output is correct
24 Correct 144 ms 7596 KB Output is correct
25 Correct 109 ms 7608 KB Output is correct
26 Correct 126 ms 7596 KB Output is correct
27 Correct 130 ms 7544 KB Output is correct
28 Correct 117 ms 7684 KB Output is correct
29 Correct 115 ms 7608 KB Output is correct
30 Correct 118 ms 7596 KB Output is correct
31 Correct 145 ms 7600 KB Output is correct
32 Correct 113 ms 7508 KB Output is correct
33 Correct 114 ms 7592 KB Output is correct
34 Correct 126 ms 7564 KB Output is correct
35 Correct 118 ms 7692 KB Output is correct
36 Correct 109 ms 7592 KB Output is correct
37 Correct 106 ms 7552 KB Output is correct
38 Correct 141 ms 7540 KB Output is correct
39 Correct 108 ms 7584 KB Output is correct
40 Correct 91 ms 7072 KB Output is correct
41 Correct 107 ms 7588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 3 ms 456 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 4 ms 608 KB Output is correct
15 Correct 4 ms 596 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 3 ms 436 KB Output is correct
19 Correct 598 ms 29688 KB Output is correct
20 Correct 609 ms 29620 KB Output is correct
21 Correct 611 ms 29636 KB Output is correct
22 Correct 644 ms 29640 KB Output is correct
23 Correct 583 ms 29636 KB Output is correct
24 Correct 49 ms 3240 KB Output is correct
25 Correct 51 ms 4556 KB Output is correct
26 Correct 50 ms 4608 KB Output is correct
27 Correct 51 ms 4556 KB Output is correct
28 Correct 53 ms 4656 KB Output is correct
29 Correct 46 ms 4536 KB Output is correct
30 Correct 51 ms 4536 KB Output is correct
31 Correct 49 ms 4720 KB Output is correct
32 Correct 36 ms 3676 KB Output is correct
33 Correct 48 ms 4656 KB Output is correct
34 Correct 125 ms 9004 KB Output is correct
35 Correct 145 ms 9000 KB Output is correct
36 Correct 128 ms 7512 KB Output is correct
37 Correct 121 ms 7500 KB Output is correct
38 Correct 127 ms 7616 KB Output is correct
39 Correct 144 ms 7596 KB Output is correct
40 Correct 109 ms 7608 KB Output is correct
41 Correct 126 ms 7596 KB Output is correct
42 Correct 130 ms 7544 KB Output is correct
43 Correct 117 ms 7684 KB Output is correct
44 Correct 115 ms 7608 KB Output is correct
45 Correct 118 ms 7596 KB Output is correct
46 Correct 145 ms 7600 KB Output is correct
47 Correct 113 ms 7508 KB Output is correct
48 Correct 114 ms 7592 KB Output is correct
49 Correct 126 ms 7564 KB Output is correct
50 Correct 118 ms 7692 KB Output is correct
51 Correct 109 ms 7592 KB Output is correct
52 Correct 106 ms 7552 KB Output is correct
53 Correct 141 ms 7540 KB Output is correct
54 Correct 108 ms 7584 KB Output is correct
55 Correct 91 ms 7072 KB Output is correct
56 Correct 107 ms 7588 KB Output is correct
57 Correct 630 ms 31256 KB Output is correct
58 Correct 659 ms 31128 KB Output is correct
59 Correct 609 ms 31184 KB Output is correct
60 Correct 617 ms 31184 KB Output is correct
61 Correct 621 ms 30888 KB Output is correct
62 Correct 614 ms 30964 KB Output is correct
63 Correct 575 ms 30712 KB Output is correct
64 Correct 621 ms 30708 KB Output is correct
65 Correct 591 ms 30860 KB Output is correct
66 Correct 583 ms 30716 KB Output is correct
67 Correct 589 ms 30704 KB Output is correct
68 Correct 620 ms 30708 KB Output is correct
69 Correct 603 ms 30584 KB Output is correct
70 Correct 618 ms 32364 KB Output is correct
71 Correct 589 ms 30620 KB Output is correct
72 Correct 597 ms 30552 KB Output is correct
73 Correct 557 ms 30472 KB Output is correct
74 Correct 558 ms 30528 KB Output is correct
75 Correct 546 ms 30440 KB Output is correct
76 Correct 577 ms 30964 KB Output is correct
77 Correct 571 ms 30636 KB Output is correct
78 Correct 547 ms 30280 KB Output is correct
79 Correct 469 ms 26292 KB Output is correct
80 Correct 632 ms 30008 KB Output is correct