# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
623826 | a_aguilo | 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 "dna.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> tree;
int n;
//type [0] = A vs T
//type [1] = T vs A
//type [2] = C vs T
//type [3] = T vs C
//type [4] = A vs C
//type [5] = C vs A
void buildTree (int node, int left, int right, vector<vector<int>>& arr){
if(left > right) return;
if(left == right){
tree[node] = arr[left];
return;
}
int mid = left + (right - left)/2;
buildTree(2*node, left, mid, arr);
buildTree(2*node+1, mid+1, right, arr);
tree[node][0] = tree[2*node][0] + tree[2*node+1][0];
tree[node][1] = tree[2*node][1] + tree[2*node+1][1];
}
vector<int> getValue (int node, int left, int right, int x, int y){
if(x > right or y < left) return 0;
if(x <= left and y >= right) return tree[node];
int mid = left + (right - left)/2;
vector<int> l = getValue(2*node, left, mid, x, y);
vector<int> r = getValue(2*node+1, mid+1, right, x, y);
vector<int> ans = {l[0] + r[0], l[1] + r[1]};
return ans;
}
void init(string a, string b) {
n = a.size();
vector<vector<int>> arr(a.size(), vector<int>(2, 0));
for (int i = 0; i < a.size(); ++i){
if(a[i] != b[i]){
if(a[i] == 'A' and b[i] == 'T') arr[i][0] = 1;
if(a[i] == 'T' and b[i] == 'A') arr[i][1] = 1;
}
}
tree = vector<vector<int>> (4*a.size(), vector<int>(2, 0));
buildTree(1, 0, a.size()-1, arr);
}
int get_distance(int x, int y) {
vector<int> ans = getValue(1, 0, n-1, x, y);
int resp = 0;
int AT = ans[0];
int TA = ans[1];
if(AT == TA) return AT;
else return -1;
}