Submission details
Task:Kyselyt
Sender:Sisuaski
Submission time:2025-12-20 16:31:17 +0200
Language:C++ (C++20)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.04 s1, 2, 3details
#20.04 s2, 3details
#30.07 s3details
#4ACCEPTED0.01 s1, 2, 3details

Code

#include <iostream>
using namespace std;
const int MN = 100<<10;
int vs[MN];
int ds[MN];

int tree[2*MN];
void add(int i, int v) {
	for(i+=MN; i; i/=2) {
		tree[i] = max(tree[i],v);
	}
}
int get(int a, int b) {
	int r=0;
	for(a+=MN,b+=MN; a<=b; a/=2,b/=2) {
		if (a%2==1) r=max(r,tree[a++]);
		if (b%2==0) r=max(r,tree[b--]);
	}
	return r;
}

int main() {
	int n,q;cin>>n>>q;
	for(int i=0; i<n; ++i) {
		cin>>vs[i];
	}
	for(int i=0, j=0; i<n; ++i) {
		while(j<n && vs[j]<2*vs[i]) ++j;
		ds[i] = j-i;
		add(i+1,ds[i]);
	}
	while(q--) {
		int a,b;cin>>a>>b;
		int n = b-a+1;
		int low=0;
		int hi=n/2+1;
		//cout<<"range "<<a<<' '<<b<<" ; "<<n<<' '<<hi<<'\n';
		while(hi-low>1) {
			int m = (low+hi)/2;
			int x = get(a,a+m-1);
			//cout<<"get "<<a<<' '<<a+low-1<<" = "<<x<<" ; "<<m<<'\n';
			if (x <= n-m) low=m;
			else hi=m;
		}
		cout<<low<<'\n';
	}
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
200000 1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
97730
98017
97642
98714
98684
...

user output
(empty)

Test 2

Group: 2, 3

Verdict:

input
200000 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
98585
98296
97821
97536
97126
...

user output
(empty)

Test 3

Group: 3

Verdict:

input
200000 200000
1682 5103 11595 22085 22347 26...

correct output
98161
98619
98358
98614
98192
...

user output
(empty)

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
44 990
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
0
1
1
2
2
...

user output
0
1
1
2
2
...