# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
467648 | iggaboi | 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.
#ifdef Icry
#include "debug.h"
#else
#include <bits/stdc++.h>
#define debug(args...)
#endif
using namespace std;
int main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// ATC
int n, q; cin >> n >> q;
string a, b; cin >> a >> b;
vector <int> noteq(n);
vector <array <int, 3>> cnta(n, {0, 0, 0}), cntb(n, {0, 0, 0});
int mpa = 0, mpt = 1, mpc = 2;
noteq[0] = a[0] != b[0];
cnta[0][mpa] = a[0] == 'A';
cnta[0][mpt] = a[0] == 'T';
cnta[0][mpc] = a[0] == 'C';
cntb[0][mpa] = b[0] == 'A';
cntb[0][mpt] = b[0] == 'T';
cntb[0][mpc] = b[0] == 'C';
for (int i = 1; i < n; ++i) {
noteq[i] = noteq[i - 1] + (a[i] != b[i]);
cnta[i][mpa] = cnta[i - 1][mpa];
cnta[i][mpt] = cnta[i - 1][mpt];
cnta[i][mpc] = cnta[i - 1][mpc];
cntb[i][mpa] = cntb[i - 1][mpa];
cntb[i][mpt] = cntb[i - 1][mpt];
cntb[i][mpc] = cntb[i - 1][mpc];
cnta[i][mpa] += a[i] == 'A';
cnta[i][mpt] += a[i] == 'T';
cnta[i][mpc] += a[i] == 'C';
cntb[i][mpa] += b[i] == 'A';
cntb[i][mpt] += b[i] == 'T';
cntb[i][mpc] += b[i] == 'C';
}
auto query = [&](int i, int j, int mp, int t) {
if (t == 1) return cnta[j][mp] - (i ? cnta[i - 1][mp] : 0);
return cntb[j][mp] - (i ? cntb[i - 1][mp] : 0);
};
while (q--) {
int x, y; cin >> x >> y;
int aa = query(x, y, 0, 1), at = query(x, y, 1, 1), ac = query(x, y, 2, 1);
int ba = query(x, y, 0, 2), bt = query(x, y, 1, 2), bc = query(x, y, 2, 2);
int neq = noteq[y] - (x ? noteq[x - 1] : 0);
if (aa != ba || at != bt || ac != bc || neq % 2) cout << "-1\n";
else {
cout << neq / 2 << '\n';
}
}
}