# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
623818 | 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<int> tree;
int n;
void buildTree (int node, int left, int right, 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] = tree[2*node] + tree[2*node+1];
}
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;
return getValue(2*node, left, mid, x, y)+getValue(2*node+1, mid+1, right, x, y);
}
void init(string a, string b) {
n = a.size();
int arr[a.size()];
for (int i = 0; i < a.size(); ++i){
if(a[i] == b[i])arr[i] = 0;
else arr[i] = 1;
}
tree = vector<int> (4*arr.size(), 0);
buildTree(1, 0, a.size()-1, arr);
}
int get_distance(int x, int y) {
int n = getValue(1, 0, n-1, x, y);
if(n%2 != 0) return -1;
else return n/2;
}