Skip to content

Instantly share code, notes, and snippets.

@KhaledElshamy
Created January 22, 2017 00:47
Show Gist options
  • Select an option

  • Save KhaledElshamy/2aaa0845a7ca4020ef46a19d3778025d to your computer and use it in GitHub Desktop.

Select an option

Save KhaledElshamy/2aaa0845a7ca4020ef46a19d3778025d to your computer and use it in GitHub Desktop.
B. Ilya and Queries-codeforces
#include <bits/stdc++.h>
using namespace std;
int main() {
//Dynamic programming
int num, x,y,d[100000]={0};
vector<int>m;
string s;
cin>>s>>num;
for(int i=s.size()-2;i>=0;i--)
{
if(s[i]==s[i+1])
d[i]=d[i+1]+1;
else
d[i]=d[i+1]+0;
}
while(num--)
{
cin>>x>>y;
m.push_back(d[x-1]-d[y-1]);
}
for(int i=0;i<m.size();i++)
cout<<m[i]<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment