Submission #60088312


Source Code Expand

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,q;
string s;
int a[N],b[N],c[N];
int p[N],tot;
void solve()
{
    cin>>n>>q;
    cin>>s;
    s="0"+s;
    for(int i=1;i<=n;i++) 
    {
        if(s[i]=='1') a[i]=1;
        else if(s[i]=='2') b[i]=1;
        else 
        {
            c[i]=1;
            p[++tot]=i;
        }
        a[i]+=a[i-1];
        b[i]+=b[i-1];
        c[i]+=c[i-1];
    }
    while(q--)
    {
        int l,r;
        cin>>l>>r;
        int ll=lower_bound(p+1,p+tot+1,l)-p;
        int rr=upper_bound(p+1,p+tot+1,r)-p-1;
        int ans=0;
        for(int i=ll;i<=rr;i++)
        {
            int id=p[i];
            int c1=a[id-1]-a[l-1];
            int c2=b[r]-b[id];
            ans=max(ans,2*min(c1,c2)+1);
        }
        cout<<ans<<'\n';
    }
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
    freopen("1.out","w",stdout);
    #endif 
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    solve();
    return 0;
}

Submission Info

Submission Time
Task E - 11/22 Subsequence
User zhouruoheng
Language C++ 20 (gcc 12.2)
Score 500
Code Size 1211 Byte
Status AC
Exec Time 1976 ms
Memory 4940 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 1
AC × 25
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
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3488 KiB
01_random_00.txt AC 1245 ms 4912 KiB
01_random_01.txt AC 656 ms 4236 KiB
01_random_02.txt AC 1141 ms 4852 KiB
01_random_03.txt AC 899 ms 4596 KiB
01_random_04.txt AC 1254 ms 4904 KiB
01_random_05.txt AC 1589 ms 4404 KiB
01_random_06.txt AC 621 ms 4812 KiB
01_random_07.txt AC 732 ms 4372 KiB
01_random_08.txt AC 565 ms 4828 KiB
01_random_09.txt AC 1091 ms 4548 KiB
01_random_10.txt AC 1139 ms 4908 KiB
01_random_11.txt AC 1708 ms 4608 KiB
01_random_12.txt AC 194 ms 4928 KiB
01_random_13.txt AC 305 ms 4716 KiB
01_random_14.txt AC 1121 ms 4928 KiB
01_random_15.txt AC 720 ms 4360 KiB
01_random_16.txt AC 1976 ms 4940 KiB
01_random_17.txt AC 643 ms 4356 KiB
01_random_18.txt AC 573 ms 4796 KiB
01_random_19.txt AC 12 ms 4592 KiB
02_corner_00.txt AC 13 ms 4704 KiB
02_corner_01.txt AC 10 ms 3632 KiB
02_corner_02.txt AC 9 ms 3504 KiB
02_corner_03.txt AC 9 ms 3488 KiB