QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#476590#5541. Substring Sortkaruna#RE 1ms5704kbC++202.7kb2024-07-13 20:21:532024-07-13 20:21:53

Judging History

你现在查看的是最新测评结果

  • [2024-07-13 20:21:53]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5704kb
  • [2024-07-13 20:21:53]
  • 提交

answer

#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int SZ = 101010;

struct perm {
	int p[3];
};

perm operator*(perm a, perm b) {
	perm c;
	for (int i = 0; i < 3; i++) {
		c.p[i] = a.p[b.p[i]];
	}
	return c;
}

int z[3], o[3];
perm operator+(perm a, perm b) {
	for (int t = 0; t < 3; t++) z[t] = 3 * a.p[t] + b.p[t];
	sort(o, o + 3, [&](int i, int j) { return z[i] < z[j]; });

	a.p[o[0]] = 0;
	for (int t = 1; t < 3; t++) a.p[o[t]] = a.p[o[t - 1]] + (z[o[t - 1]] != z[o[t]]);
	return a;
}

string S[3], T[3];
struct seg {
	perm lazy[4 * SZ];
	perm tree[4 * SZ];

	void apply(int x, perm v) {
		lazy[x] = lazy[x] * v;
		tree[x] = tree[x] * v;
	}
	void push(int l, int r, int x) {
		if (l != r) {
			apply(2 * x, lazy[x]);
			apply(2 * x + 1, lazy[x]);
			for (int t = 0; t < 3; t++) lazy[x].p[t] = t;
		}
	}
	void init(int l, int r, int x) {
		for (int t = 0; t < 3; t++) lazy[x].p[t] = t;
		if (l == r) {
			sort(o, o + 3, [&](int i, int j) { return S[i][l] < S[j][l]; });
			tree[x].p[o[0]] = 0;
			for (int t = 1; t < 3; t++) tree[x].p[o[t]] = tree[x].p[o[t - 1]] + (S[o[t - 1]][l] != S[o[t]][l]);
			return;
		}
		int m = (l + r) / 2;
		init(l, m, 2 * x);
		init(m + 1, r, 2 * x + 1);
		tree[x] = tree[2 * x] + tree[2 * x + 1];
	}
	void update(int a, int b, perm v, int l, int r, int x) {
		if (b < l || a > r) return;
		if (a <= l && r <= b) {
			apply(x, v);
			return;
		}
		push(l, r, x);
		int m = (l + r) / 2;
		update(a, b, v, l, m, 2 * x);
		update(a, b, v, m + 1, r, 2 * x + 1);
		tree[x] = tree[2 * x] + tree[2 * x + 1];
	}
	perm query(int a, int b, int l, int r, int x) {
		if (a <= l && r <= b) return tree[x];
		push(l, r, x);
		int m = (l + r) / 2;
		if (b <= m) return query(a, b, l, m, 2 * x);
		else if (a > m) return query(a, b, m + 1, r, 2 * x + 1);
		else {
			return query(a, b, l, m, 2 * x) + query(a, b, m + 1, r, 2 * x + 1);
		}
	}
	void dfs(int l, int r, int x) {
		if (l == r) {
			for (int t = 0; t < 3; t++) {
				T[t] += S[lazy[x].p[t]][l];
			}
			return;
		}
		push(l, r, x);
		int m = (l + r) / 2;
		dfs(l, m, 2 * x);
		dfs(m + 1, r, 2 * x + 1);
	}
} seg;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	
	int n, q;
	cin >> n >> q;

	for (int t = 0; t < 3; t++) cin >> S[t];
	iota(o, o + 3, 0);

	seg.init(0, n - 1, 1);
	while (q--) {
		int s, e;
		cin >> s >> e;
		--s; --e;

		perm p = seg.query(s, e, 0, n - 1, 1);
		perm q;
		for (int t = 0; t < 3; t++) q.p[p.p[t]] = t;

		seg.update(s, e, q, 0, n - 1, 1);
	}
	seg.dfs(0, n - 1, 1);

	for (int t = 0; t < 3; t++) {
		cout << T[t] << '\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5612kb

input:

5 2
icpca
siaja
karta
2 4
1 5

output:

iarta
kiaja
scpca

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 5704kb

input:

6 6
aabbcc
bcacab
cbcaba
1 1
2 2
3 3
4 4
5 5
6 6

output:

aaaaaa
bbbbbb
cccccc

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 5640kb

input:

3 1
aba
aab
aac
1 3

output:

aab
aac
aba

result:

ok 3 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 5616kb

input:

1 1
z
y
x
1 1

output:

x
y
z

result:

ok 3 lines

Test #5:

score: -100
Runtime Error

input:

100000 100000
llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll...

output:


result: