# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1001987 | vjudge1 | Mutating DNA (IOI21_dna) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pb push_back
#define pf push_front
#define pi pair<int,int>
string a,b;
const int MAX = 1e5+10;
int n;
ll hold[MAX+1];
ll how[2][MAX][3];
map<char,int>mtch;
void init(string A, string B){
a = A;
b = B;
mtch['A']=0;
mtch['C']=1;
mtch['T']=2;
for(int i = 0; i <a.size(); i++){
for(int j = 0; j<3; j++){
how[0][i+1][j] = how[0][i][j] ;
how[1][i+1][j] = how[1][i][j] ;
// cnt[i+1][j] = cnt[i][j];
}
// cout << mtch[A[i]]<<" s "<< mtch[B[i]]<<endl;
how[0][i+1][mtch[A[i]]]++;
how[1][i+1][mtch[B[i]]]++;
}
for(int i = 1; i <=a.size(); i++){
hold[i] =hold[i-1];
if(A[i-1]!=B[i-1]){
hold[i]++;
}
}
}
int get_distance(int x, int y){
// cout << y << " " << x << endl;
// cout << hold[y+1] << " " << hold[x] << endl;
ll add = hold[y+1]-hold[x] ;
int vala,valb;
for(int i =0; i < 3; i++){
vala = how[0][y+1][i]-how[0][x][i];
valb = how[1][y+1][i]-how[1][x][i];
// cout<< vala<<" " << valb << endl;
if(vala!=valb) return -1;
}
// if(add==0) return 0;
return (add+1)/2;
}
int main(){
int n,q ;
cin >> n >> q;
string a,b;
cin >> a >>b;
init(a,b);
int x,y;
while(q--){
cin >> x >>y;
cout << get_distance(x,y)<<endl;
}
}