Submission #573219

# Submission time Handle Problem Language Result Execution time Memory
573219 2022-06-06T09:21:20 Z SSRS Collider (IZhO11_collider) C++14
100 / 100
52 ms 3192 KB
#include <bits/stdc++.h>
using namespace std;
const int B = 1000;
int main(){
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  int cnt = (n + B - 1) / B;
  vector<string> t(cnt);
  for (int i = 0; i < n; i++){
    t[i / B] += s[i];
  }
  for (int i = 0; i < m; i++){
    char c;
    cin >> c;
    if (c == 'a'){
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      char p;
      for (int j = 0; j < cnt; j++){
        if (x < t[j].size()){
          p = t[j][x];
          t[j].erase(t[j].begin() + x);
          break;
        }
        x -= t[j].size();
      }
      for (int j = 0; j < cnt; j++){
        if (y <= t[j].size()){
          t[j].insert(t[j].begin() + y, p);
          break;
        }
        y -= t[j].size();
      }
    }
    if (c == 'q'){
      int x;
      cin >> x;
      x--;
      for (int j = 0; j < cnt; j++){
        if (x < t[j].size()){
          cout << t[j][x] << endl;
          break;
        }
        x -= t[j].size();
      }
    }
  }
}

Compilation message

collider.cpp: In function 'int main()':
collider.cpp:24:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         if (x < t[j].size()){
      |             ~~^~~~~~~~~~~~~
collider.cpp:32:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         if (y <= t[j].size()){
      |             ~~^~~~~~~~~~~~~~
collider.cpp:44:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         if (x < t[j].size()){
      |             ~~^~~~~~~~~~~~~
collider.cpp:33:42: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |           t[j].insert(t[j].begin() + y, p);
      |                                          ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 224 KB Output is correct
2 Correct 8 ms 308 KB Output is correct
3 Correct 8 ms 596 KB Output is correct
4 Correct 35 ms 2684 KB Output is correct
5 Correct 37 ms 2568 KB Output is correct
6 Correct 43 ms 2916 KB Output is correct
7 Correct 48 ms 3192 KB Output is correct
8 Correct 36 ms 3136 KB Output is correct
9 Correct 52 ms 3164 KB Output is correct
10 Correct 45 ms 3188 KB Output is correct