1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define ROF(i, a, b) for (int i = (a); i >= (b); --i) #define debug(var) cerr << #var <<":"<<var<<"\n"; #define cend cerr<<"\n-----------\n" #define fsp(x) fixed<<setprecision(x) #define all(vec) vec.begin(),vec.end() using namespace std; using ll = long long;using ull = unsigned long long; using DB=double;using LD=long double;
using CD=complex<double>; static constexpr ll MAXN=(ll)1e6+10,INF=(1ll<<61)-1; static constexpr ll mod=(ll)1e9+7; static constexpr double eps=1e-8;const double pi=acos(-1.0); #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using ordered_set = tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>; ll lT; void Solve(){ ll N,A,B; cin>>N>>A>>B; vector<char> S(N+5); FOR(i,1,N) { cin>>S[i]; } ll cnta=0,cntb=0; ll ans=0; ll up=1; ordered_set posa; FOR(i,1,N) { bool isb=false; FOR(j,up,N) { if(S[j]=='b') { ++cntb; }else { posa.insert(j); ++cnta; } if(cnta>=A && cntb<B) {
ans+=(*posa.find_by_order(cnta-A)-i+1);
} if(cntb>=B) { up=j; if(S[i]=='a') { posa.erase(i); --cnta; }else { --cntb; } if(S[j]=='b') { --cntb; }else { posa.erase(j); --cnta; } isb=true; break; } } if(!isb) { up=N+1; } } cout<<ans<<"\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); return 0; }
|