Submission #57957660


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
const char sp = ' ';
const int inf = 0x3f3f3f3f;
const string OUT[2]{ "NO", "YES" };
const string out[2]{ "No", "Yes" };
#define all(a) a.begin(), a.end()
#define dbg(a) cerr << (#a) << " = " << a << nl
#define OK() cerr << "OK until line " << __LINE__ << nl
using ll = long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ifstream fin(".in");
ofstream fout(".out");

auto start_time = chrono::high_resolution_clock::now();

double amcbn() {
    auto end_time = chrono::high_resolution_clock::now();
    return chrono::duration<double>(end_time - start_time).count();
}

template<typename T>
int rand(T a, T b) { return uniform_int_distribution<T>(a, b)(rng); }

template<typename T1, typename T2>
bool ckmax(T1& a, T2 b) { return a < b ? a = b, true : false; }

template<typename T1, typename T2>
bool ckmin(T1& a, T2 b) { return a > b ? a = b, true : false; }

int n, q;
string s;
set<int> pos;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q >> s;
    s = '$' + s;
    for (int i = 1; i + 2 <= n; ++i) {
        if (s.substr(i, 3) == "ABC") {
            pos.insert(i);
        }
    }
    while (q--) {
        int i;
        char ch;
        cin >> i >> ch;
        for (int j = max(1, i - 2); j <= i && j + 2 <= n; ++j) {
            if (s.substr(j, 3) == "ABC") {
                pos.erase(j);
            }
        }
        s[i] = ch;
        for (int j = max(1, i - 2); j <= i && j + 2 <= n; ++j) {
            if (s.substr(j, 3) == "ABC") {
                pos.insert(j);
            }
        }
        cout << '\t' << pos.size() << nl;
    }
}

Submission Info

Submission Time
Task C - Count ABC Again
User amcbn
Language C++ 20 (gcc 12.2)
Score 350
Code Size 1742 Byte
Status AC
Exec Time 106 ms
Memory 6724 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 17
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3600 KiB
00_sample_01.txt AC 1 ms 3592 KiB
00_sample_02.txt AC 1 ms 3548 KiB
01_handmade_00.txt AC 1 ms 3560 KiB
01_handmade_01.txt AC 106 ms 6724 KiB
02_random_00.txt AC 44 ms 3896 KiB
02_random_01.txt AC 44 ms 4048 KiB
02_random_02.txt AC 44 ms 3904 KiB
02_random_03.txt AC 36 ms 3704 KiB
02_random_04.txt AC 35 ms 3796 KiB
02_random_05.txt AC 35 ms 3796 KiB
02_random_06.txt AC 13 ms 4416 KiB
02_random_07.txt AC 20 ms 3560 KiB
02_random_08.txt AC 21 ms 3564 KiB
02_random_09.txt AC 21 ms 3560 KiB
02_random_10.txt AC 21 ms 3528 KiB
02_random_11.txt AC 21 ms 3572 KiB