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<bits/stdc++.h>
#include "dna.h"
using namespace std;
string a, b;
struct SegTree{
vector<int>sTree;
void Build(int node, int l, int r){
if(l == r){
sTree[node] = (a[l] != b[l]);
}
else{
int mid = (l + r) >> 1;
Build(node * 2, l, mid);
Build(node * 2 + 1, mid + 1, r);
sTree[node] = sTree[node * 2] + sTree[node * 2 + 1];
}
}
int Query(int node, int l, int r, int ql, int qr){
if(ql <= l && r <= qr)return sTree[node];
if(ql > r || qr < l)return 0;
int mid = (l + r) >> 1;
int Lc = Query(node * 2, l, mid, ql, qr);
int Rc = Query(node * 2 + 1, mid + 1, r, ql, qr);
return Lc + Rc;
}
};
SegTree st;
struct ATC{
int A = 0, T = 0, C = 0;
};
vector<ATC>cnt_A, cnt_B;
void init(string A, string B){
a = " ", b = " ";
a += A, b += B;
cnt_A.resize(a.length());
cnt_B.resize(a.length());
st.sTree.resize(4 * A.length());
st.Build(1, 1, A.length());
for(int i = 1;i <= A.length();++i){
cnt_A[i].A = cnt_A[i - 1].A;
cnt_A[i].T = cnt_A[i - 1].T;
cnt_A[i].C = cnt_A[i - 1].C;
if(a[i] == 'A')cnt_A[i].A++;
if(a[i] == 'T')cnt_A[i].T++;
if(a[i] == 'C')cnt_A[i].C++;
}
for(int i = 1;i <= A.length();++i){
cnt_B[i].A = cnt_B[i - 1].A;
cnt_B[i].T = cnt_B[i - 1].T;
cnt_B[i].C = cnt_B[i - 1].C;
if(b[i] == 'A')cnt_B[i].A++;
if(b[i] == 'T')cnt_B[i].T++;
if(b[i] == 'C')cnt_B[i].C++;
}
}
int get_distance(int x, int y){
x++;
y++;
int q = st.Query(1, 1, a.length() - 1, x, y);
ATC num1, num2;
num1.A = cnt_A[y].A - cnt_A[x - 1].A;
num1.T = cnt_A[y].T - cnt_A[x - 1].T;
num1.C = cnt_A[y].C - cnt_A[x - 1].C;
num2.A = cnt_B[y].A - cnt_B[x - 1].A;
num2.T = cnt_B[y].T - cnt_B[x - 1].T;
num2.C = cnt_B[y].C - cnt_B[x - 1].C;
if(num1.A != num2.A)return -1;
if(num1.T != num2.T)return -1;
if(num1.C != num2.C)return -1;
return q - 1;
}
//int main(){
// init("ATACAT", "ACTATA");
// cout << get_distance(1, 3);
//}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i = 1;i <= A.length();++i){
| ~~^~~~~~~~~~~~~
dna.cpp:47:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i = 1;i <= A.length();++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... |