#include <bits/stdc++.h>
#define in(x) ll x;cin>>x;
#define al(x) x.begin(),x.end()
#define vc vector
#define fo(i,a,b) for(ll i=a;i<b;i++)
using namespace std;
using ll = int; // mem
int main(){
cin.sync_with_stdio(false);
cout.sync_with_stdio(false);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
in(n);in(m);
vc<ll> ar(2*n+50,-1);
vc<ll> ps(2*n+50,-1);
vc<ll> is(2*n+50,-1);
ll cnt = 0;
ll fst = -1;
fo(i,0,n){
char c;cin>>c;
bool tp = (c=='T');
if(fst==-1 && !tp){fst = cnt;}
ar[cnt]=i;
ps[i]=cnt;
cnt++; cnt+=tp;
}
if(fst==-1){fst = cnt;}
ar[cnt] = n;
ps[n] = cnt;
ll sz = ar[fst];
ll c[2] = {2,1};
fo(i,ar[fst]-1,n){
ll v = ps[i+1]-fst;
//cout<<v<<" "<<c[v%2]<<endl;
for(ll j = max(v,c[v%2]); j <= min((ll)(2*n),v+2*sz); j+=2){
//assert(is[j] == -1);
is[j] = i;
//cerr<<"oh "<<j<<" "<<i<<endl;
}
c[v%2] = v+2*sz+2;
}
/*fo(i,1,sz+1){
is[2*i] = ar[fst]-1;
}*/
fo(z,0,m){
in(k);
ll l=-1,r=-1;
if(fst+k<cnt){
if(ar[fst+k]==-1){
l = ar[fst]+1;
r = ar[fst+k-1];
}
else{
l = ar[fst];
r = ar[fst+k]-1;
}
}
else {
if(is[k]!=-1){
r = is[k];
l = ar[ps[r+1]-k];
}
}
if(l!=-1){
cout<<l+1<<" "<<r+1<<endl;
}
else {
cout<<"NIE"<<endl;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
356 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
508 KB |
Output is correct |
2 |
Correct |
3 ms |
508 KB |
Output is correct |
3 |
Correct |
5 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
540 KB |
Output is correct |
2 |
Correct |
3 ms |
540 KB |
Output is correct |
3 |
Correct |
41 ms |
668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
672 KB |
Output is correct |
2 |
Correct |
23 ms |
816 KB |
Output is correct |
3 |
Correct |
27 ms |
880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
1280 KB |
Output is correct |
2 |
Correct |
54 ms |
1280 KB |
Output is correct |
3 |
Correct |
201 ms |
2192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
2732 KB |
Output is correct |
2 |
Correct |
814 ms |
5580 KB |
Output is correct |
3 |
Correct |
417 ms |
5580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
177 ms |
5580 KB |
Output is correct |
2 |
Correct |
206 ms |
5580 KB |
Output is correct |
3 |
Correct |
419 ms |
5580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
661 ms |
5636 KB |
Output is correct |
2 |
Correct |
699 ms |
5636 KB |
Output is correct |
3 |
Correct |
899 ms |
8752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1156 ms |
14944 KB |
Output is correct |
2 |
Correct |
1255 ms |
14944 KB |
Output is correct |
3 |
Correct |
1341 ms |
18556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1105 ms |
18556 KB |
Output is correct |
2 |
Correct |
1494 ms |
19856 KB |
Output is correct |
3 |
Correct |
1461 ms |
23360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2066 ms |
32788 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2051 ms |
36352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |