# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
250546 | waynetuinfor | Lollipop (POI11_liz) | C++17 | 869 ms | 112532 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 1;
int s[maxn / 2], fr[2], ql[maxn], qr[maxn];
vector<int> qry[maxn];
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n, m; cin >> n >> m;
string t; cin >> t;
for (int i = 1; i <= n; ++i) {
int a = (t[i - 1] == 'T' ? 2 : 1);
s[i] = a + s[i - 1];
}
// for (int i = 1; i <= n; ++i) cout << s[i] << ' '; cout << endl;
for (int i = 0; i < m; ++i) {
int k; cin >> k;
qry[k].push_back(i);
}
for (int i = 0; i < 2; ++i) {
int prv = -1, l = -1, r = -1;
fr[0] = 0; fr[1] = -1;
for (int j = 1; j <= n; ++j) {
if (fr[(s[j] & 1) ^ i] != -1) {
if (prv < s[j] - s[fr[(s[j] & 1) ^ i]]) {
prv = s[j] - s[fr[(s[j] & 1) ^ i]];
l = fr[(s[j] & 1) ^ i] + 1; r = j;
}
}
if (fr[s[j] & 1] == -1 || fr[s[j] & 1] > s[j]) fr[s[j] & 1] = j;
}
if (l == -1) {
for (int j = i; j < maxn; j += 2) {
for (int k = 0; k < qry[j].size(); ++k) ql[qry[j][k]] = qr[qry[j][k]] = -1;
}
continue;
}
// cout << "prv = " << prv << " l = " << l << " r = " << r << endl;
for (int j = prv + 2; j < maxn; j += 2) {
for (int k = 0; k < qry[j].size(); ++k) ql[qry[j][k]] = qr[qry[j][k]] = -1;
}
for (int j = prv; j >= 1; j -= 2) {
for (int k = 0; k < qry[j].size(); ++k) ql[qry[j][k]] = l, qr[qry[j][k]] = r;
if (t[l - 1] == 'T') ++l;
else if (t[r - 1] == 'T') --r;
else ++l, --r;
}
}
for (int i = 0; i < m; ++i) {
if (ql[i] == -1) cout << "NIE" << '\n';
else cout << ql[i] << ' ' << qr[i] << '\n';
}
return 0;
}
Compilation message (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... |
# | 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... |