Submission #1040431

# Submission time Handle Problem Language Result Execution time Memory
1040431 2024-08-01T03:56:49 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
860 ms 107316 KB
#include<bits/stdc++.h>
using namespace std;
long long n,q,a[2000001],t[8000004];
long long k;
bool kt;
void build(long long id ,long long l,long long r)
{
	if(l==r)
	{
		t[id]=a[l];
		return;
	}
	long long mid=(l+r)/2;
	build(id*2,l,mid);
	build(id*2+1,mid+1,r);
	t[id]=max(t[id*2],t[id*2+1]);
}
void update(long long id,long long l,long long r,long long pos,long long w)
{
	if(l>pos||pos>r) return ;
	if(l==r)
	{
		t[id]=max(t[id],w);
		return;
	}
	long long mid=(l+r)/2;
	update(id*2,l,mid,pos,w);
	update(id*2+1,mid+1,r,pos,w);
	t[id]=max(t[id*2],t[id*2+1]);
}
long long get_max(long long id,long long l,long long r,long long u,long long v)
{
	if(l>v||r<u) return -1000000009;
	if(u<=l&&r<=v)
	{
		return t[id];
	}
	long long mid=(l+r)/2;
	return max(get_max(id*2,l,mid,u,v),get_max(id*2+1,mid+1,r,u,v));
}
vector<pair<int,pair<int,int>>> eve[2000005]; 
long long ans[2000005];
int main() 
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>q;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=q;i++)
	{
		long long l,r,k;
		cin>>l>>r>>k;
		eve[r].push_back({i,{l,k}});
	}
	stack<int> st;
	for(int i=1;i<=n;i++)
	{
		while(!st.empty()&&a[st.top()]<=a[i]) st.pop();
		if(st.size()) update(1,1,n,st.top(),a[st.top()]+a[i]);
		st.push(i);
		for(auto x:eve[i])
		{
			long long id=x.first,l=x.second.first,k=x.second.second;
			if(get_max(1,1,n,l,i)<=k) ans[id]=1;
			else ans[id]=0;
		}
	}
	for(int i=1;i<=q;i++)
	{
		cout<<ans[i]<<"\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 51548 KB Output is correct
2 Correct 7 ms 51760 KB Output is correct
3 Correct 7 ms 51784 KB Output is correct
4 Correct 7 ms 51548 KB Output is correct
5 Correct 7 ms 51636 KB Output is correct
6 Correct 7 ms 51548 KB Output is correct
7 Correct 7 ms 51548 KB Output is correct
8 Correct 8 ms 51548 KB Output is correct
9 Correct 7 ms 51688 KB Output is correct
10 Correct 7 ms 51784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 51548 KB Output is correct
2 Correct 7 ms 51760 KB Output is correct
3 Correct 7 ms 51784 KB Output is correct
4 Correct 7 ms 51548 KB Output is correct
5 Correct 7 ms 51636 KB Output is correct
6 Correct 7 ms 51548 KB Output is correct
7 Correct 7 ms 51548 KB Output is correct
8 Correct 8 ms 51548 KB Output is correct
9 Correct 7 ms 51688 KB Output is correct
10 Correct 7 ms 51784 KB Output is correct
11 Correct 8 ms 51804 KB Output is correct
12 Correct 9 ms 51804 KB Output is correct
13 Correct 9 ms 51696 KB Output is correct
14 Correct 9 ms 51804 KB Output is correct
15 Correct 10 ms 51804 KB Output is correct
16 Correct 9 ms 51804 KB Output is correct
17 Correct 9 ms 51804 KB Output is correct
18 Correct 9 ms 51800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 860 ms 107304 KB Output is correct
2 Correct 808 ms 107092 KB Output is correct
3 Correct 807 ms 107316 KB Output is correct
4 Correct 793 ms 107092 KB Output is correct
5 Correct 638 ms 91992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 58992 KB Output is correct
2 Correct 57 ms 58796 KB Output is correct
3 Correct 52 ms 58196 KB Output is correct
4 Correct 57 ms 58196 KB Output is correct
5 Correct 57 ms 58288 KB Output is correct
6 Correct 43 ms 57688 KB Output is correct
7 Correct 44 ms 57940 KB Output is correct
8 Correct 49 ms 58120 KB Output is correct
9 Correct 28 ms 55564 KB Output is correct
10 Correct 48 ms 58124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 51548 KB Output is correct
2 Correct 7 ms 51760 KB Output is correct
3 Correct 7 ms 51784 KB Output is correct
4 Correct 7 ms 51548 KB Output is correct
5 Correct 7 ms 51636 KB Output is correct
6 Correct 7 ms 51548 KB Output is correct
7 Correct 7 ms 51548 KB Output is correct
8 Correct 8 ms 51548 KB Output is correct
9 Correct 7 ms 51688 KB Output is correct
10 Correct 7 ms 51784 KB Output is correct
11 Correct 8 ms 51804 KB Output is correct
12 Correct 9 ms 51804 KB Output is correct
13 Correct 9 ms 51696 KB Output is correct
14 Correct 9 ms 51804 KB Output is correct
15 Correct 10 ms 51804 KB Output is correct
16 Correct 9 ms 51804 KB Output is correct
17 Correct 9 ms 51804 KB Output is correct
18 Correct 9 ms 51800 KB Output is correct
19 Correct 158 ms 63568 KB Output is correct
20 Correct 139 ms 63568 KB Output is correct
21 Correct 117 ms 63060 KB Output is correct
22 Correct 116 ms 63060 KB Output is correct
23 Correct 119 ms 63056 KB Output is correct
24 Correct 95 ms 59984 KB Output is correct
25 Correct 94 ms 60004 KB Output is correct
26 Correct 109 ms 60128 KB Output is correct
27 Correct 103 ms 60240 KB Output is correct
28 Correct 110 ms 60304 KB Output is correct
29 Correct 146 ms 60472 KB Output is correct
30 Correct 111 ms 60460 KB Output is correct
31 Correct 116 ms 60496 KB Output is correct
32 Correct 113 ms 60504 KB Output is correct
33 Correct 112 ms 60416 KB Output is correct
34 Correct 86 ms 59728 KB Output is correct
35 Correct 93 ms 59728 KB Output is correct
36 Correct 87 ms 59732 KB Output is correct
37 Correct 86 ms 59728 KB Output is correct
38 Correct 90 ms 59732 KB Output is correct
39 Correct 102 ms 61196 KB Output is correct
40 Correct 85 ms 59904 KB Output is correct
41 Correct 97 ms 60080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 51548 KB Output is correct
2 Correct 7 ms 51760 KB Output is correct
3 Correct 7 ms 51784 KB Output is correct
4 Correct 7 ms 51548 KB Output is correct
5 Correct 7 ms 51636 KB Output is correct
6 Correct 7 ms 51548 KB Output is correct
7 Correct 7 ms 51548 KB Output is correct
8 Correct 8 ms 51548 KB Output is correct
9 Correct 7 ms 51688 KB Output is correct
10 Correct 7 ms 51784 KB Output is correct
11 Correct 8 ms 51804 KB Output is correct
12 Correct 9 ms 51804 KB Output is correct
13 Correct 9 ms 51696 KB Output is correct
14 Correct 9 ms 51804 KB Output is correct
15 Correct 10 ms 51804 KB Output is correct
16 Correct 9 ms 51804 KB Output is correct
17 Correct 9 ms 51804 KB Output is correct
18 Correct 9 ms 51800 KB Output is correct
19 Correct 860 ms 107304 KB Output is correct
20 Correct 808 ms 107092 KB Output is correct
21 Correct 807 ms 107316 KB Output is correct
22 Correct 793 ms 107092 KB Output is correct
23 Correct 638 ms 91992 KB Output is correct
24 Correct 63 ms 58992 KB Output is correct
25 Correct 57 ms 58796 KB Output is correct
26 Correct 52 ms 58196 KB Output is correct
27 Correct 57 ms 58196 KB Output is correct
28 Correct 57 ms 58288 KB Output is correct
29 Correct 43 ms 57688 KB Output is correct
30 Correct 44 ms 57940 KB Output is correct
31 Correct 49 ms 58120 KB Output is correct
32 Correct 28 ms 55564 KB Output is correct
33 Correct 48 ms 58124 KB Output is correct
34 Correct 158 ms 63568 KB Output is correct
35 Correct 139 ms 63568 KB Output is correct
36 Correct 117 ms 63060 KB Output is correct
37 Correct 116 ms 63060 KB Output is correct
38 Correct 119 ms 63056 KB Output is correct
39 Correct 95 ms 59984 KB Output is correct
40 Correct 94 ms 60004 KB Output is correct
41 Correct 109 ms 60128 KB Output is correct
42 Correct 103 ms 60240 KB Output is correct
43 Correct 110 ms 60304 KB Output is correct
44 Correct 146 ms 60472 KB Output is correct
45 Correct 111 ms 60460 KB Output is correct
46 Correct 116 ms 60496 KB Output is correct
47 Correct 113 ms 60504 KB Output is correct
48 Correct 112 ms 60416 KB Output is correct
49 Correct 86 ms 59728 KB Output is correct
50 Correct 93 ms 59728 KB Output is correct
51 Correct 87 ms 59732 KB Output is correct
52 Correct 86 ms 59728 KB Output is correct
53 Correct 90 ms 59732 KB Output is correct
54 Correct 102 ms 61196 KB Output is correct
55 Correct 85 ms 59904 KB Output is correct
56 Correct 97 ms 60080 KB Output is correct
57 Correct 789 ms 106620 KB Output is correct
58 Correct 787 ms 106576 KB Output is correct
59 Correct 737 ms 105300 KB Output is correct
60 Correct 774 ms 105340 KB Output is correct
61 Correct 700 ms 105296 KB Output is correct
62 Correct 692 ms 105372 KB Output is correct
63 Correct 450 ms 88628 KB Output is correct
64 Correct 461 ms 88656 KB Output is correct
65 Correct 583 ms 89936 KB Output is correct
66 Correct 573 ms 90196 KB Output is correct
67 Correct 567 ms 89936 KB Output is correct
68 Correct 641 ms 91448 KB Output is correct
69 Correct 618 ms 91448 KB Output is correct
70 Correct 620 ms 91072 KB Output is correct
71 Correct 643 ms 91176 KB Output is correct
72 Correct 655 ms 91216 KB Output is correct
73 Correct 436 ms 88144 KB Output is correct
74 Correct 418 ms 88160 KB Output is correct
75 Correct 431 ms 88148 KB Output is correct
76 Correct 421 ms 88404 KB Output is correct
77 Correct 423 ms 87796 KB Output is correct
78 Correct 614 ms 94712 KB Output is correct
79 Correct 408 ms 83440 KB Output is correct
80 Correct 536 ms 91120 KB Output is correct