Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- long long n, t, a, b;
- long long out[3000001], sum[3][3000001];
- string s;
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cin>>n;
- cin>>s;
- sum[0][0]=0;
- sum[1][0]=0;
- sum[2][0]=0;
- for(int i=1; i<=n; i++)
- {
- if (s[i-1]==82 && i<n)
- {
- sum[1][i]=sum[1][i-1]+1;
- sum[0][i]=sum[0][i-1];
- sum[2][i]=sum[2][i-1];
- }
- else
- {
- sum[1][i]=sum[1][i-1];
- sum[0][i]=sum[0][i-1];
- sum[2][i]=sum[2][i-1];
- }
- if (s[i-1]==78)
- {
- sum[0][i]=sum[0][i-1]+sum[1][i-1];
- sum[1][i]=sum[1][i-1];
- sum[2][i]=sum[2][i-1]+1;
- }
- }
- cin>>t;
- for(int i=0; i<t; i++)
- {
- cin>>a>>b;
- out[i]=sum[0][b]-sum[0][a-1]-((sum[2][b]-sum[2][a-1])*sum[1][a-1]);
- }
- for(int i=0; i<t; i++)
- {
- cout<<out[i]<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement