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, 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;
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 0; i < a.size(); ++i){
| ~~^~~~~~~~~~
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:54:6: warning: unused variable 'resp' [-Wunused-variable]
54 | int resp = 0;
| ^~~~
# | 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... |