이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, int> ii;
struct seg {
int s, e, m;
ii v;
seg *l, *r;
seg(int _s, int _e) {
s = _s, e = _e, m = (s + e) / 2;
if (s != e) {
l = new seg(s, m);
r = new seg(m + 1, e);
v = max(l -> v, r -> v);
} else v = ii(0, s);
}
void update(int i, int dv) {
if (s == e) {
v.first = dv;
return;
} else if (i > m) r -> update(i, dv);
else l -> update(i, dv);
v = max(l -> v, r -> v);
}
ii query(int a, int b) {
if (s == a && e == b) return v;
if (a > m) return r -> query(a, b);
if (b <= m) return l -> query(a, b);
return max(l -> query(a, m), r -> query(m + 1, b));
}
} *root[26];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string S;
cin >> S;
int Q;
cin >> Q;
int a[Q], b[Q], p[S.size()], ans = 0;
for (int i = 0; i < Q; ++i) cin >> a[i] >> b[i];
for (int i = 0; i < S.size(); ++i) cin >> p[i];
for (int i = 0; i < 26; ++i) root[i] = new seg(0, S.size() - 1);
for (int i = 0; i < S.size(); ++i) root[S[i] - 'a'] -> update(i, p[i]);
for (int i = 0; i < Q; ++i) {
for (int j = 0; j < 26; ++j) {
ii mx = root[j] -> query(a[i] - 1, b[i] - 1);
root[j] -> update(mx.second, 0);
ans = max(ans, (root[j] -> query(a[i] - 1, b[i] - 1)).first);
root[j] -> update(mx.second, mx.first);
}
}
printf("%d", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
grudanje.cpp: In function 'int main()':
grudanje.cpp:42:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < S.size(); ++i) cin >> p[i];
~~^~~~~~~~~~
grudanje.cpp:44:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < S.size(); ++i) root[S[i] - 'a'] -> update(i, p[i]);
~~^~~~~~~~~~
# | 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... |
# | 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... |