Submission #599248

#TimeUsernameProblemLanguageResultExecution timeMemory
599248lcjMutating DNA (IOI21_dna)C++17
21 / 100
56 ms4976 KiB
#include <bits/stdc++.h>
#include "dna.h"

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define LSOne(S) ((S) & -(S))

struct Fenwick {
    vector<int> ft;
    Fenwick(int n) : ft(n+1, 0) {}
    int qry(int i) {
        int su = 0;
        for (; i > 0; i -= LSOne(i)) {
            su += ft[i];
        }
        return su;
    }
    int qry(int i, int j) {
        return qry(j)-qry(i-1);
    }
    void upd(int i, int dv) {
        for (; i < ft.size(); i += LSOne(i)) {
            ft[i] += dv;
        }
    }
};

map<char, int> cmap = {
    {'A', 0},
    {'T', 1},
    {'C', 2}
};
vector<Fenwick> o1;
vector<Fenwick> o2;

void init(string a, string b) {
    int n = a.size();
    o1.assign(3, Fenwick(n));
    o2.assign(3, Fenwick(n));
    for (int i = 0; i < n; i++)
    {
        if (a[i] == b[i]) continue;
        o1[cmap[a[i]]].upd(i+1, 1);
        o2[cmap[b[i]]].upd(i+1, 1);
    }
}

int get_distance(int x, int y) {
    int su = 0;
    bool val = 1;
    for (int i = 0; i < 3; i++)
    {
        if (o1[i].qry(x+1, y+1) != o2[i].qry(x+1, y+1)) {
            val = 0;break;
        }
        su += o1[i].qry(x+1, y+1);
    }
    if (!val) {
        return -1;
    }
    if (su == 0) return 0;
    return su-1;
}

Compilation message (stderr)

dna.cpp: In member function 'void Fenwick::upd(int, int)':
dna.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (; i < ft.size(); i += LSOne(i)) {
      |                ~~^~~~~~~~~~~
#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...