# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167508 | Thuleanx | Lollipop (POI11_liz) | C++14 | 539 ms | 51088 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;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m; cin>>n>>m;
string s; cin>>s;
int p[n];
for (int i = 0; i < n; i++)
p[i] = (i?p[i-1]:0) + (s[i] == 'T' ? 2 : 1);
int st = 0, tt = n-1;
while (st < n && s[st] == 'T')
st++;
while (tt >= 0 && s[tt] == 'T')
tt--;
stringstream ss;
while (m--) {
int x; cin>>x;
if (p[n-1] - (st?p[st-1]:0) >= x) {
// always possible
int lo = st, hi = n-1;
int left = st?p[st-1]:0;
while (lo <= hi) {
int mid = lo+hi>>1;
if (p[mid] - left >= x)
hi = mid-1;
else lo = mid+1;
}
ss << st+1+(p[lo]-left>x) << " " << lo+1 << endl;
} else if (p[tt] >= x) {
// always possible
int lo = 0, hi = tt;
while (lo <= hi) {
int mid = lo+hi>>1;
if (p[tt] - (mid?p[mid-1]:0) >= x)
lo = mid+1;
else hi = mid-1;
}
ss << hi+1 << " " << tt + 1 - (p[tt] - (hi?p[hi-1]:0) > x) << endl;
} else {
// maybe not
int lo = 0, hi = n-1;
while (lo <= hi) {
int mid = lo+hi>>1;
if (p[mid] >= x) hi = mid-1;
else lo = mid+1;
}
if (p[lo] == x)
ss << 1 << " " << lo+1 << endl;
else
ss << "NIE" << endl;
}
}
cout << ss.str();
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... |