数据生成器使用说明
使用Python生成器可以快速创建测试数据,已内置random库,支持所有标准Python功能。
num: int -
表示当前测试点编号(从 1 开始)
一个单点修改,区间查询的数据结构题
# 测试点规模配置
N = [0, 100, 2000, 100000, 100000, 200000, 200000, 300000, 400000, 500000, 500000]
Q = [0, 100, 2000, 100000, 100000, 200000, 200000, 300000, 400000, 500000, 500000]
E9 = 10 ** 9
# 根据测试点编号获取规模
n, q = N[num], Q[num]
print(n, q)
# 生成n个随机数作为初始数组
for i in range(n):
print(randint(-E9, E9), end=' ')
print()
# 生成q个操作
for i in range(q):
opt = choice([1, 2]) # 随机选择操作类型
l = randint(1, n) # 随机左端点
if opt == 1:
# 单点修改操作
print(opt, l, randint(-E9, E9))
else:
# 区间查询操作
r = randint(1, n)
if l > r:
l, r = r, l
print(opt, l, r)
单源最短路模板题
# 测试点规模配置
N = [0, 100, 2000, 100000, 100000, 200000, 200000, 300000, 400000, 500000, 500000]
M = [0, 100, 2000, 100000, 100000, 200000, 200000, 300000, 400000, 500000, 500000]
E9 = 10 ** 9
n = N[num] # 点数
m = M[num] # 边数
s = randint(1, n) # 随机选取源点
print(n, m, s)
graph = cyaron.Graph.graph(n, m, weight_limit=E9) # 生成一个n点,m边的随机图,边权限制为1e9
print(graph.to_str()) # 输出无向图,默认以一行一组u v w的形式输出
使用C++生成器可以获得更好的性能,适合大规模数据与复杂逻辑场景。编译选项与 std.cpp 相同。
num -
表示当前测试点编号(从 1 开始)
一个单点修改,区间查询的数据结构题
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int randint(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
// 测试点规模配置
const int N[] = {0, 100, 2000, 100000, 100000, 200000, 200000, 300000, 400000, 500000, 500000};
const int Q[] = {0, 100, 2000, 100000, 100000, 200000, 200000, 300000, 400000, 500000, 500000};
const int E9 = 1e9;
int num;
int main() {
// 关闭同步加速输出
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
// 根据测试点编号获取规模
cin >> num;
int n = N[num];
int q = Q[num];
cout << n << " " << q << "\n";
// 生成n个随机数作为初始数组
for (int i = 0; i < n; i++) {
cout << randint(-E9, E9) << " ";
}
cout << "\n";
// 生成q个操作
while (q--) {
int opt = randint(1, 2); // 随机选择操作类型
int l = randint(1, n); // 随机左端点
if (opt == 1) {
// 单点修改操作
cout << opt << " " << l << " " << randint(-E9, E9) << "\n";
} else {
// 区间查询操作
int r = randint(1, n);
if (l > r) swap(l, r);
cout << opt << " " << l << " " << r << "\n";
}
}
cout << flush; // 注意刷新缓冲区
return 0;
}