102742024-03-29 21:33:28szilGénsebészcpp17Wrong answer 0/1004ms4476 KiB
#include <bits/stdc++.h>
#include "grader.h"

#pragma GCC optimize("O3, unroll-loops")

using namespace std;
using ll = long long;

int char_to_index(char x) {
	if (x == 'A') return 0;
	if (x == 'C') return 1;
	if (x == 'G') return 2;
	if (x == 'T') return 3;
	throw 1;
}

struct Node {
	Node *l, *r;

	int cnt[4], prior, siz;
	char c;

	Node(char x) {
		c = x;
		fill(cnt, cnt+4, 0);
		cnt[char_to_index(x)]++;
		prior = rand();
		siz = 1;
		l = r = nullptr;
	}
};

int get_size(Node *ptr) {
	return ptr ? ptr->siz : 0;
}

void pull(Node *v) {
	v->siz = 1 + get_size(v->l) + get_size(v->r);
	fill(v->cnt, v->cnt+4, 0);
	v->cnt[char_to_index(v->c)] = 1;
	if (v->l) {
		for (int i = 0; i < 4; i++) {
			v->cnt[i] += v->l->cnt[i];
		}
	}
	if (v->r) {
		for (int i = 0; i < 4; i++) {
			v->cnt[i] += v->l->cnt[i];
		}
	} 
}

Node *merge(Node *l, Node *r) {
	if (!l || !r) return l ? l : r;
	if (l->prior > r->prior) {
		l->r = merge(l->r, r);
		pull(l);
		return l;
	} else {
		r->l = merge(l, r->l);
		pull(r);
		return r;
	}
}

pair<Node *, Node *> split(Node *v, int x) {
	if (!v) return {nullptr, nullptr};
	if (get_size(v->l) < x) {
		auto [l, r] = split(v->r, x - 1 - get_size(v->l));
		v->r = l;
		pull(v);
		return {v, r};
	} else {
		auto [l, r] = split(v->l, x);
		v->l = r;
		pull(v);
		return {l, v};
	}
}

void print(Node *v, string &res) {
	if (v->l) print(v->l, res);
	res += v->c;
	if (v->r) print(v->r, res);
}

Node *root = nullptr;

void Kezd(string s) {
	srand(2);
	for (char c : s) {
		root = merge(root, new Node(c));
	}
}

void Beszur(int i, char x) {
	auto [a, b] = split(root, i);
	root = merge(a, merge(new Node(x), b));
}

void Mutal(int i, char x) {
	auto [a, b] = split(root, i-1);
	auto [c, d] = split(b, 1);
	root = merge(a, merge(new Node(x), d));
}

void Kivag(int i, int j) {
	auto [a, b] = split(root, i-1);
	auto [c, d] = split(b, j-i+1);
	root = merge(a, d);
}

int Szamlal(int i, int j, char x) {
	auto [a, b] = split(root, i-1);
	auto [c, d] = split(b, j-i+1);
	int res = c->cnt[char_to_index(x)];
	root = merge(a, merge(c, d));
	return res;
}

string Eredmeny() {
	string res;
	if (root) print(root, res);
	return res;
}
/*
int main() {
	string s; cin >> s;
	Kezd(s);
	while (true) {
		int op; cin >> op;
		cerr << op << endl;
		if (op == 0) {
			break;
		}
		if (op == 1) {
			int x; char c; cin >> x >> c;
			Beszur(x, c);
		}
		if (op == 2) {
			int x; char c; cin >> x >> c;
			Mutal(x, c);
		}
		if (op == 3) {
			int l, r; cin >> l >> r;
			Kivag(l, r);
		}
		if (op == 4) {
			int l, r, ans; char c; cin >> l >> r >> c >> ans;
			int res = Szamlal(l, r, c);
			// if (ans == res) cout << "Correct\n";
			// else cout << "Incorrect: " << ans << " " << res << "\n";
		}
		if (op == 5) {
			string res = Eredmeny();
			string ans; cin >> ans;
			ans.pop_back();
			// if (ans == res) cout << "Correct\n";
			// else cout << "Incorrect: " << ans << " " << res << "\n";
		}
		cout << Eredmeny() << "\n";
	}
}
*/
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1936 KiB
2Runtime error3ms2276 KiB
subtask20/30
3Runtime error3ms2548 KiB
4Runtime error3ms2760 KiB
5Runtime error3ms2932 KiB
6Runtime error3ms3020 KiB
7Runtime error3ms2972 KiB
8Runtime error4ms3444 KiB
subtask30/30
9Runtime error3ms3540 KiB
10Runtime error3ms3644 KiB
11Runtime error3ms3668 KiB
12Runtime error3ms3664 KiB
13Runtime error3ms3536 KiB
14Runtime error4ms4056 KiB
subtask40/20
15Runtime error3ms3896 KiB
16Runtime error3ms3680 KiB
17Runtime error3ms3824 KiB
18Runtime error3ms3916 KiB
19Runtime error4ms4076 KiB
subtask50/20
20Runtime error3ms3760 KiB
21Runtime error3ms3784 KiB
22Runtime error3ms3764 KiB
23Runtime error3ms4048 KiB
24Runtime error4ms4476 KiB