이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include "dna.h"
#include "bits/stdc++.h"
#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define pb push_back
#define all(ar) ar.begin(),ar.end()
#define pii pair<int,int>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 100000007;
const ll si = 100005;
const ll inf = 7000;
ll po[si][3], pt[si][3],n;
unordered_map<char,ll> hau = {{'A',0},{'T',1},{'C',2}};
ll str[si * 4];
void make(ll x,ll y,ll node,string &a,string &b){
if(x == y){
str[node] = a[x] == b[x];
return;
}
ll mid = x + (y - x)/2, lef = node * 2;
make(x,mid,lef,a,b); make(mid+1,y,lef + 1,a,b);
str[node] = str[lef] + str[lef+1];
return;
}
ll que(ll a,ll b,ll l,ll r,ll node){
if(b < l || r < a) return 0;
if(a >= l && r >= b) return str[node];
ll mid = a + (b - a)/2, lef = node * 2;
return que(a,mid,l,r,lef) + que(mid+1,b,l,r,lef+1);
}
void init(std::string a, std::string b){
n = a.size();
memset(po,0,sizeof(po)); memset(pt,0,sizeof(pt));
po[0][hau[a[0]]] += 1; pt[0][hau[b[0]]] += 1;
for(ll i = 1; i < n; i++){
for(ll j = 0; j < 3; j++){
po[i][j] = po[i - 1][j];
pt[i][j] = pt[i - 1][j];
}
po[i][hau[a[i]]] += 1;
pt[i][hau[b[i]]] += 1;
}
memset(str,0,sizeof(str));
make(0,n-1,1,a,b);
return;
}
ll get(ll x,ll y,ll i,bool t){
ll ans = t ? pt[y][i] : po[y][i];
if(x) ans -= t ? pt[x - 1][i] : po[x - 1][i];
return ans;
}
bool hobe(ll x,ll y){
//cout<<get(x,y,0,0) sp<< get(x,y,0,1) sp<<get(x,y,1,0) sp<< get(x,y,1,1) sp<<get(x,y,2,0) sp<< get(x,y,2,1) el;
return (get(x,y,0,0) == get(x,y,0,1)) && (get(x,y,1,0) == get(x,y,1,1)) && (get(x,y,2,0) == get(x,y,2,1));
}
int get_distance(int x, int y) {
if(!hobe(x,y)) return -1;
return (y - x - que(0,n - 1,x,y,1) + 2)/2;
}
# | 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... |