Submission #60174343


Source Code Expand

// LUOGU_RID: 191031469
#include <bits/stdc++.h>
#define int long long
#define ls p<<1
#define rs p<<1|1 
#define re register 
const int N=1e5+10;
const int mod=998244353;
using namespace std;

int n,m;
char a[N];
int ld[N];
int rd[N];

int len=0;
int v[N];


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); 
    
    cin>>n>>m;
    
    for(re int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]=='/'){
			v[++len]=i;
		}
	} 
	
	for(re int i=1;i<=n;i++){
		ld[i]=ld[i-1];
		if(a[i]=='1'){
			ld[i]++;
		}
	}
	
	for(re int i=n;i>=1;i--){
		rd[i]=rd[i+1];
		if(a[i]=='2'){
			rd[i]++;
		}
	}
//	cout<<"\n\n";
//	for(int i=1;i<=len;i++){
//		cout<<v[i]<<" ";
//	}
//	cout<<"\n\n";
	for(re int i=1;i<=m;i++){
		int x,y,l,r;
		cin>>l>>r;
		x=lower_bound(v+1,v+1+len,l)-v;
		y=upper_bound(v+1,v+1+len,r)-v-1; 
		
		int mid,ans=-1;
		while(x<=y){
			mid=(x+y)>>1;
			int c1=ld[v[mid]]-ld[l-1];
			int c2=rd[v[mid]]-rd[r+1];
			ans=max(ans,min(c1,c2));
			if(c1>c2){
				y=mid-1;
			}
			else{
				x=mid+1;
			}
		}
		if(ans==-1){
			cout<<"0\n";
		}
		else{
			cout<<ans*2+1<<"\n";
		}
	} 
    
    
	return 0;
}

Submission Info

Submission Time
Task E - 11/22 Subsequence
User sadlin
Language C++ 17 (gcc 12.2)
Score 500
Code Size 1196 Byte
Status AC
Exec Time 46 ms
Memory 6072 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:26:16: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   26 |     for(re int i=1;i<=n;i++){
      |                ^
Main.cpp:33:20: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   33 |         for(re int i=1;i<=n;i++){
      |                    ^
Main.cpp:40:20: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   40 |         for(re int i=n;i>=1;i--){
      |                    ^
Main.cpp:51:20: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   51 |         for(re int i=1;i<=m;i++){
      |                    ^

Judge Result

Set Name Sample All after_contest
Score / Max Score 0 / 0 500 / 500 0 / 0
Status
AC × 1
AC × 25
AC × 2
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_random_00.txt, 01_random_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, 02_corner_00.txt, 02_corner_01.txt, 02_corner_02.txt, 02_corner_03.txt
after_contest 99_after_contest_00.txt, 99_after_contest_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3432 KiB
01_random_00.txt AC 44 ms 5552 KiB
01_random_01.txt AC 37 ms 4432 KiB
01_random_02.txt AC 40 ms 5328 KiB
01_random_03.txt AC 38 ms 4908 KiB
01_random_04.txt AC 43 ms 5408 KiB
01_random_05.txt AC 41 ms 4732 KiB
01_random_06.txt AC 35 ms 5296 KiB
01_random_07.txt AC 25 ms 4584 KiB
01_random_08.txt AC 37 ms 5168 KiB
01_random_09.txt AC 40 ms 4784 KiB
01_random_10.txt AC 29 ms 5500 KiB
01_random_11.txt AC 35 ms 5176 KiB
01_random_12.txt AC 34 ms 5112 KiB
01_random_13.txt AC 35 ms 4796 KiB
01_random_14.txt AC 36 ms 5392 KiB
01_random_15.txt AC 32 ms 4584 KiB
01_random_16.txt AC 46 ms 5528 KiB
01_random_17.txt AC 35 ms 4684 KiB
01_random_18.txt AC 31 ms 5316 KiB
01_random_19.txt AC 14 ms 4984 KiB
02_corner_00.txt AC 14 ms 5260 KiB
02_corner_01.txt AC 10 ms 3488 KiB
02_corner_02.txt AC 7 ms 3456 KiB
02_corner_03.txt AC 7 ms 3512 KiB
99_after_contest_00.txt AC 18 ms 6072 KiB
99_after_contest_01.txt AC 18 ms 5480 KiB