Advertisement
jkonefal

Untitled

Nov 30th, 2020
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. long long n, t, a, b;
  4. long long out[3000001], sum[3][3000001];
  5. string s;
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(0);
  9. cin.tie(0);
  10. cin>>n;
  11. cin>>s;
  12.  
  13. sum[0][0]=0;
  14. sum[1][0]=0;
  15. sum[2][0]=0;
  16. for(int i=1; i<=n; i++)
  17. {
  18. if (s[i-1]==82 && i<n)
  19. {
  20. sum[1][i]=sum[1][i-1]+1;
  21. sum[0][i]=sum[0][i-1];
  22. sum[2][i]=sum[2][i-1];
  23. }
  24. else
  25. {
  26. sum[1][i]=sum[1][i-1];
  27. sum[0][i]=sum[0][i-1];
  28. sum[2][i]=sum[2][i-1];
  29. }
  30. if (s[i-1]==78)
  31. {
  32. sum[0][i]=sum[0][i-1]+sum[1][i-1];
  33. sum[1][i]=sum[1][i-1];
  34. sum[2][i]=sum[2][i-1]+1;
  35. }
  36. }
  37. cin>>t;
  38. for(int i=0; i<t; i++)
  39. {
  40. cin>>a>>b;
  41. out[i]=sum[0][b]-sum[0][a-1]-((sum[2][b]-sum[2][a-1])*sum[1][a-1]);
  42. }
  43.  
  44. for(int i=0; i<t; i++)
  45. {
  46. cout<<out[i]<<"\n";
  47. }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement