This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// KALAM
# include<bits/stdc++.h>
using namespace std;
const int N = 2000000 + 77;
int n , q , ps[N] , L[N] , R[N];
char S[N];
inline int Get(int l , int r) {
if(l > r) return 0;
return ps[r] - ps[l - 1];
}
int main() {
scanf("%d %d" , & n , & q);
scanf("%s" , S + 1);
for(int i = 1;i <= n;++ i)
ps[i] = ps[i - 1] + 1 + (S[i] == 'T');
for(int i = 1;i <= n;++ i)
L[Get(1 , i)] = 1 , R[Get(1 , i)] = i , L[Get(i , n)] = i , R[Get(i , n)] = n;
int best_i = -1;
for(int i = 1;i <= n;++ i)
if(S[i] == 'W' && (best_i < 0 || max(ps[i] , ps[n] - ps[i - 1]) > max(ps[best_i] , ps[n] - ps[best_i - 1])))
best_i = i;
for(int i = best_i;i <= n;++ i)
L[Get(best_i , i)] = best_i , R[Get(best_i , i)] = i;
for(int i = best_i;i > 0;-- i)
L[Get(i , best_i)] = i , R[Get(i , best_i)] = best_i;
-- best_i;
if(best_i > 0 && best_i <= n) {
for(int i = best_i;i <= n;++ i)
L[Get(best_i , i)] = best_i , R[Get(best_i , i)] = i;
for(int i = best_i;i > 0;-- i)
L[Get(i , best_i)] = i , R[Get(i , best_i)] = best_i;
}
best_i += 2;
if(best_i > 0 && best_i <= n) {
for(int i = best_i;i <= n;++ i)
L[Get(best_i , i)] = best_i , R[Get(best_i , i)] = i;
for(int i = best_i;i > 0;-- i)
L[Get(i , best_i)] = i , R[Get(i , best_i)] = best_i;
}
while(q --) {
int x;
scanf("%d" , & x);
if(L[x] == 0) printf("NIE\n");
else printf("%d %d\n" , L[x] , R[x]);
}
return 0;
}
Compilation message (stderr)
liz.cpp: In function 'int main()':
liz.cpp:14:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d" , & n , & q);
~~~~~^~~~~~~~~~~~~~~~~~~~~
liz.cpp:15:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s" , S + 1);
~~~~~^~~~~~~~~~~~~~
liz.cpp:44:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d" , & 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... |