#include <bits/stdc++.h>
using namespace std;
const int BASE = 1<<19;
int tree[BASE<<1];
void update(int a, int b, const int &x){
a+=BASE;
b+=BASE;
while(a<=b){
if(a&1) tree[a] += x;
if(!(b&1)) tree[b] += x;
a = (a+1)>>1;
b = (b-1)>>1;
}
}
int query(int a){
int res = 0;
a+=BASE;
res += tree[a];
a>>=1;
while(a>0){
res+=tree[a];
a>>=1;
}
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
string s;
cin >> s;
int b;
for(b = n-1; b>=0; b--) if(s[b]=='L') break;
for(int i = b-1; i >= 0; i--){
if(s[i]=='L') continue;
update(i, i, 1);
update(i+1, b-1, 2);
update(b, b, 1);
b--;
}
for(int i = 0; i < n; i++){
cout << query(i) << ' ';
}
cout << '\n';
}
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 | #include <bits/stdc++.h> using namespace std; const int BASE = 1<<19; int tree[BASE<<1]; void update(int a, int b, const int &x){ a+=BASE; b+=BASE; while(a<=b){ if(a&1) tree[a] += x; if(!(b&1)) tree[b] += x; a = (a+1)>>1; b = (b-1)>>1; } } int query(int a){ int res = 0; a+=BASE; res += tree[a]; a>>=1; while(a>0){ res+=tree[a]; a>>=1; } return res; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string s; cin >> s; int b; for(b = n-1; b>=0; b--) if(s[b]=='L') break; for(int i = b-1; i >= 0; i--){ if(s[i]=='L') continue; update(i, i, 1); update(i+1, b-1, 2); update(b, b, 1); b--; } for(int i = 0; i < n; i++){ cout << query(i) << ' '; } cout << '\n'; } |
English