Submission #250546

#TimeUsernameProblemLanguageResultExecution timeMemory
250546waynetuinforLollipop (POI11_liz)C++17
100 / 100
869 ms112532 KiB
#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)

liz.cpp: In function 'int main()':
liz.cpp:35:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int k = 0; k < qry[j].size(); ++k) ql[qry[j][k]] = qr[qry[j][k]] = -1;
                                 ~~^~~~~~~~~~~~~~~
liz.cpp:41:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int k = 0; k < qry[j].size(); ++k) ql[qry[j][k]] = qr[qry[j][k]] = -1;
                             ~~^~~~~~~~~~~~~~~
liz.cpp:44:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int k = 0; k < qry[j].size(); ++k) ql[qry[j][k]] = l, qr[qry[j][k]] = r;
                             ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...