제출 #715461

#제출 시각아이디문제언어결과실행 시간메모리
715461aykhnDNA 돌연변이 (IOI21_dna)C++17
56 / 100
93 ms9688 KiB
#include <bits/stdc++.h>
#include "dna.h"

using namespace std;

typedef long long ll;

#define OPT ios_base::sync_with_stdio(0); \
            cin.tie(0); \
            cout.tie(0)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define bpc __builtin_popcount
#define print(v) for(int i = 0; i < v.size(); i++) \
                    cout << v[i] << " "; \
                    cout<<endl;



struct cus
{
    int a1 = 0, t1 = 0, c1 = 0, a2 = 0, t2 = 0, c2 = 0;
    int same = 0;
};

struct SegTree
{
    int size;
    vector<cus> tree;

    void init(int n)
    {
        size = 1;

        while (size < n) size *= 2;

        tree.resize(2*size);
    }

    void build(int l, int r, int x, string &a, string &b)
    {
        if (l + 1 == r)
        {
            if (l >= a.length()) return;

            if (a[l] == 'A') tree[x].a1 = 1;
            else if (a[l] == 'C') tree[x].c1 = 1;
            else tree[x].t1 = 1;

            if (b[l] == 'A') tree[x].a2 = 1;
            else if (b[l] == 'C') tree[x].c2 = 1;
            else tree[x].t2 = 1;

            if (a[l] == b[l]) tree[x].same = 1;

            return;
        }

        int mid = (l + r) >> 1;

        build(l, mid, 2*x+1, a, b);
        build(mid, r, 2*x+2, a, b);

        tree[x].a1 = tree[2*x+1].a1 + tree[2*x+2].a1;
        tree[x].a2 = tree[2*x+1].a2 + tree[2*x+2].a2;
        tree[x].c1 = tree[2*x+1].c1 + tree[2*x+2].c1;
        tree[x].c2 = tree[2*x+1].c2 + tree[2*x+2].c2;
        tree[x].t1 = tree[2*x+1].t1 + tree[2*x+2].t1;
        tree[x].t2 = tree[2*x+1].t2 + tree[2*x+2].t2;
        tree[x].same = tree[2*x+1].same + tree[2*x+2].same;
    }

    void build(string &a, string &b)
    {
        build(0, size, 0, a, b);
    }

    cus get(int lx, int rx, int l, int r, int x)
    {
        if (l >= lx && r <= rx)
        {
            return tree[x];
        }
        if (l >= rx || r <= lx)
        {
            cus temp;
            return temp;
        }

        int mid = (l + r) >> 1;

        cus a = get(lx, rx, l, mid, 2*x+1);
        cus b = get(lx, rx, mid, r, 2*x+2);

        a.a1 +=  b.a1;
        a.a2 +=  b.a2;
        a.c1 +=  b.c1;
        a.c2 +=  b.c2;
        a.t1 +=  b.t1;
        a.t2 +=  b.t2;
        a.same +=  b.same;

        return a;
    }

    int get(int l, int r)
    {
        cus s = get(l, r + 1, 0, size, 0);

        if (s.a1 != s.a2 || s.c1 != s.c2 || s.t1 != s.t2) return -1;

        return (r - l + 2 - s.same)/2;
    }

};
string a, b;
SegTree st;

void init(string t1, string t2)
{
    st.init(t1.length());
    st.build(t1, t2);
}

int get_distance(int x, int y)
{
    return st.get(x, y);
}

컴파일 시 표준 에러 (stderr) 메시지

dna.cpp: In member function 'void SegTree::build(int, int, int, std::string&, std::string&)':
dna.cpp:53:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             if (l >= a.length()) return;
      |                 ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...