Submission #652133

# Submission time Handle Problem Language Result Execution time Memory
652133 2022-10-21T11:58:47 Z peter940324 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1137 ms 77972 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pii pair<int,int>
#define ff first
#define ss second
#define mp make_pair

#define pb push_back
#define pf push_front
#define all(x) x.begin(),x.end()

#define de(x) cout << #x << ' ' << x << '\n';
template<class T> void prt(T l,T r){
  while(l!=r) cout << *l << ' ',l++;
  cout << '\n';
}

const int N=1e6+5,M=1e9+7,INF=1e18;

struct qr{
	int l,r,k,i,ans;
};

struct SegTree{
	int a[4*N]{0};
	void mod(int l,int r,int cur,int ind,int val){
		if(r-l<=1){
			a[cur]=val;
			return;
		}
		int mid=(l+r)/2;
		if(ind<mid) mod(l,mid,cur*2,ind,val);
		else mod(mid,r,cur*2+1,ind,val);
		a[cur]=max(a[cur*2],a[cur*2+1]);
	}
	int qry(int l,int r,int cur,int ql,int qr){
		if(ql>=r||qr<=l) return 0;
		if(ql<=l&&qr>=r) return a[cur];
		int mid=(l+r)/2;
		return max(qry(l,mid,cur*2,ql,qr),qry(mid,r,cur*2+1,ql,qr));
	}
}sgt;

