Submission #537943

# Submission time Handle Problem Language Result Execution time Memory
537943 2022-03-15T23:54:52 Z GioChkhaidze Collider (IZhO11_collider) C++14
0 / 100
9 ms 956 KB
#include <bits/stdc++.h>

using namespace std;

string s;
vector < int > v[10003];
int n, m, bs = 1000, a[1000006];

main () {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);

	cin >> n >> m >> s;
	for (int i = 0; i < s.size(); ++i) {
		v[i / bs].push_back(i);
	}
	int ms = (n - 1) / bs + 1;
	for (int i = 1; i <= m; ++i) {
		char c;
		cin >> c;
		if (c == 'a') {
			int id = 0, l, r;
			cin >> l >> r; --l, --r;
			for (int b = 0; b < ms; ++b) {
				if (!v[b].size()) continue;
				if (v[b].size() <= l) {
					l -= v[b].size();
				}
					else {
					id = v[b][l];
					v[b].erase(v[b].begin() + l);
					break;
				}
			}
			
			for (int b = 0; b < ms; ++b) {
				if (!v[b].size()) continue;
				if (v[b].size() <= r) {
					r -= v[b].size();
				}
					else {
					v[b].insert(v[b].begin() + r, id);
					break;
				}
			}
		}
			else 
		if (c == 'q') {
			int x;
			cin >> x; --x;
			for (int b = 0; b < ms; ++b) {
				if (!v[b].size()) continue;
				if (v[b].size() <= x) {
					x -= v[b].size();
				}
					else {
					cout << s[v[b][x]] << "\n";
					break;
				}
			}
		}
		
		if (i % bs == 0) {
			vector < int > rec;
			for (int b = 0; b < ms; ++b) {
				for (int j = 0; j < v[b].size(); ++j) {
					rec.push_back(v[b][j]);
				}
			}
			for (int j = 0; j < rec.size(); ++j) {
				v[j / bs].push_back(rec[j]);
			}
			rec.clear();
		}
	}
}

Compilation message

collider.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main () {
      | ^~~~
collider.cpp: In function 'int main()':
collider.cpp:14:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for (int i = 0; i < s.size(); ++i) {
      |                  ~~^~~~~~~~~~
collider.cpp:26:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |     if (v[b].size() <= l) {
      |         ~~~~~~~~~~~~^~~~
collider.cpp:38:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |     if (v[b].size() <= r) {
      |         ~~~~~~~~~~~~^~~~
collider.cpp:53:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   53 |     if (v[b].size() <= x) {
      |         ~~~~~~~~~~~~^~~~
collider.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for (int j = 0; j < v[b].size(); ++j) {
      |                     ~~^~~~~~~~~~~~~
collider.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |    for (int j = 0; j < rec.size(); ++j) {
      |                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Incorrect 9 ms 956 KB Output isn't correct
3 Halted 0 ms 0 KB -