Submission #1072221

# Submission time Handle Problem Language Result Execution time Memory
1072221 2024-08-23T15:42:48 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1262 ms 140976 KB
#include <bits/stdc++.h>
#define int long long
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout)
const int N=1e6+1;
const int inf=1e18;
const int mod=1e9+7;
using namespace std;
struct edge{
	int l,k,id;
};
vector<edge>v1[N];
vector<int>v;
int t[4*N];
void upd(int n,int tl,int tr,int pos,int x){
	if(tl==tr){
		t[n]=x;
		return;
	}
	int mid=(tl+tr)/2;
	if(pos<=mid){
		upd(n*2,tl,mid,pos,x);
	}else{
		upd(n*2+1,mid+1,tr,pos,x);
	}
	t[n]=max(t[n*2],t[n*2+1]);
}
int get(int n,int tl,int tr,int l,int r){
	if(tr<l||r<tl){
		return 0;
	}
	if(l<=tl&&tr<=r){
		return t[n];
	}
	int mid=(tl+tr)/2;
	return max(get(n*2,tl,mid,l,r),get(n*2+1,mid+1,tr,l,r));
}
stack<int >st;
int pos[N];
int ans[N];
signed main(){
	boost;
	int n,m;
	cin>>n>>m;
	v.push_back(0);
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		v.push_back(x);
	}
	for(int i=1;i<=n;i++){
		while(st.size()>0&&v[st.top()]<=v[i]){
			st.pop();
		}
		if(st.size()>0){
			pos[i]=st.top();
		}
		st.push(i);
	}
	for(int i=1;i<=m;i++){
		int l,r,k;
		cin>>l>>r>>k;
		edge x;
		x.l=l;
		x.k=k;
		x.id=i;
		v1[r].push_back(x);
	}
	for(int i=1;i<=n;i++){
		if(pos[i]>0){
			int y=v[pos[i]];
			upd(1,1,n,pos[i],y+v[i]);
		}
	for(int j=0;j<v1[i].size();j++){
		ans[v1[i][j].id]=(get(1,1,n,v1[i][j].l,i)<=v1[i][j].k);
	}	
	st.push(i);
	}
	for(int i=1;i<=m;i++){
		cout<<ans[i]<<"\n";
	}
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:74:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |  for(int j=0;j<v1[i].size();j++){
      |              ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 25432 KB Output is correct
2 Correct 9 ms 25436 KB Output is correct
3 Correct 9 ms 23920 KB Output is correct
4 Correct 14 ms 23900 KB Output is correct
5 Correct 9 ms 23900 KB Output is correct
6 Correct 11 ms 25436 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 10 ms 23896 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 12 ms 25600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 25432 KB Output is correct
2 Correct 9 ms 25436 KB Output is correct
3 Correct 9 ms 23920 KB Output is correct
4 Correct 14 ms 23900 KB Output is correct
5 Correct 9 ms 23900 KB Output is correct
6 Correct 11 ms 25436 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 10 ms 23896 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 12 ms 25600 KB Output is correct
11 Correct 10 ms 24156 KB Output is correct
12 Correct 13 ms 24412 KB Output is correct
13 Correct 13 ms 25948 KB Output is correct
14 Correct 15 ms 26204 KB Output is correct
15 Correct 18 ms 24412 KB Output is correct
16 Correct 14 ms 24412 KB Output is correct
17 Correct 13 ms 24156 KB Output is correct
18 Correct 12 ms 25944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1203 ms 124052 KB Output is correct
2 Correct 1234 ms 122992 KB Output is correct
3 Correct 1262 ms 123136 KB Output is correct
4 Correct 1217 ms 123104 KB Output is correct
5 Correct 990 ms 98824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 35480 KB Output is correct
2 Correct 99 ms 36396 KB Output is correct
3 Correct 74 ms 33228 KB Output is correct
4 Correct 69 ms 33468 KB Output is correct
5 Correct 73 ms 31692 KB Output is correct
6 Correct 55 ms 31436 KB Output is correct
7 Correct 55 ms 33232 KB Output is correct
8 Correct 92 ms 31684 KB Output is correct
9 Correct 56 ms 29188 KB Output is correct
10 Correct 64 ms 33220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 25432 KB Output is correct
2 Correct 9 ms 25436 KB Output is correct
3 Correct 9 ms 23920 KB Output is correct
4 Correct 14 ms 23900 KB Output is correct
5 Correct 9 ms 23900 KB Output is correct
6 Correct 11 ms 25436 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 10 ms 23896 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 12 ms 25600 KB Output is correct
11 Correct 10 ms 24156 KB Output is correct
12 Correct 13 ms 24412 KB Output is correct
13 Correct 13 ms 25948 KB Output is correct
14 Correct 15 ms 26204 KB Output is correct
15 Correct 18 ms 24412 KB Output is correct
16 Correct 14 ms 24412 KB Output is correct
17 Correct 13 ms 24156 KB Output is correct
18 Correct 12 ms 25944 KB Output is correct
19 Correct 179 ms 47812 KB Output is correct
20 Correct 179 ms 49564 KB Output is correct
21 Correct 155 ms 49860 KB Output is correct
22 Correct 161 ms 48328 KB Output is correct
23 Correct 158 ms 48264 KB Output is correct
24 Correct 128 ms 44188 KB Output is correct
25 Correct 159 ms 44232 KB Output is correct
26 Correct 160 ms 43980 KB Output is correct
27 Correct 148 ms 43972 KB Output is correct
28 Correct 171 ms 42184 KB Output is correct
29 Correct 161 ms 43796 KB Output is correct
30 Correct 175 ms 43792 KB Output is correct
31 Correct 174 ms 43760 KB Output is correct
32 Correct 165 ms 42180 KB Output is correct
33 Correct 144 ms 42232 KB Output is correct
34 Correct 155 ms 41312 KB Output is correct
35 Correct 154 ms 41416 KB Output is correct
36 Correct 126 ms 41164 KB Output is correct
37 Correct 122 ms 41156 KB Output is correct
38 Correct 124 ms 41412 KB Output is correct
39 Correct 145 ms 42188 KB Output is correct
40 Correct 106 ms 38336 KB Output is correct
41 Correct 147 ms 40636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 25432 KB Output is correct
2 Correct 9 ms 25436 KB Output is correct
3 Correct 9 ms 23920 KB Output is correct
4 Correct 14 ms 23900 KB Output is correct
5 Correct 9 ms 23900 KB Output is correct
6 Correct 11 ms 25436 KB Output is correct
7 Correct 10 ms 23900 KB Output is correct
8 Correct 10 ms 23896 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 12 ms 25600 KB Output is correct
11 Correct 10 ms 24156 KB Output is correct
12 Correct 13 ms 24412 KB Output is correct
13 Correct 13 ms 25948 KB Output is correct
14 Correct 15 ms 26204 KB Output is correct
15 Correct 18 ms 24412 KB Output is correct
16 Correct 14 ms 24412 KB Output is correct
17 Correct 13 ms 24156 KB Output is correct
18 Correct 12 ms 25944 KB Output is correct
19 Correct 1203 ms 124052 KB Output is correct
20 Correct 1234 ms 122992 KB Output is correct
21 Correct 1262 ms 123136 KB Output is correct
22 Correct 1217 ms 123104 KB Output is correct
23 Correct 990 ms 98824 KB Output is correct
24 Correct 98 ms 35480 KB Output is correct
25 Correct 99 ms 36396 KB Output is correct
26 Correct 74 ms 33228 KB Output is correct
27 Correct 69 ms 33468 KB Output is correct
28 Correct 73 ms 31692 KB Output is correct
29 Correct 55 ms 31436 KB Output is correct
30 Correct 55 ms 33232 KB Output is correct
31 Correct 92 ms 31684 KB Output is correct
32 Correct 56 ms 29188 KB Output is correct
33 Correct 64 ms 33220 KB Output is correct
34 Correct 179 ms 47812 KB Output is correct
35 Correct 179 ms 49564 KB Output is correct
36 Correct 155 ms 49860 KB Output is correct
37 Correct 161 ms 48328 KB Output is correct
38 Correct 158 ms 48264 KB Output is correct
39 Correct 128 ms 44188 KB Output is correct
40 Correct 159 ms 44232 KB Output is correct
41 Correct 160 ms 43980 KB Output is correct
42 Correct 148 ms 43972 KB Output is correct
43 Correct 171 ms 42184 KB Output is correct
44 Correct 161 ms 43796 KB Output is correct
45 Correct 175 ms 43792 KB Output is correct
46 Correct 174 ms 43760 KB Output is correct
47 Correct 165 ms 42180 KB Output is correct
48 Correct 144 ms 42232 KB Output is correct
49 Correct 155 ms 41312 KB Output is correct
50 Correct 154 ms 41416 KB Output is correct
51 Correct 126 ms 41164 KB Output is correct
52 Correct 122 ms 41156 KB Output is correct
53 Correct 124 ms 41412 KB Output is correct
54 Correct 145 ms 42188 KB Output is correct
55 Correct 106 ms 38336 KB Output is correct
56 Correct 147 ms 40636 KB Output is correct
57 Correct 1217 ms 140012 KB Output is correct
58 Correct 1248 ms 139996 KB Output is correct
59 Correct 1097 ms 140940 KB Output is correct
60 Correct 1038 ms 140976 KB Output is correct
61 Correct 1143 ms 140640 KB Output is correct
62 Correct 1123 ms 140944 KB Output is correct
63 Correct 677 ms 114820 KB Output is correct
64 Correct 718 ms 114864 KB Output is correct
65 Correct 952 ms 116908 KB Output is correct
66 Correct 884 ms 116796 KB Output is correct
67 Correct 921 ms 117012 KB Output is correct
68 Correct 975 ms 115964 KB Output is correct
69 Correct 982 ms 115676 KB Output is correct
70 Correct 894 ms 116136 KB Output is correct
71 Correct 959 ms 116148 KB Output is correct
72 Correct 991 ms 116148 KB Output is correct
73 Correct 630 ms 106068 KB Output is correct
74 Correct 608 ms 109224 KB Output is correct
75 Correct 609 ms 106192 KB Output is correct
76 Correct 654 ms 106164 KB Output is correct
77 Correct 603 ms 105904 KB Output is correct
78 Correct 953 ms 115360 KB Output is correct
79 Correct 620 ms 93492 KB Output is correct
80 Correct 788 ms 109216 KB Output is correct