Submission #573203

# Submission time Handle Problem Language Result Execution time Memory
573203 2022-06-06T09:01:43 Z SSRS Collider (IZhO11_collider) C++14
100 / 100
170 ms 4384 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();
      }
    }
    if (i % B == B - 1){
      s.clear();
      for (int j = 0; j < cnt; j++){
        s += t[j];
        t[j].clear();
      }
      for (int j = 0; j < n; j++){
        t[j / B] += s[j];
      }
    }
  }
}

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 1 ms 212 KB Output is correct
2 Correct 8 ms 340 KB Output is correct
3 Correct 13 ms 696 KB Output is correct
4 Correct 62 ms 3452 KB Output is correct
5 Correct 100 ms 3524 KB Output is correct
6 Correct 131 ms 3900 KB Output is correct
7 Correct 143 ms 4364 KB Output is correct
8 Correct 75 ms 4160 KB Output is correct
9 Correct 170 ms 4384 KB Output is correct
10 Correct 123 ms 4288 KB Output is correct