제출 #479934

#제출 시각아이디문제언어결과실행 시간메모리
479934glomeDNA 돌연변이 (IOI21_dna)C++17
56 / 100
114 ms17496 KiB
#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); }

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

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 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...