#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
char c[]={'A','C','T'};
int n,q,x,y,temp;
int pre[N][3][3],preTwo[N][3][3],cnt[3][3],dem[3][3];
string a,b;
void init(string a,string b)
{
    for (int i=1;i<=n;i++)
    {
        for (int j=0;j<3;j++)
        for (int k=0;k<3;k++)
        {
            pre[i][j][k]=pre[i-1][j][k]+(a[i-1]!=b[i-1] and a[i-1]==c[j] and b[i-1]==c[k]);
            preTwo[i][j][k]=preTwo[i-1][j][k]+(a[i-1]!=b[i-1] and b[i-1]==c[j] and a[i-1]==c[k]);
        }
    }
}
int get_distance(int x,int y)
{
    x++;
    y++;
    for (int j=0;j<3;j++)
    {
        for (int k=0;k<3;k++)
        {
            cnt[j][k]=pre[y][j][k]-pre[x-1][j][k];
            dem[j][k]=preTwo[y][j][k]-preTwo[x-1][j][k];
        }
        if (cnt[j][0]+cnt[j][1]+cnt[j][2]!=dem[j][0]+dem[j][1]+dem[j][2]) return -1;
    }
    int ans=0;
    for (int j=0;j<3;j++)
    for (int k=0;k<3;k++)
    {
        temp=min(cnt[j][k],cnt[k][j]);
        cnt[j][k]-=temp;
        cnt[k][j]-=temp;
        ans+=temp;
    }
    bool ok=false;
    for (int j=0;j<3;j++)
    for (int k=0;k<3;k++)
    {
        ans+=cnt[j][k];
        if (cnt[j][k]) ok=true;
    }
    ans-=ok;
    return ans;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |