# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
442020 | penguinhacker | Election (BOI18_election) | C++14 | 1 ms | 588 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN=5e5;
int n, q, lg[mxN+1], st1[mxN][19], st2[mxN][19];
string s;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> s >> q;
for (int i=0; i<n; ++i)
st1[i][0]=(i?st1[i-1][0]:0)+(s[i]=='T'?1:-1);
for (int i=n-1; ~i; --i)
st2[i][0]=(i+1<n?st2[i+1][0]:0)+(s[i]=='T'?1:-1);
for (int i=2; i<=n; ++i)
lg[i]=lg[i/2]+1;
for (int j=1; 1<<j<=n; ++j)
for (int i=0; i+(1<<j)-1<n; ++i) {
st1[i][j]=max(st1[i][j-1], st1[i+(1<<j-1)][j-1]);
st2[i][j]=max(st2[i][j-1], st2[i+(1<<j-1)][j-1]);
}
while(q--) {
int l, r;
cin >> l >> r, --l, --r;
int k=lg[r-l+1];
int a1=max(st1[l][k], st1[r-(1<<k)+1][k])-(l?st1[l-1][0]:0);
int a2=max(st2[l][k], st2[r-(1<<k)+1][k])-(r+1<n?st2[r+1][0]:0);
cout << max({0, a1, a2}) << "\n";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |