#ifdef DEBUG #define _GLIBCXX_DEBUG #endif //#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; typedef long double ld; int n; const int maxN = 300'005; ll p[maxN]; char s[maxN]; ll ans[maxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef DEBUG freopen("input.txt", "r", stdin); #endif cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; } int cnt_l = 0; for (int i = n - 1; i >= 0; i--) { if (s[i] == 'L') cnt_l++; else { p[i] += 1; p[i + cnt_l] -= 1; } } for (int i = 0; i + 1 < n; i++) { if (i > 0) p[i] += p[i - 1]; ans[i] += p[i]; ans[i + 1] += p[i]; } for (int i = 0; i < n; i++) cout << ans[i] << " "; return 0; }
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 | #ifdef DEBUG #define _GLIBCXX_DEBUG #endif //#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; typedef long double ld; int n; const int maxN = 300'005; ll p[maxN]; char s[maxN]; ll ans[maxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef DEBUG freopen("input.txt", "r", stdin); #endif cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; } int cnt_l = 0; for (int i = n - 1; i >= 0; i--) { if (s[i] == 'L') cnt_l++; else { p[i] += 1; p[i + cnt_l] -= 1; } } for (int i = 0; i + 1 < n; i++) { if (i > 0) p[i] += p[i - 1]; ans[i] += p[i]; ans[i + 1] += p[i]; } for (int i = 0; i < n; i++) cout << ans[i] << " "; return 0; } |