Submission #167508

#TimeUsernameProblemLanguageResultExecution timeMemory
167508ThuleanxLollipop (POI11_liz)C++14
100 / 100
539 ms51088 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin>>n>>m; string s; cin>>s; int p[n]; for (int i = 0; i < n; i++) p[i] = (i?p[i-1]:0) + (s[i] == 'T' ? 2 : 1); int st = 0, tt = n-1; while (st < n && s[st] == 'T') st++; while (tt >= 0 && s[tt] == 'T') tt--; stringstream ss; while (m--) { int x; cin>>x; if (p[n-1] - (st?p[st-1]:0) >= x) { // always possible int lo = st, hi = n-1; int left = st?p[st-1]:0; while (lo <= hi) { int mid = lo+hi>>1; if (p[mid] - left >= x) hi = mid-1; else lo = mid+1; } ss << st+1+(p[lo]-left>x) << " " << lo+1 << endl; } else if (p[tt] >= x) { // always possible int lo = 0, hi = tt; while (lo <= hi) { int mid = lo+hi>>1; if (p[tt] - (mid?p[mid-1]:0) >= x) lo = mid+1; else hi = mid-1; } ss << hi+1 << " " << tt + 1 - (p[tt] - (hi?p[hi-1]:0) > x) << endl; } else { // maybe not int lo = 0, hi = n-1; while (lo <= hi) { int mid = lo+hi>>1; if (p[mid] >= x) hi = mid-1; else lo = mid+1; } if (p[lo] == x) ss << 1 << " " << lo+1 << endl; else ss << "NIE" << endl; } } cout << ss.str(); return 0; }

Compilation message (stderr)

liz.cpp: In function 'int main()':
liz.cpp:28:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = lo+hi>>1;
               ~~^~~
liz.cpp:38:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = lo+hi>>1;
               ~~^~~
liz.cpp:48:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = lo+hi>>1;
               ~~^~~
#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...