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 "dna.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> pref1(1e5, vector<int> (3, 0)), pref2(1e5, vector<int> (3, 0));
vector<int> sum(1e5, 0);
int n;
struct seg {
vector<int> t = vector<int> (1e5 * 4);
void build(int x, int l, int r) {
if(l == r) {
t[x] = sum[l];
return;
}
int m = (l + r) / 2;
build(2 * x, l, m);
build(2 * x + 1, m + 1, r);
t[x] = t[2 * x] + t[2 * x + 1];
}
void build() {
build(1, 0, n - 1);
}
int ans(int x, int lx, int rx, int l, int r) {
if(lx >= l && rx <= r) {
return t[x];
}
if(lx > r || rx < l) {
return 0;
}
int m = (lx + rx) / 2;
return ans(2 * x, lx, m, l, r) + ans(2 * x + 1, m + 1, rx, l, r);
}
int ans(int l, int r) {
return ans(1, 0, n - 1, l, r);
}
};
seg st;
void init(std::string a, std::string b) {
n = a.size();;
for (int i = 0; i<a.size(); i++) {
pref1[i][0] = pref1[max(i-1, 0)][0];
pref1[i][1] = pref1[max(i-1, 0)][1];
pref1[i][2] = pref1[max(i-1, 0)][2];
pref2[i][0] = pref2[max(i-1, 0)][0];
pref2[i][1] = pref2[max(i-1, 0)][1];
pref2[i][2] = pref2[max(i-1, 0)][2];
if(a[i] == 'A') {
pref1[i][0] += 1;
}
if(a[i] == 'T') {
pref1[i][1] += 1;
}
if(a[i] == 'C') {
pref1[i][2] += 1;
}
if(b[i] == 'A') {
pref2[i][0] += 1;
}
if(b[i] == 'T') {
pref2[i][1] += 1;
}
if(b[i] == 'C') {
pref2[i][2] += 1;
}
if(a[i] != b[i]) {
sum[i]++;
}
}
st.build();
}
int get_distance(int x, int y) {
if(pref1[y][0] - (x - 1 < 0 ? 0 : pref1[max(x-1, 0)][0]) != pref2[y][0] - (x - 1 < 0 ? 0 : pref2[max(x-1, 0)][0]) || pref1[y][1] - (x - 1 < 0 ? 0 : pref1[max(x-1, 0)][1]) != pref2[y][1] - (x - 1 < 0 ? 0 : pref2[max(x-1, 0)][1]) || pref1[y][2] - (x - 1 < 0 ? 0 : pref1[max(x-1, 0)][2]) != pref2[y][2] - (x - 1 < 0 ? 0 : pref2[max(x-1, 0)][2])) {
return -1;
}
int k = st.ans(x, y);
return (k & 1 ? k / 2 + 1 : k / 2);
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:46:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int i = 0; i<a.size(); i++) {
| ~^~~~~~~~~
# | 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... |