跳到正文

题解

题解:AT_abc411_d [ABC411D] Conflict 2

#SUSPENDED#约 3 分钟
原文
文章信息与版本

文章信息

发布
2025年6月22日
收录
2025年12月12日
更新
2026年11月16日
篇幅
约 3 分钟

版本

  1. v1当前

主包做了一个小时,吃了五发罚时才过的唐诗题目。

思路

看到数据范围,疑似可以直接模拟。
但是交上去发现 TLE 了。 为什么呢?哥们到网上搜搜就知道了。
C++ 中的 string 操作一般需要 O(N)O(N) 的复杂度,带入到题目中总共就是 105∗106=101110^5 * 10^6 = 10^{11},这计算机哪里受得了。
那主包主包,有什么替代的方法吗?
上网搜搜可以发现有个东西叫做 rope,效果和 string 差不多,但是操作复杂度一般为 O(1)O(1),这样就不会超时了。

AC CODE

C++
#include <bits/stdc++.h>
#include <ext/rope>
#define el "\n"
#define sp " "
#define fi first
#define se second
#define inf 1e18
#define r0 return 0
#define int long long
#define F(i, a, b, c) for (int i = a; i <= b; i += c)
#define debug printf ("bug is in here\n")
#define TheEnd continue
#define base(s) s = sp + s
#define lcm(a, b) a / __gcd(a, b) * b
#define setp(x) fixed << setprecision(x)
#define getmid(l, r) l + (r - l) / 2

using namespace std;
using namespace __gnu_cxx;

typedef long long ll;
typedef string str;
using ull = unsigned long long;

int n, q;
crope t;
std::vector<crope> s(210000);

signed main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	cin >> n >> q;
	while (q--) {
		int op, p;
		cin >> op >> p;
		if (op == 1) {
			s[p] = t;
		} else {
			if (op == 2) {
				str r;
				cin >> r;
				s[p].append(r.c_str());
			} else {
				t = s[p];
			}
		}
	}
	cout << t << el;
	r0;
}
//Yuexingfei_qwq is a flying-wind

AC 记录


完结不散花。

原文