# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
479934 |
2021-10-14T01:30:37 Z |
glome |
Mutating DNA (IOI21_dna) |
C++17 |
|
114 ms |
17496 KB |
#include "dna.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<long long>> pref1(1e5, vector<long long> (3, 0)), pref2(1e5, vector<long long> (3, 0));
vector<long long> sum(1e5, 0);
long long n;
struct seg {
vector<long long> t = vector<long long> (1e5 * 4);
void build(long long x, long long l, long long r) {
if(l == r) {
t[x] = sum[l];
return;
}
long long m = (l + r) / 2;
build(2 * x, l, m);
build(2 * x + 1, m + 1, r);
t[x] = t[2 * x] + t[2 * x + 1];
}
void build() {
build(1, 0, n - 1);
}
long long ans(long long x, long long lx, long long rx, long long l, long long r) {
if(lx >= l && rx <= r) {
return t[x];
}
if(lx > r || rx < l) {
return 0;
}
long long m = (lx + rx) / 2;
return ans(2 * x, lx, m, l, r) + ans(2 * x + 1, m + 1, rx, l, r);
}
long long ans(long long l, long long r) {
return ans(1, 0, n - 1, l, r);
}
};
seg st;
void init(std::string a, std::string b) {
n = a.size();;
for (long long i = 0; i<a.size(); i++) {
pref1[i][0] = pref1[max(i-1, 0LL)][0];
pref1[i][1] = pref1[max(i-1, 0LL)][1];
pref1[i][2] = pref1[max(i-1, 0LL)][2];
pref2[i][0] = pref2[max(i-1, 0LL)][0];
pref2[i][1] = pref2[max(i-1, 0LL)][1];
pref2[i][2] = pref2[max(i-1, 0LL)][2];
if(a[i] == 'A') {
pref1[i][0] += 1;
}
if(a[i] == 'T') {
pref1[i][1] += 1;
}
if(a[i] == 'C') {
pref1[i][2] += 1;
}
if(b[i] == 'A') {
pref2[i][0] += 1;
}
if(b[i] == 'T') {
pref2[i][1] += 1;
}
if(b[i] == 'C') {
pref2[i][2] += 1;
}
if(a[i] != b[i]) {
sum[i]++;
}
}
st.build();
}
int get_distance(int x, int y) {
if(pref1[y][0] - (x - 1 < 0LL ? 0LL : pref1[max(x-1, 0)][0]) != pref2[y][0] - (x - 1 < 0 ? 0 : pref2[max(x-1, 0)][0]) || pref1[y][1] - (x - 1 < 0 ? 0 : pref1[max(x-1, 0)][1]) != pref2[y][1] - (x - 1 < 0 ? 0 : pref2[max(x-1, 0)][1]) || pref1[y][2] - (x - 1 < 0 ? 0 : pref1[max(x-1, 0)][2]) != pref2[y][2] - (x - 1 < 0 ? 0 : pref2[max(x-1, 0)][2])) {
return -1;
}
long long k = st.ans(x, y);
return (k & 1 ? k / 2 + 1 : k / 2);
}
Compilation message
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:46:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (long long i = 0; i<a.size(); i++) {
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
17028 KB |
Output is correct |
2 |
Correct |
90 ms |
16948 KB |
Output is correct |
3 |
Correct |
79 ms |
16908 KB |
Output is correct |
4 |
Correct |
81 ms |
16956 KB |
Output is correct |
5 |
Correct |
16 ms |
15180 KB |
Output is correct |
6 |
Correct |
13 ms |
15180 KB |
Output is correct |
7 |
Correct |
13 ms |
15180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
15072 KB |
Output is correct |
2 |
Correct |
15 ms |
15172 KB |
Output is correct |
3 |
Correct |
14 ms |
15180 KB |
Output is correct |
4 |
Correct |
19 ms |
15692 KB |
Output is correct |
5 |
Correct |
18 ms |
15692 KB |
Output is correct |
6 |
Correct |
19 ms |
15756 KB |
Output is correct |
7 |
Correct |
19 ms |
15692 KB |
Output is correct |
8 |
Correct |
18 ms |
15768 KB |
Output is correct |
9 |
Correct |
18 ms |
15692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
15072 KB |
Output is correct |
2 |
Correct |
15 ms |
15172 KB |
Output is correct |
3 |
Correct |
14 ms |
15180 KB |
Output is correct |
4 |
Correct |
19 ms |
15692 KB |
Output is correct |
5 |
Correct |
18 ms |
15692 KB |
Output is correct |
6 |
Correct |
19 ms |
15756 KB |
Output is correct |
7 |
Correct |
19 ms |
15692 KB |
Output is correct |
8 |
Correct |
18 ms |
15768 KB |
Output is correct |
9 |
Correct |
18 ms |
15692 KB |
Output is correct |
10 |
Correct |
95 ms |
16992 KB |
Output is correct |
11 |
Correct |
80 ms |
16988 KB |
Output is correct |
12 |
Correct |
100 ms |
17296 KB |
Output is correct |
13 |
Correct |
104 ms |
17352 KB |
Output is correct |
14 |
Correct |
103 ms |
17436 KB |
Output is correct |
15 |
Correct |
114 ms |
17348 KB |
Output is correct |
16 |
Correct |
104 ms |
17288 KB |
Output is correct |
17 |
Correct |
98 ms |
17288 KB |
Output is correct |
18 |
Correct |
98 ms |
17496 KB |
Output is correct |
19 |
Correct |
83 ms |
17396 KB |
Output is correct |
20 |
Correct |
85 ms |
17416 KB |
Output is correct |
21 |
Correct |
83 ms |
17420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
15072 KB |
Output is correct |
2 |
Correct |
15 ms |
15172 KB |
Output is correct |
3 |
Correct |
14 ms |
15180 KB |
Output is correct |
4 |
Correct |
19 ms |
15692 KB |
Output is correct |
5 |
Correct |
18 ms |
15692 KB |
Output is correct |
6 |
Correct |
19 ms |
15756 KB |
Output is correct |
7 |
Correct |
19 ms |
15692 KB |
Output is correct |
8 |
Correct |
18 ms |
15768 KB |
Output is correct |
9 |
Correct |
18 ms |
15692 KB |
Output is correct |
10 |
Correct |
17 ms |
15692 KB |
Output is correct |
11 |
Correct |
20 ms |
15692 KB |
Output is correct |
12 |
Incorrect |
18 ms |
15692 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
17028 KB |
Output is correct |
2 |
Correct |
90 ms |
16948 KB |
Output is correct |
3 |
Correct |
79 ms |
16908 KB |
Output is correct |
4 |
Correct |
81 ms |
16956 KB |
Output is correct |
5 |
Correct |
16 ms |
15180 KB |
Output is correct |
6 |
Correct |
13 ms |
15180 KB |
Output is correct |
7 |
Correct |
13 ms |
15180 KB |
Output is correct |
8 |
Correct |
14 ms |
15072 KB |
Output is correct |
9 |
Correct |
15 ms |
15172 KB |
Output is correct |
10 |
Correct |
14 ms |
15180 KB |
Output is correct |
11 |
Correct |
19 ms |
15692 KB |
Output is correct |
12 |
Correct |
18 ms |
15692 KB |
Output is correct |
13 |
Correct |
19 ms |
15756 KB |
Output is correct |
14 |
Correct |
19 ms |
15692 KB |
Output is correct |
15 |
Correct |
18 ms |
15768 KB |
Output is correct |
16 |
Correct |
18 ms |
15692 KB |
Output is correct |
17 |
Correct |
95 ms |
16992 KB |
Output is correct |
18 |
Correct |
80 ms |
16988 KB |
Output is correct |
19 |
Correct |
100 ms |
17296 KB |
Output is correct |
20 |
Correct |
104 ms |
17352 KB |
Output is correct |
21 |
Correct |
103 ms |
17436 KB |
Output is correct |
22 |
Correct |
114 ms |
17348 KB |
Output is correct |
23 |
Correct |
104 ms |
17288 KB |
Output is correct |
24 |
Correct |
98 ms |
17288 KB |
Output is correct |
25 |
Correct |
98 ms |
17496 KB |
Output is correct |
26 |
Correct |
83 ms |
17396 KB |
Output is correct |
27 |
Correct |
85 ms |
17416 KB |
Output is correct |
28 |
Correct |
83 ms |
17420 KB |
Output is correct |
29 |
Correct |
17 ms |
15692 KB |
Output is correct |
30 |
Correct |
20 ms |
15692 KB |
Output is correct |
31 |
Incorrect |
18 ms |
15692 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |