模板
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
typedef long long ll;
using namespace std;
int main() {
#ifdef DEBUG
freopen("1.in", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
return 0;
}
快读
const int Bsiz = 1 << 20;
char BB[Bsiz], *SB = BB, *TB = BB;
char gc() {
if(SB != TB) {
return *SB++;
}
SB = BB;
TB = SB + fread(BB, 1, Bsiz, stdin);
if(SB == TB) {
return EOF;
}
return *SB++;
}
template <typename T> void read(T &x) {
T f = 1;
char ch = gc();
x = 0;
while(!isdigit(ch)) {
if(ch == '-') {
f = -1;
}
ch = gc();
}
while(isdigit(ch)) {
x = x * 10 + (ch & 15);
ch = gc();
}
x *= f;
}
数据生成器
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
namespace DM {
mt19937_64 rnd(time(NULL));
ll number(ll l, ll r) {
uniform_int_distribution<ll> dis(l, r);
return dis(rnd);
}
pair<ll, ll> range(ll l, ll r) {
uniform_int_distribution<ll> dis(l, r);
ll p = dis(rnd), q = dis(rnd);
if(p > q) {
swap(p, q);
}
return mp(p, q);
}
vector<int> permutation(int n) {
vector<int> res(n);
for(int i = 0; i < n; i++) {
res[i] = i + 1;
}
shuffle(res.begin(), res.end(), rnd);
return res;
}
/*
array
value range : [l, r]
*/
vector<ll> array(int n, ll l, ll r) {
vector<ll> res(n);
for(int i = 0; i < n; i++) {
res[i] = number(l, r);
}
return res;
}
/*
tree
root : random
*/
vector<pair<int, int> > tree(int n) {
vector<pair<int, int> > res;
for(int i = 2; i <= n; i++) {
res.pb(mp(number(1, i - 1), i));
}
vector<int> p = permutation(n);
for(int i = 0; i < n - 1; i++) {
res[i].fi = p[res[i].fi - 1];
res[i].se = p[res[i].se - 1];
}
return res;
}
/*
Binary Tree
root : 1
*/
vector<int> binary_tree(int n) {
vector<int> fa, deg;
fa.resize(n), deg.resize(n);
for(int i = 2; i <= n; i++) {
while(1) {
int u = number(1, i - 1);
if(deg[u] < 2) {
deg[u]++;
fa[i - 1] = u;
break;
}
}
}
return fa;
}
/*
DAG / Undirected Graph
*/
vector<pair<int, int> > graph(int n, int m) {
vector<pair<int, int> > res;
map<pair<int, int>, bool> vis;
for(int i = 2; i <= n; i++) {
while(1) {
pair<int, int> e = mp(number(1, i - 1), i);
if(vis[e]) {
continue;
}
res.pb(e), vis[e] = 1;
break;
}
}
for(int i = 1; i <= m - n + 1; i++) {
while(1) {
pair<int, int> e = range(1, n);
if(vis[e] || e.fi == e.se) {
continue;
}
res.pb(e), vis[e] = 1;
break;
}
}
vector<int> p = permutation(n);
for(int i = 0; i < m; i++) {
res[i].fi = p[res[i].fi - 1];
res[i].se = p[res[i].se - 1];
}
return res;
}
}
namespace output {
void number1(ll l, ll r) {
ll x = DM::number(l, r);
cout << x << ' ';
}
void number2(ll l, ll r) {
ll x = DM::number(l, r);
cout << x << '\n';
}
void range(ll l, ll r) {
pair<ll, ll> x = DM::range(l, r);
cout << x.fi << ' ' << x.se << '\n';
}
void tree(int n) {
vector<pair<int, int> > x = DM::tree(n);
for(int i = 0; i < n - 1; i++) {
cout << x[i].fi << ' ' << x[i].se << '\n';
}
}
void graph(int n, int m) {
vector<pair<int, int> > x = DM::graph(n, m);
for(int i = 0; i < m; i++) {
cout << x[i].fi << ' ' << x[i].se << '\n';
}
}
}
int main() {
freopen("1.in", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
return 0;
}
标签:return,int,res,ll,vector,模板,define
From: https://www.cnblogs.com/yanchengzhi/p/17002163.html