이 제출은 이전 버전의 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.first = max((l -> v).first, (r -> v).first);
v.second = max(min((l -> v).first, (r -> v).first), max((l -> v).second, (r -> v).second));
} else v = ii(0, 0);
}
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.first = max((l -> v).first, (r -> v).first);
v.second = max(min((l -> v).first, (r -> v).first), max((l -> v).second, (r -> v).second));
}
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);
ii x = l -> v, y = r -> v;
return ii(max(x.first, y.first), max(min(x.first, y.first), max(x.second, y.second)));
}
} *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) ans = max(ans, (root[j] -> query(a[i] - 1, b[i] - 1)).second);
}
printf("%d", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
grudanje.cpp: In function 'int main()':
grudanje.cpp:45:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < S.size(); ++i) cin >> p[i];
~~^~~~~~~~~~
grudanje.cpp:47: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... |