0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:05:26 +00:00

P3514 [POI2011]LIZ-Lollipop

https://www.luogu.com.cn/record/92628223
This commit is contained in:
Baoshuo Ren 2022-11-03 10:37:33 +08:00
parent 7a99b6b16e
commit 0a6ff1cad8
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

58
Luogu/P3514/P3514.cpp Normal file
View File

@ -0,0 +1,58 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e6 + 5,
M = 2e6 + 5;
int n, m, a[N], s[N], l[M], r[M];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
char c;
cin >> c;
a[i] = c == 'T' ? 2 : 1;
}
for (int i = n; i; i--) {
s[i] = a[i] == 2 ? s[i + 1] + 1 : 0;
}
for (int i = 1, sum = 0; i <= n; i++) {
sum += a[i];
l[sum] = 1, r[sum] = i;
if (a[i] == 2) {
if (s[i] > s[1]) {
l[sum - 1] = s[1] + 2;
r[sum - 1] = s[1] + i;
} else if (s[i] != n - i + 1) {
l[sum - 1] = s[i] + 1;
r[sum - 1] = s[i] + i;
}
}
}
while (m--) {
int k;
cin >> k;
if (!l[k]) {
cout << "NIE" << endl;
} else {
cout << l[k] << ' ' << r[k] << endl;
}
}
return 0;
}