Submission #217953

#TimeUsernameProblemLanguageResultExecution timeMemory
217953KalamLollipop (POI11_liz)C++11
100 / 100
503 ms41940 KiB
// 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...