Submission #70663082


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "include/debug.cpp"
#else
#define debug(...) (void)(0)
#endif
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
void sol(){
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;

    vector<vector<int>> pre(2, vector<int>(n + 1));
	for (int i = 1; i <= n; i++) {
		pre[0][i] = pre[0][i - 1];
		pre[1][i] = pre[1][i - 1];
		pre[s[i - 1] - 'a'][i]++;
	}

	ll ans = 0;
	for (int l = 1; l <= n; l++) {
		int ar = lower_bound(pre[0].begin(), pre[0].end(), pre[0][l - 1] + a) - pre[0].begin();
		int br = lower_bound(pre[1].begin(), pre[1].end(), pre[1][l - 1] + b) - pre[1].begin();
		br--;
		if (ar <= br) {
			ans += (br - ar + 1);
		}
	}
	cout << ans << "\n";
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--){
        sol();
    }
    return 0;
}
/**
 * 前缀和?
 * 滑动窗口?
 * 
 * r++ 使得 cnta 可以增加到 a
 * l++ 使得 cntb 可以减少到 b
 * abbaaabaaba
 * 
 * 好像不对
 * 
 * 前缀和之后
 * 二分
 * 
 * 对于每一个 l
 * 可以二分得到 r
 * 这个 r 满足 条件 a 和条件 b
 * 不对
 * 应该是得到两个 ar, br
 * 然后同时满足 ar && br 的区间就是答案
 */

Submission Info

Submission Time
Task C - Truck Driver
User LanternCX
Language C++23 (GCC 15.2.0)
Score 300
Code Size 1369 Byte
Status AC
Exec Time 29 ms
Memory 7316 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 25
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
hand.txt AC 1 ms 3636 KiB
random_01.txt AC 19 ms 7208 KiB
random_02.txt AC 18 ms 7268 KiB
random_03.txt AC 19 ms 7148 KiB
random_04.txt AC 19 ms 7024 KiB
random_05.txt AC 24 ms 7128 KiB
random_06.txt AC 24 ms 7080 KiB
random_07.txt AC 23 ms 7128 KiB
random_08.txt AC 23 ms 7148 KiB
random_09.txt AC 22 ms 7148 KiB
random_10.txt AC 24 ms 7160 KiB
random_11.txt AC 24 ms 7212 KiB
random_12.txt AC 22 ms 7208 KiB
random_13.txt AC 28 ms 7136 KiB
random_14.txt AC 29 ms 7084 KiB
random_15.txt AC 27 ms 7148 KiB
random_16.txt AC 27 ms 7280 KiB
random_17.txt AC 27 ms 7136 KiB
random_18.txt AC 28 ms 7212 KiB
random_19.txt AC 13 ms 7316 KiB
random_20.txt AC 27 ms 7076 KiB
random_21.txt AC 27 ms 7132 KiB
random_22.txt AC 27 ms 7084 KiB
sample_01.txt AC 1 ms 3640 KiB
sample_02.txt AC 1 ms 3636 KiB