102692024-03-29 21:00:30szilGénsebészcpp17Wrong answer 0/10024ms16532 KiB
#include <bits/stdc++.h>
#include "grader.h"

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);
	for (int i = 0; i++; i < 4) {
		v->cnt[i] = (char_to_index(v->c) == i);
		if (v->l) v->cnt[i] += v->l->cnt[i];
		if (v->r) v->cnt[i] += v->r->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) {
	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;
	print(root, res);
	return res;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1812 KiB
2Wrong answer3ms2248 KiB
subtask20/30
3Wrong answer3ms2280 KiB
4Wrong answer3ms2448 KiB
5Wrong answer3ms2536 KiB
6Wrong answer3ms2672 KiB
7Wrong answer3ms2940 KiB
8Wrong answer8ms6904 KiB
subtask30/30
9Wrong answer3ms3268 KiB
10Wrong answer3ms3272 KiB
11Wrong answer3ms3276 KiB
12Wrong answer3ms3280 KiB
13Wrong answer3ms3724 KiB
14Wrong answer9ms8584 KiB
subtask40/20
15Wrong answer3ms3552 KiB
16Wrong answer3ms3464 KiB
17Wrong answer3ms3572 KiB
18Wrong answer3ms3476 KiB
19Wrong answer12ms9848 KiB
subtask50/20
20Wrong answer3ms3804 KiB
21Wrong answer3ms3980 KiB
22Wrong answer3ms4120 KiB
23Wrong answer4ms4964 KiB
24Wrong answer24ms16532 KiB