Aquabet

Talk is cheap. Show me the code.

0%

比赛用模板

Leetcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include<bits/stdc++.h>
using namespace std;

#define LOCAL

#define PB push_back
#define PF push_front

typedef long long ll;
typedef unsigned long long ull;

struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

ll gcd(ll a, ll b) {
return b ? gcd(b, a%b) : a;
}

ll exgcd(ll l,ll r,ll &x,ll &y) {
if(r == 0) {
x = 1;
y = 0;
return l;
} else {
ll d = exgcd(r, l%r, y, x);
y -= l/r*x;
return d;
}
}

ll MOD(ll a, ll m) {
a %= m;
if(a < 0)a += m;
return a;
}
//乘法逆元
ll inverse(ll a, ll m) {
a = MOD(a, m);
if(a <= 1)return a;
return MOD((1 - inverse(m, a) * m) / a, m);
}
//快速幂
ll kasumi(ll a, ll b, ll mod) {
a %= mod;
if(b < 0)a = inverse(a, mod), b = -b;
ll ans = 1;
while(b) {
if(b & 1)ans = ans * a % mod;
a = a * a % mod;
b /= 2;
}
return ans % mod;
}
//二叉树的序列化
string serialize(TreeNode* root) {
if (!root) {
return "X";
}
auto left = "(" + serialize(root->left) + ")";
auto right = "(" + serialize(root->right) + ")";
return left + to_string(root->val) + right;
}

inline TreeNode* parseSubtree(const string &data, int &ptr) {
++ptr; // 跳过左括号
auto subtree = parse(data, ptr);
++ptr; // 跳过右括号
return subtree;
}

inline int parseInt(const string &data, int &ptr) {
int x = 0, sgn = 1;
if (!isdigit(data[ptr])) {
sgn = -1;
++ptr;
}
while (isdigit(data[ptr])) {
x = x * 10 + data[ptr++] - '0';
}
return x * sgn;
}

TreeNode* parse(const string &data, int &ptr) {
if (data[ptr] == 'X') {
++ptr;
return nullptr;
}
auto cur = new TreeNode(0);
cur->left = parseSubtree(data, ptr);
cur->val = parseInt(data, ptr);
cur->right = parseSubtree(data, ptr);
return cur;
}
//二叉树的反序列化
TreeNode* deserialize(string data) {
int ptr = 0;
return parse(data, ptr);
}

#ifdef LOCAL

int main() {
freopen("testdata.in", "r", stdin);
}
#endif

Codeforces

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<bits/stdc++.h>
using namespace std;

#define PB push_back
#define PF push_front

typedef long long ll;
typedef unsigned long long ull;

inline int read() {
char ch = getchar(); int x = 0, f = 1;
while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
return x*f;
}

ll gcd(ll a, ll b) {
return b ? gcd(b, a%b) : a;
}

ll exgcd(ll l,ll r,ll &x,ll &y) {
if(r == 0) {
x = 1;
y = 0;
return l;
} else {
ll d = exgcd(r, l%r, y, x);
y -= l/r*x;
return d;
}
}

ll MOD(ll a, ll m) {
a %= m;
if(a < 0)a += m;
return a;
}
//乘法逆元
ll inverse(ll a, ll m) {
a = MOD(a, m);
if(a <= 1)return a;
return MOD((1 - inverse(m, a) * m) / a, m);
}
//快速幂
ll kasumi(ll a, ll b, ll mod) {
a %= mod;
if(b < 0)a = inverse(a, mod), b = -b;
ll ans = 1;
while(b) {
if(b & 1)ans = ans * a % mod;
a = a * a % mod;
b /= 2;
}
return ans % mod;
}

void solve() {
//
}

int main() {
solve();
}