// #pragma GCC optimize("no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC diagnostic ignored "-W"
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#include <utility>
#include <functional>
#include <complex>
#include <climits>
#include <random>
#include <thread>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#endif
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/rope>
using namespace std;
// using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define vint vector<int>
#define vpii vector<pair<int, int>>
#define SS stringstream
#define PQ priority_queue
#define MS(x, v) memset((x), (v), sizeof(x))
#define RZUNI(x) sort(x.begin(), x.end()), x.resize(unique(x.begin(), x.end()) - x.begin())
#define FLH fflush(stdout)
#define CPPinput ios_base::sync_with_stdio(0), cin.tie(0)
#define FIO(fname) freopen(fname ".in", "r", stdin), freopen(fname ".out", "w", stdout)
#define FIN(fname) freopen(fname, "r", stdin)
#define FOUT(fname) freopen(fname, "w", stdout)
#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define expl explexplexpl
#define data datadetedoto
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#ifdef WEAK
#include"/home/edison/Coding/cpp/template/debug.cpp"
#define DEB(...) printf(__VA_ARGS__), fflush(stdout)
#define WHR() printf("%s: Line %d", __PRETTY_FUNCTION__, __LINE__), fflush(stdout)
#define LOG(...) printf("%s: Line %d ", __PRETTY_FUNCTION__, __LINE__), printf(__VA_ARGS__), fflush(stdout)
#define DEBUG 1
#define exit(x) cout << "exit code " << x << endl, exit(0)
#else
#define PDE(...) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define DEBUG 0
#endif
#define lowbit(x) ((x) & (-(x)))
void JIZZ(string output = ""){ cout << output; exit(0); }
const long double PI = 3.14159265358979323846264338327950288;
const long double eps = 1e-10;
const long long mod = 1e9+7;
int main() {
CPPinput;
int n, m; cin >> n >> m;
string s; cin >> s; s = " " + s;
vector<int> pre(n + 1, 0);
for (int i = 1; i <= n; ++i) s[i] = s[i] == 'W' ? 1 : 2;
for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + s[i];
vector<pair<int, int>> ans(n * 2 + 1, pair<int, int>(-1, -1));
bool all2 = true;
for (int i = 1; i <= n; ++i) if (s[i] == 1) all2 = false;
if (all2) {
for (int i = 1; i <= n; ++i) ans[i * 2] = make_pair(1, i);
} else {
int l2 = 0, r2 = 0;
while (s[l2 + 1] == 2) ++l2;
while (s[n - r2] == 2) ++r2;
auto Add = [&] (int l, int r) {
if (l > r) return;
PDE(l, r, pre[r] - pre[l - 1]);
ans[pre[r] - pre[l - 1]] = make_pair(l, r);
};
PDE(l2, r2);
if (l2 > r2) {
for (int l = 1; l <= n - r2; ++l) Add(l, n - r2), Add(l, n - r2 - 1);
for (int r = n - r2; r <= n; ++r) Add(1, r);
} else {
for (int r = l2; r <= n; ++r) Add(l2 + 1, r), Add(l2 + 2, r);
for (int l = 1; l <= l2; ++l) Add(l, n);
}
}
while (m--) {
int x; cin >> x;
if (ans[x].first == -1) cout << "NIE" << '\n';
else cout << ans[x].first << ' ' << ans[x].second << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Liczba calkowita spoza zakresu |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
3 |
Correct |
4 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1152 KB |
Output is correct |
2 |
Correct |
7 ms |
1024 KB |
Output is correct |
3 |
Correct |
30 ms |
2424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
2936 KB |
Output is correct |
2 |
Correct |
112 ms |
8568 KB |
Output is correct |
3 |
Correct |
57 ms |
4984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
3196 KB |
Output is correct |
2 |
Correct |
26 ms |
3196 KB |
Output is correct |
3 |
Correct |
59 ms |
5620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
7284 KB |
Output is correct |
2 |
Correct |
86 ms |
7668 KB |
Output is correct |
3 |
Correct |
148 ms |
10860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
204 ms |
18532 KB |
Output is correct |
2 |
Correct |
208 ms |
18400 KB |
Output is correct |
3 |
Correct |
274 ms |
22276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
20508 KB |
Output is correct |
2 |
Correct |
239 ms |
25760 KB |
Output is correct |
3 |
Correct |
304 ms |
27588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
413 ms |
38940 KB |
Output is correct |
2 |
Correct |
363 ms |
39712 KB |
Output is correct |
3 |
Correct |
409 ms |
37152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
420 ms |
43068 KB |
Output is correct |
2 |
Correct |
401 ms |
38176 KB |
Output is correct |
3 |
Correct |
339 ms |
42808 KB |
Output is correct |