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;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1e6 + 5;
int n, m, a[NMAX], l, r;
pair<int, int> ans[NMAX * 2];
string s;
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> s;
for(int i = 1; i <= n; i++) a[i] = (s[i -1] == 'T') ? 2 : 1;
l = 1; r = n;
while(a[l] == 2) l++;
while(a[r] == 2) r--;
if(l <= r){
int s = 0;
for(int i = r; i; i--){
s += a[i];
ans[s] = {i, r};
ans[s - a[r]] = {i, r - 1};
}
s = 0;
for(int i = l; i <= n; i++){
s += a[i];
ans[s] = {l, i};
ans[s - a[l]] = {l + 1, i};
}
for(int i = l - 1; i; i--){
s += a[i];
ans[s] = {i, n};
}
}
else{
for(int i = 1; i <= n; i++) ans[2 * i] = {1, i};
}
while(m--){
int x; cin >> x;
auto& [a, b] = ans[x];
if(!a) cout << "NIE\n";
else cout << a << ' ' << b << '\n';
}
return 0;
}
Compilation message (stderr)
liz.cpp: In function 'int main()':
liz.cpp:45:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
45 | auto& [a, b] = ans[x];
| ^
# | 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... |