fork download
  1. #include<bits/stdc++.h>
  2. /*#include <boost/multiprecision/cpp_int.hpp>
  3. using namespace boost::multiprecision; */
  4. using namespace std;
  5. #define ll long long int
  6. #define MOD 1000000007
  7. #define fori(i,a,b) for(ll i=a;i<b;i++)
  8. #define ford(i,a,b) for(ll i=a;i>=b;i--)
  9. #define all(arr) arr.begin(),arr.end()
  10. #define mp make_pair
  11. #define sorti(v) sort(v.begin(),v.end())
  12. #define sortd(v) sort(v.rbegin(),v.rend())
  13. #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  14. template <typename T1, typename T2>
  15. inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
  16. {
  17. return os << "(" << p.first << ", " << p.second << ")";
  18. }
  19. template<typename T>
  20. inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v)
  21. {
  22. bool first = true;
  23. os << "[";
  24. for(unsigned int i = 0; i < v.size(); i++)
  25. {
  26. if(!first)
  27. os << ", ";
  28. os << v[i];
  29. first = false;
  30. }
  31. return os << "]";
  32. }
  33. template<typename T>
  34. inline std::ostream &operator << (std::ostream & os,const std::set<T>& v)
  35. {
  36. bool first = true;
  37. os << "[";
  38. for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
  39. {
  40. if(!first)
  41. os << ", ";
  42. os << *ii;
  43. first = false;
  44. }
  45. return os << "]";
  46. }
  47. template<typename T1, typename T2>
  48. inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v)
  49. {
  50. bool first = true;
  51. os << "[";
  52. for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
  53. {
  54. if(!first)
  55. os << ", ";
  56. os << *ii ;
  57. first = false;
  58. }
  59. return os << "]";
  60. }
  61. ll power(ll x,ll y){
  62. ll res=1;
  63. while(y>0){
  64. if(y&1)
  65. res=(res*x);
  66. y=y>>1;
  67. x=(x*x);
  68. }
  69. return (res);
  70. }
  71. typedef pair<ll,ll> pll;
  72. typedef pair<int,int> pii;
  73. typedef vector<int> vi;
  74. typedef vector<pii> vii;
  75. int main(){
  76. IOS
  77. string s;
  78. cin>>s;
  79. int n=s.length();
  80. vector<int> pre(n+1);
  81. pre[0]=0;
  82. fori(i,1,n+1){
  83. pre[i]=pre[i-1];
  84. if(s[i-1]==s[i-2])
  85. pre[i]++;
  86. }
  87. int m;cin>>m;
  88. int l,r;
  89. while(m--){
  90. cin>>l>>r;
  91. cout<<pre[r]-pre[l-1]<<endl;
  92. }
  93. cout<<pre<<endl;
  94. }
Success #stdin #stdout 0s 4476KB
stdin
......
4
3 4
2 3
1 6
2 6
stdout
2
2
5
5
[0, 0, 1, 2, 3, 4, 5]