Submission #60071269


Source Code Expand

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <atcoder/all>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, l, r) for (int i = l; i <= r; i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<VI>;
using VVL = vector<VL>;

int main()
{
    int n, q;
    string s;
    cin >> n >> q;
    cin >> s;
    VI one(n + 1), two(n + 1), pos;
    REP(i,n){
        one[i + 1] = one[i] + (s[i] == '1');
        two[i + 1] = two[i] + (s[i] == '2');
        if (s[i] == '/') pos.push_back(i);
    }
    REP(_,q){
        int l, r;
        cin >> l >> r;
        l--;
        int lef, rig;
        lef = lower_bound(pos.begin(), pos.end(), l) - pos.begin();
        rig = lower_bound(pos.begin(), pos.end(), r) - pos.begin();
        // cout << "lef: " << lef << " rig: " << rig << endl;
        if (lef == rig) {
            cout << 0 << endl;
            continue;
        }
        while (rig - lef > 1) {
            int mid = (lef + rig) / 2;
            int s1 = one[pos[mid]] - one[l];
            int s2 = two[r] - two[pos[mid]];
            if (s1 < s2) lef = mid;
            else rig = mid;
        }
        int ans = 0;
        FOR(i,lef,rig){
            if (rig > pos.size()) break;
            chmax(ans, 1 + 2 * min(one[pos[i]] - one[l], two[r] - two[pos[i]]));
        }
        cout << ans << endl;
    }
}

Submission Info

Submission Time
Task E - 11/22 Subsequence
User TangentDay
Language C++ 20 (gcc 12.2)
Score 500
Code Size 1582 Byte
Status AC
Exec Time 169 ms
Memory 4672 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:54:21: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   54 |             if (rig > pos.size()) break;
      |                 ~~~~^~~~~~~~~~~~

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 3480 KiB
01_random_00.txt AC 169 ms 4512 KiB
01_random_01.txt AC 161 ms 3972 KiB
01_random_02.txt AC 154 ms 4576 KiB
01_random_03.txt AC 153 ms 4228 KiB
01_random_04.txt AC 166 ms 4604 KiB
01_random_05.txt AC 165 ms 4228 KiB
01_random_06.txt AC 146 ms 4540 KiB
01_random_07.txt AC 102 ms 4160 KiB
01_random_08.txt AC 163 ms 4284 KiB
01_random_09.txt AC 163 ms 4044 KiB
01_random_10.txt AC 104 ms 4672 KiB
01_random_11.txt AC 132 ms 4272 KiB
01_random_12.txt AC 157 ms 4236 KiB
01_random_13.txt AC 158 ms 3988 KiB
01_random_14.txt AC 140 ms 4564 KiB
01_random_15.txt AC 143 ms 3960 KiB
01_random_16.txt AC 168 ms 4512 KiB
01_random_17.txt AC 161 ms 3972 KiB
01_random_18.txt AC 122 ms 4368 KiB
01_random_19.txt AC 87 ms 3960 KiB
02_corner_00.txt AC 128 ms 4208 KiB
02_corner_01.txt AC 114 ms 3520 KiB
02_corner_02.txt AC 113 ms 3568 KiB
02_corner_03.txt AC 114 ms 3508 KiB