Submission #61597191


Source Code Expand

Copy
#include<bits/stdc++.h>
#define int long long
#define For(i, a, b) for(int i = (a); i <= (b); i++)
#define Rof(i, a, b) for(int i = (a); i >= (b); i--)
using namespace std;
const int N = 5e5 + 5, inf = 1e18;
int n, q, a[N], b[N], st[20][N];
int query(int l, int r){
int k = __lg(r - l + 1);
return max(st[k][l], st[k][r - (1 << k) + 1]);
}
void Solve(){
cin >> n;
For(i, 1, n) cin >> a[i];
int j = n + 1;
Rof(i, n, 1){
while(j > i && a[i] * 2 <= a[j - 1]) j--;
if(j <= n && j != i) b[i] = j; else b[i] = inf;
st[0][i] = b[i] - i;
}
For(i, 1, __lg(n))
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include<bits/stdc++.h>
#define int long long
#define For(i, a, b) for(int i = (a); i <= (b); i++)
#define Rof(i, a, b) for(int i = (a); i >= (b); i--)
using namespace std;
const int N = 5e5 + 5, inf = 1e18;
int n, q, a[N], b[N], st[20][N];
int query(int l, int r){
	int k = __lg(r - l + 1);
	return max(st[k][l], st[k][r - (1 << k) + 1]);
}
void Solve(){
	cin >> n;
	For(i, 1, n) cin >> a[i];
	int j = n + 1;
	Rof(i, n, 1){
		while(j > i && a[i] * 2 <= a[j - 1]) j--;
		if(j <= n && j != i) b[i] = j; else b[i] = inf;
		st[0][i] = b[i] - i;
	}
	For(i, 1, __lg(n))
		for(int j = 1; j + (1 << i) - 1 <= n; j++)
			st[i][j] = max(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
	//For(i, 1, n) cerr << "b[" << i << "]=" << b[i] << '\n';
	cin >> q;
	while(q--){
		int ql, qr; cin >> ql >> qr;
		int len = qr - ql + 1, l = 1, r = len / 2, pos = 0;
		while(l <= r){
			int mid = (l + r) >> 1;
			//cerr << "mid=" << mid << '\n';
			if(query(ql, ql + mid - 1) <= qr - mid + 1 - ql) l = mid + 1, pos = mid;
			else r = mid - 1;
		}
		cout << pos << '\n';
	}
}
signed main(){
	cin.tie(0)->sync_with_stdio(0);
	int T = 1; //cin >> T;
	while(T--) Solve();
	return 0;
}

Submission Info

Submission Time
Task G - Simultaneous Kagamimochi 2
User Anyees
Language C++ 20 (gcc 12.2)
Score 575
Code Size 1196 Byte
Status AC
Exec Time 107 ms
Memory 32908 KB

Compile Error

Main.cpp: In function ‘void Solve()’:
Main.cpp:23:76: warning: suggest parentheses around ‘-’ inside ‘<<’ [-Wparentheses]
   23 |                         st[i][j] = max(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
      |                                                                          ~~^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 575 / 575
Status
AC × 2
AC × 46
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 02_handmade_40.txt, 02_handmade_41.txt, 02_handmade_42.txt, 02_handmade_43.txt, 02_handmade_44.txt, 02_handmade_45.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3528 KB
00_sample_01.txt AC 1 ms 3432 KB
01_random_02.txt AC 107 ms 32684 KB
01_random_03.txt AC 101 ms 32836 KB
01_random_04.txt AC 93 ms 32760 KB
01_random_05.txt AC 94 ms 32716 KB
01_random_06.txt AC 87 ms 32680 KB
01_random_07.txt AC 64 ms 22364 KB
01_random_08.txt AC 30 ms 4728 KB
01_random_09.txt AC 82 ms 30580 KB
01_random_10.txt AC 93 ms 32688 KB
01_random_11.txt AC 100 ms 32676 KB
01_random_12.txt AC 85 ms 32780 KB
01_random_13.txt AC 86 ms 32840 KB
01_random_14.txt AC 81 ms 32716 KB
01_random_15.txt AC 87 ms 32900 KB
01_random_16.txt AC 71 ms 32752 KB
01_random_17.txt AC 94 ms 32744 KB
01_random_18.txt AC 97 ms 32784 KB
01_random_19.txt AC 86 ms 32776 KB
01_random_20.txt AC 85 ms 32768 KB
01_random_21.txt AC 91 ms 32844 KB
01_random_22.txt AC 80 ms 32688 KB
01_random_23.txt AC 79 ms 32772 KB
01_random_24.txt AC 84 ms 32748 KB
01_random_25.txt AC 79 ms 32720 KB
01_random_26.txt AC 91 ms 32908 KB
01_random_27.txt AC 97 ms 32780 KB
01_random_28.txt AC 86 ms 32768 KB
01_random_29.txt AC 92 ms 32708 KB
01_random_30.txt AC 97 ms 32724 KB
01_random_31.txt AC 88 ms 32780 KB
01_random_32.txt AC 51 ms 15856 KB
01_random_33.txt AC 36 ms 6008 KB
01_random_34.txt AC 29 ms 4024 KB
01_random_35.txt AC 58 ms 32720 KB
01_random_36.txt AC 62 ms 32768 KB
01_random_37.txt AC 54 ms 32784 KB
01_random_38.txt AC 61 ms 32848 KB
01_random_39.txt AC 60 ms 32780 KB
02_handmade_40.txt AC 18 ms 3648 KB
02_handmade_41.txt AC 18 ms 3504 KB
02_handmade_42.txt AC 20 ms 3536 KB
02_handmade_43.txt AC 94 ms 32776 KB
02_handmade_44.txt AC 69 ms 32764 KB
02_handmade_45.txt AC 65 ms 32720 KB


2025-03-05 (Wed)
18:04:33 +00:00