Submission #467989

# Submission time Handle Problem Language Result Execution time Memory
467989 2021-08-25T19:50:17 Z starplat Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1839 ms 84204 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define f first
#define s second
#define pll pair<ll,ll>
using namespace std;
ll n,m,w[(int)2e6+5],pos,val;
ll t[(int)(2e6+5)<<2],ans[(int)2e6+5];
vector<pll> v;
deque<int> q;
struct query{
	ll l,r,k,pos;
}e[(int)2e6+5];
bool s3(query a,query b)
{
	return a.l>b.l;
}
bool s1(pll a,pll b)
{
	return a.s>b.s;
}
bool s2(query a,query b)
{
	return a.pos<b.pos;
}
void update(int id,int x,int y,int tar,ll v)
{
	if (x==y){
		t[id]=max(t[id],v);
	}
	else {
		int mid=(x+y)/2;
		if (tar<=mid) update(id*2,x,mid,tar,v);
		else update(id*2+1,mid+1,y,tar,v);
		t[id]=max(t[id*2],t[id*2+1]);
	}
}
ll answer(int id,int x,int y,int lo,int hi)
{
	if (x>y||x>hi||y<lo) return 0;
	if (lo<=x&&y<=hi) return t[id];
	else {
		int mid=(x+y)/2;
		return max(answer(id*2,x,mid,lo,hi),answer(id*2+1,mid+1,y,lo,hi));
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for (int i=1;i<=n;i++) cin>>w[i];
	q.pb(1);
	for (int i=2;i<=n;i++){
		while (!q.empty()){
			if (w[q.back()]<=w[i]) q.pop_back();
			else break;
		}
		if (!q.empty()) v.pb({i,q.back()});
		q.pb(i);
	}
	sort(v.begin(),v.end(),s1);
//	for (pll i:v) cout<<i.f<<" "<<i.s<<"\n";
	for (int i=0;i<m;i++) cin>>e[i].l>>e[i].r>>e[i].k,e[i].pos=i;
	sort(e,e+m,s3);
	int ptr=0,mx=v.size();
	for (int i=0;i<m;i++){
		while(ptr<mx && e[i].l<=v[ptr].s){
			//cout<<e[i].l<<" "<<v[ptr].f<<" "<<v[ptr].s<<"\n";
			update(1,1,n,v[ptr].f,w[v[ptr].f]+w[v[ptr].s]);
			++ptr;
		}
		//cout<<e[i].l<<" ";
		//cout<<answer(1,1,n,e[i].l,e[i].r)<<"\n";
		if (answer(1,1,n,e[i].l,e[i].r)<=e[i].k) ans[e[i].pos]=1;
		else ans[e[i].pos]=0;
	}
	for (int i=0;i<m;i++) cout<<ans[i]<<"\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 380 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 380 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 4 ms 716 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 6 ms 840 KB Output is correct
15 Correct 8 ms 844 KB Output is correct
16 Correct 6 ms 708 KB Output is correct
17 Correct 4 ms 588 KB Output is correct
18 Correct 6 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1772 ms 82672 KB Output is correct
2 Correct 1839 ms 83788 KB Output is correct
3 Correct 1753 ms 83792 KB Output is correct
4 Correct 1788 ms 83644 KB Output is correct
5 Correct 1365 ms 51648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 8872 KB Output is correct
2 Correct 136 ms 8908 KB Output is correct
3 Correct 106 ms 5172 KB Output is correct
4 Correct 104 ms 5148 KB Output is correct
5 Correct 104 ms 5188 KB Output is correct
6 Correct 96 ms 5736 KB Output is correct
7 Correct 110 ms 5708 KB Output is correct
8 Correct 108 ms 7896 KB Output is correct
9 Correct 58 ms 4348 KB Output is correct
10 Correct 104 ms 7448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 380 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 4 ms 716 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 6 ms 840 KB Output is correct
15 Correct 8 ms 844 KB Output is correct
16 Correct 6 ms 708 KB Output is correct
17 Correct 4 ms 588 KB Output is correct
18 Correct 6 ms 716 KB Output is correct
19 Correct 329 ms 17508 KB Output is correct
20 Correct 328 ms 17456 KB Output is correct
21 Correct 290 ms 17484 KB Output is correct
22 Correct 294 ms 17504 KB Output is correct
23 Correct 299 ms 17424 KB Output is correct
24 Correct 239 ms 10108 KB Output is correct
25 Correct 225 ms 10124 KB Output is correct
26 Correct 236 ms 10052 KB Output is correct
27 Correct 260 ms 10152 KB Output is correct
28 Correct 254 ms 10108 KB Output is correct
29 Correct 241 ms 10104 KB Output is correct
30 Correct 243 ms 10080 KB Output is correct
31 Correct 257 ms 10232 KB Output is correct
32 Correct 240 ms 10180 KB Output is correct
33 Correct 237 ms 10096 KB Output is correct
34 Correct 217 ms 10156 KB Output is correct
35 Correct 217 ms 10164 KB Output is correct
36 Correct 236 ms 10052 KB Output is correct
37 Correct 206 ms 10052 KB Output is correct
38 Correct 213 ms 10120 KB Output is correct
39 Correct 238 ms 12688 KB Output is correct
40 Correct 174 ms 10688 KB Output is correct
41 Correct 239 ms 14388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 380 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 4 ms 716 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 6 ms 840 KB Output is correct
15 Correct 8 ms 844 KB Output is correct
16 Correct 6 ms 708 KB Output is correct
17 Correct 4 ms 588 KB Output is correct
18 Correct 6 ms 716 KB Output is correct
19 Correct 1772 ms 82672 KB Output is correct
20 Correct 1839 ms 83788 KB Output is correct
21 Correct 1753 ms 83792 KB Output is correct
22 Correct 1788 ms 83644 KB Output is correct
23 Correct 1365 ms 51648 KB Output is correct
24 Correct 134 ms 8872 KB Output is correct
25 Correct 136 ms 8908 KB Output is correct
26 Correct 106 ms 5172 KB Output is correct
27 Correct 104 ms 5148 KB Output is correct
28 Correct 104 ms 5188 KB Output is correct
29 Correct 96 ms 5736 KB Output is correct
30 Correct 110 ms 5708 KB Output is correct
31 Correct 108 ms 7896 KB Output is correct
32 Correct 58 ms 4348 KB Output is correct
33 Correct 104 ms 7448 KB Output is correct
34 Correct 329 ms 17508 KB Output is correct
35 Correct 328 ms 17456 KB Output is correct
36 Correct 290 ms 17484 KB Output is correct
37 Correct 294 ms 17504 KB Output is correct
38 Correct 299 ms 17424 KB Output is correct
39 Correct 239 ms 10108 KB Output is correct
40 Correct 225 ms 10124 KB Output is correct
41 Correct 236 ms 10052 KB Output is correct
42 Correct 260 ms 10152 KB Output is correct
43 Correct 254 ms 10108 KB Output is correct
44 Correct 241 ms 10104 KB Output is correct
45 Correct 243 ms 10080 KB Output is correct
46 Correct 257 ms 10232 KB Output is correct
47 Correct 240 ms 10180 KB Output is correct
48 Correct 237 ms 10096 KB Output is correct
49 Correct 217 ms 10156 KB Output is correct
50 Correct 217 ms 10164 KB Output is correct
51 Correct 236 ms 10052 KB Output is correct
52 Correct 206 ms 10052 KB Output is correct
53 Correct 213 ms 10120 KB Output is correct
54 Correct 238 ms 12688 KB Output is correct
55 Correct 174 ms 10688 KB Output is correct
56 Correct 239 ms 14388 KB Output is correct
57 Correct 1819 ms 84204 KB Output is correct
58 Correct 1812 ms 84000 KB Output is correct
59 Correct 1814 ms 83924 KB Output is correct
60 Correct 1777 ms 83860 KB Output is correct
61 Correct 1733 ms 84060 KB Output is correct
62 Correct 1728 ms 83980 KB Output is correct
63 Correct 1250 ms 51368 KB Output is correct
64 Correct 1279 ms 51416 KB Output is correct
65 Correct 1362 ms 51720 KB Output is correct
66 Correct 1366 ms 51688 KB Output is correct
67 Correct 1416 ms 51632 KB Output is correct
68 Correct 1339 ms 51800 KB Output is correct
69 Correct 1401 ms 51760 KB Output is correct
70 Correct 1391 ms 51764 KB Output is correct
71 Correct 1351 ms 51656 KB Output is correct
72 Correct 1375 ms 51760 KB Output is correct
73 Correct 1146 ms 51416 KB Output is correct
74 Correct 1198 ms 51400 KB Output is correct
75 Correct 1182 ms 51336 KB Output is correct
76 Correct 1204 ms 51424 KB Output is correct
77 Correct 1148 ms 51340 KB Output is correct
78 Correct 1277 ms 62176 KB Output is correct
79 Correct 966 ms 51736 KB Output is correct
80 Correct 1366 ms 74156 KB Output is correct