# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
250546 | 2020-07-18T09:49:09 Z | waynetuinfor | Lollipop (POI11_liz) | C++17 | 869 ms | 112532 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47376 KB | Output is correct |
2 | Correct | 39 ms | 47360 KB | Output is correct |
3 | Correct | 33 ms | 47360 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47360 KB | Output is correct |
2 | Correct | 32 ms | 47360 KB | Output is correct |
3 | Correct | 34 ms | 47352 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47360 KB | Output is correct |
2 | Correct | 33 ms | 47360 KB | Output is correct |
3 | Correct | 47 ms | 47992 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 47744 KB | Output is correct |
2 | Correct | 36 ms | 47864 KB | Output is correct |
3 | Correct | 44 ms | 47864 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 48376 KB | Output is correct |
2 | Correct | 48 ms | 48376 KB | Output is correct |
3 | Correct | 78 ms | 50936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 66 ms | 51252 KB | Output is correct |
2 | Correct | 179 ms | 61304 KB | Output is correct |
3 | Correct | 105 ms | 55032 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 65 ms | 51192 KB | Output is correct |
2 | Correct | 76 ms | 52236 KB | Output is correct |
3 | Correct | 115 ms | 55416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 209 ms | 60664 KB | Output is correct |
2 | Correct | 198 ms | 60024 KB | Output is correct |
3 | Correct | 223 ms | 63876 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 399 ms | 77580 KB | Output is correct |
2 | Correct | 399 ms | 77228 KB | Output is correct |
3 | Correct | 446 ms | 80776 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 367 ms | 76428 KB | Output is correct |
2 | Correct | 465 ms | 82444 KB | Output is correct |
3 | Correct | 650 ms | 90260 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 869 ms | 105492 KB | Output is correct |
2 | Correct | 737 ms | 94228 KB | Output is correct |
3 | Correct | 711 ms | 105028 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 761 ms | 106548 KB | Output is correct |
2 | Correct | 866 ms | 105420 KB | Output is correct |
3 | Correct | 477 ms | 112532 KB | Output is correct |