#include<stdio.h> inline char nc() { static char buf[99999],*l,*r; return l==r&&(r=(l=buf)+fread(buf,1,99999,stdin),l==r)?EOF:*l++; } inline void read(int&x) { char c=nc();for(;c<'0'||'9'<c;c=nc()); for(x=0;'0'<=c&&c<='9';x=(x<<3)+(x<<1)+(c^48),c=nc()); } int n,ans[300009];char s[300009]; main() { read(n); for(int i=1;i<=n;++i)for(;s[i]=nc(),(s[i]^'L')&&(s[i]^'P');); for(int i=1,l=-1;i<=n;++i)if(s[i]^'L') { if(l>>31)l=i; } else { if(l>>31)continue; ++ans[l];--ans[i]; ++ans[l+1];--ans[i+1]; ++l; } for(int i=2;i<=n;++i)ans[i]+=ans[i-1]; for(int i=1;i<=n;printf("%d ",ans[i++])); }
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 | #include<stdio.h> inline char nc() { static char buf[99999],*l,*r; return l==r&&(r=(l=buf)+fread(buf,1,99999,stdin),l==r)?EOF:*l++; } inline void read(int&x) { char c=nc();for(;c<'0'||'9'<c;c=nc()); for(x=0;'0'<=c&&c<='9';x=(x<<3)+(x<<1)+(c^48),c=nc()); } int n,ans[300009];char s[300009]; main() { read(n); for(int i=1;i<=n;++i)for(;s[i]=nc(),(s[i]^'L')&&(s[i]^'P');); for(int i=1,l=-1;i<=n;++i)if(s[i]^'L') { if(l>>31)l=i; } else { if(l>>31)continue; ++ans[l];--ans[i]; ++ans[l+1];--ans[i+1]; ++l; } for(int i=2;i<=n;++i)ans[i]+=ans[i-1]; for(int i=1;i<=n;printf("%d ",ans[i++])); } |