Cod sursa(job #2977861)

Utilizator JustinTrudeauBarack Obama JustinTrudeau Data 12 februarie 2023 16:21:35
Problema Secv8 Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.2 kb
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include <numeric>

using namespace std;

struct Dumb {
	vector<int> elements;
	void ins(int k, int e) {
		k--;
		assert(0 <= k && k <= (int)elements.size());
		vector<int> newElements;
		for (int i = 0; i < k; i++) newElements.push_back(elements[i]);
		newElements.push_back(e);
		for (int i = k; i < (int)elements.size(); i++) newElements.push_back(elements[i]);
		elements = newElements;
	}
	int get(int k) {
		k--;
		assert(0 <= k && k < (int)elements.size());
		return elements[k];
	}
	void rev(int l, int r) {
		l--;
		r--;
		assert(0 <= l && l <= r && r < (int)elements.size());
		reverse(elements.begin() + l, elements.begin() + r + 1);
	}
	void del(int l, int r) {
		l--;
		r--;
		assert(0 <= l && l <= r && r < (int)elements.size());
		vector<int> newElements;
		for (int i = 0; i < l; i++) newElements.push_back(elements[i]);
		for (int i = r + 1; i < (int)elements.size(); i++) newElements.push_back(elements[i]);
		elements = newElements;
	}
};

signed main() {
#ifdef INFOARENA
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("secv8.in", "r", stdin);
	freopen("secv8.out", "w", stdout);
#else
	FILE* stream;
	freopen_s(&stream, "input.txt", "r", stdin);
#endif

	Dumb d;

	int q, _;
	cin >> q >> _;
	for (int iq = 1; iq <= q; iq++) {
		string s;
		cin >> s;
		if (s == "I") {
			int k, e;
			cin >> k >> e;
			d.ins(k, e);
			continue;
		}
		if (s == "A") {
			int k;
			cin >> k;
			cout << d.get(k) << "\n";
			continue;
		}
		if (s == "R") {
			int l, r;
			cin >> l >> r;
			d.rev(l, r);
			continue;
		}
		if (s == "D") {
			int l, r;
			cin >> l >> r;
			d.del(l, r);
			continue;
		}
		assert(0);
	}
	for (auto& x : d.elements) {
		cout << x << " ";
	}
	cout << "\n";

	return 0;
}