signed main(){
  IO
	int n,m;cin >> n >> m;
	vector<int> a(n+1);
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	vector<qr> Q(m);
	for(int i=0;i<m;i++){
		cin >> Q[i].l >> Q[i].r >> Q[i].k;
		Q[i].i=i;
	}
	sort(all(Q),[](qr aa,qr bb){
		return aa.r<bb.r;
	});
	int ind=0;
	stack<int> st;
	for(int i=0;i<m;i++){
		while(ind<=Q[i].r){
			while(!st.empty()&&a[ind]>=a[st.top()]) st.pop();
			if(!st.empty()){
				sgt.mod(1,n+1,1,st.top(),a[ind]+a[st.top()]);
			}
			st.push(ind);
			ind++;
		}
		int mx=sgt.qry(1,n+1,1,Q[i].l,Q[i].r+1);
		if(mx>Q[i].k) Q[i].ans=0;
		else Q[i].ans=1;
	}
	sort(all(Q),[](qr aa,qr bb){
		return aa.i<bb.i;
	});
	for(int i=0;i<m;i++){
		cout << Q[i].ans << '\n';
	}
  return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 4 ms 724 KB Output is correct
14 Correct 5 ms 856 KB Output is correct
15 Correct 6 ms 848 KB Output is correct
16 Correct 6 ms 680 KB Output is correct
17 Correct 4 ms 596 KB Output is correct
18 Correct 3 ms 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1103 ms 65748 KB Output is correct
2 Correct 1049 ms 67140 KB Output is correct
3 Correct 1072 ms 67404 KB Output is correct
4 Correct 1055 ms 67168 KB Output is correct
5 Correct 934 ms 49336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 8756 KB Output is correct
2 Correct 88 ms 9100 KB Output is correct
3 Correct 97 ms 7124 KB Output is correct
4 Correct 76 ms 7092 KB Output is correct
5 Correct 77 ms 7116 KB Output is correct
6 Correct 69 ms 6976 KB Output is correct
7 Correct 77 ms 7028 KB Output is correct
8 Correct 72 ms 6936 KB Output is correct
9 Correct 44 ms 5652 KB Output is correct
10 Correct 74 ms 6952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 4 ms 724 KB Output is correct
14 Correct 5 ms 856 KB Output is correct
15 Correct 6 ms 848 KB Output is correct
16 Correct 6 ms 680 KB Output is correct
17 Correct 4 ms 596 KB Output is correct
18 Correct 3 ms 608 KB Output is correct
19 Correct 234 ms 20736 KB Output is correct
20 Correct 194 ms 20700 KB Output is correct
21 Correct 189 ms 20624 KB Output is correct
22 Correct 192 ms 20584 KB Output is correct
23 Correct 194 ms 20620 KB Output is correct
24 Correct 163 ms 16412 KB Output is correct
25 Correct 167 ms 16492 KB Output is correct
26 Correct 189 ms 16612 KB Output is correct
27 Correct 180 ms 16612 KB Output is correct
28 Correct 187 ms 16640 KB Output is correct
29 Correct 183 ms 16720 KB Output is correct
30 Correct 183 ms 16616 KB Output is correct
31 Correct 176 ms 16708 KB Output is correct
32 Correct 182 ms 16720 KB Output is correct
33 Correct 173 ms 16700 KB Output is correct
34 Correct 164 ms 16348 KB Output is correct
35 Correct 153 ms 16356 KB Output is correct
36 Correct 154 ms 16116 KB Output is correct
37 Correct 196 ms 16084 KB Output is correct
38 Correct 157 ms 16460 KB Output is correct
39 Correct 156 ms 16752 KB Output is correct
40 Correct 125 ms 14028 KB Output is correct
41 Correct 198 ms 14800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 4 ms 724 KB Output is correct
14 Correct 5 ms 856 KB Output is correct
15 Correct 6 ms 848 KB Output is correct
16 Correct 6 ms 680 KB Output is correct
17 Correct 4 ms 596 KB Output is correct
18 Correct 3 ms 608 KB Output is correct
19 Correct 1103 ms 65748 KB Output is correct
20 Correct 1049 ms 67140 KB Output is correct
21 Correct 1072 ms 67404 KB Output is correct
22 Correct 1055 ms 67168 KB Output is correct
23 Correct 934 ms 49336 KB Output is correct
24 Correct 87 ms 8756 KB Output is correct
25 Correct 88 ms 9100 KB Output is correct
26 Correct 97 ms 7124 KB Output is correct
27 Correct 76 ms 7092 KB Output is correct
28 Correct 77 ms 7116 KB Output is correct
29 Correct 69 ms 6976 KB Output is correct
30 Correct 77 ms 7028 KB Output is correct
31 Correct 72 ms 6936 KB Output is correct
32 Correct 44 ms 5652 KB Output is correct
33 Correct 74 ms 6952 KB Output is correct
34 Correct 234 ms 20736 KB Output is correct
35 Correct 194 ms 20700 KB Output is correct
36 Correct 189 ms 20624 KB Output is correct
37 Correct 192 ms 20584 KB Output is correct
38 Correct 194 ms 20620 KB Output is correct
39 Correct 163 ms 16412 KB Output is correct
40 Correct 167 ms 16492 KB Output is correct
41 Correct 189 ms 16612 KB Output is correct
42 Correct 180 ms 16612 KB Output is correct
43 Correct 187 ms 16640 KB Output is correct
44 Correct 183 ms 16720 KB Output is correct
45 Correct 183 ms 16616 KB Output is correct
46 Correct 176 ms 16708 KB Output is correct
47 Correct 182 ms 16720 KB Output is correct
48 Correct 173 ms 16700 KB Output is correct
49 Correct 164 ms 16348 KB Output is correct
50 Correct 153 ms 16356 KB Output is correct
51 Correct 154 ms 16116 KB Output is correct
52 Correct 196 ms 16084 KB Output is correct
53 Correct 157 ms 16460 KB Output is correct
54 Correct 156 ms 16752 KB Output is correct
55 Correct 125 ms 14028 KB Output is correct
56 Correct 198 ms 14800 KB Output is correct
57 Correct 1137 ms 77528 KB Output is correct
58 Correct 1123 ms 77556 KB Output is correct
59 Correct 1054 ms 77972 KB Output is correct
60 Correct 1045 ms 77780 KB Output is correct
61 Correct 1065 ms 77860 KB Output is correct
62 Correct 999 ms 77920 KB Output is correct
63 Correct 817 ms 60852 KB Output is correct
64 Correct 831 ms 60980 KB Output is correct
65 Correct 876 ms 61256 KB Output is correct
66 Correct 891 ms 61340 KB Output is correct
67 Correct 864 ms 61224 KB Output is correct
68 Correct 895 ms 61408 KB Output is correct
69 Correct 891 ms 61388 KB Output is correct
70 Correct 868 ms 60952 KB Output is correct
71 Correct 871 ms 59028 KB Output is correct
72 Correct 871 ms 58844 KB Output is correct
73 Correct 757 ms 58956 KB Output is correct
74 Correct 803 ms 59140 KB Output is correct
75 Correct 767 ms 58868 KB Output is correct
76 Correct 745 ms 57552 KB Output is correct
77 Correct 778 ms 56752 KB Output is correct
78 Correct 787 ms 61340 KB Output is correct
79 Correct 630 ms 54572 KB Output is correct
80 Correct 779 ms 55600 KB Output is correct