FASTREAD
char buf[(1 << 20) + 5],*p1 = buf,*p2 = buf;
#define getchar() ((p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,1 << 20,stdin))),p1==p2 ? EOF : *p1++)signed read
inline int read() {
int res = 0,l = 1;char ch = getchar();
while(!isdigit(ch))l = ((ch == '-') ? (-1) : (l)),ch = getchar();
while(isdigit(ch))res = res * 10 - '0' + ch,ch = getchar();
return res * l;
}unsigned read
inline int read() {
int res = 0;char ch = getchar();
while(!isdigit(ch))ch = getchar();
while(isdigit(ch))res = res * 10 - '0' + ch,ch = getchar();
return res;
}char read
inline char readc(){
char ch = getchar();
while(!isalpha(ch)) ch = getchar();
return ch;
}模板
图论
dij
struct typ{
int u,l;
inline friend bool operator < (typ a,typ b){
return a.l > b.l;
}
};
void dij(){
for(int i = 1;i <= n;i++) dis[i] = inf,vis[i] = 0;
dis[1] = 0;
priority_queue<typ> pq;
pq.push({1,0});
while(!pq.empty()){
auto v = pq.top(); pq.pop();
if(vis[v.u]) continue;
vis[v.u] = true;
for(auto k : vec[v.u]){
if(dis[k.to] > dis[v.u] + k.l){
dis[k.to] = dis[v.u] + k.l;
pq.push({k.to,dis[k.to]});
}
}
}
}重构树
//请复制并查集模板
void kru(){
sort(E.begin(),E.end());
dsu.init(n << 1);
for(int i = 1;i <= (n << 1);i++) tre[i].clear();
int tot = n;
for(auto k : E){
int L = dsu.find(k.u),R = dsu.find(k.v);
if(L != R){
tre[++tot].push_back(L);
tre[tot].push_back(R);
tre[L].push_back(tot);
tre[R].push_back(tot);
jmp[L][0] = jmp[R][0] = tot;
dsu.merge(L,tot);
dsu.merge(R,tot);
val[tot] = k.a;
}
}
}最小生成树
void kruskal(){
dsu.init(n);
sort(E.begin(),E.end());
for(auto &k : E){
if(dsu.find(k.l) == dsu.find(k.r)){
mes.push_back(k);
continue;
}
dsu.merge(k.l,k.r);
tre[k.l].push_back(k.r);
tre[k.r].push_back(k.l);
}
}强连通分量
int n,m,a[N],nw[N],nwa[N],l[N],r[N],ans;
vector<int> vec[N];
int st[N],where,tot,dfn[N],low[N],in[N];
bool instk[N];
void targan(int x){
dfn[x] = low[x] = ++tot;
st[++where] = x; instk[x] = 1;
for(auto k : vec[x]){
if(!dfn[k]){
targan(k);
low[x] = min(low[k],low[x]);
}
else if(instk[k])low[x] = min(low[k],low[x]);
}
if(dfn[x] == low[x]){
int y;
do{
y = st[where--]; instk[y] = 0; nw[y] = x;
nwa[x] += a[y];
}while(y != x);
}
}数据结构
并查集
struct DSU{
int fa[N];
void init(int n){
for(int i = 1;i <= n;i++) fa[i] = i;
}
int find(int x){
return ((fa[x] == x) ? x : (fa[x] = find(fa[x])));
}
void merge(int x,int y){
fa[find(x)] = find(y);
}
}dsu;树状数组
struct BIT{
int tre[N];
void init(){
memset(tre,0,sizeof(tre));
}
inline int lowbit(int x){
return (-x) & x;
}
inline void add(int x,int w){
for(int i = x;i <= n;i += lowbit(i)) tre[i] += w;
}
inline int query(int x,int res = 0){
for(int i = x;i;i -= lowbit(i)) res += tre[i];
return res;
}
}bit;线段树
#define ls (x << 1)
#define rs ((x << 1) | 1)
#define mid ((l + r) >> 1)
struct segment{
struct tree{
int l,r,tag,sum;
}tre[N << 2];
void pushup(int x){
tre[x].sum = tre[ls].sum + tre[rs].sum;
}
void lazy(int x,int w){
tre[x].tag += w;
tre[x].sum += (tre[x].r - tre[x].l + 1) * w;
}
void pushdown(int x){
if(tre[x].l == tre[x].r || tre[x].tag == 0) return;
lazy(ls,tre[x].tag);
lazy(rs,tre[x].tag);
tre[x].tag = 0;
}
void build(int l = 1,int r = n,int x = 1){
if(l == r)tre[x] = {l,r,0,a[l]};
else{
tre[x].l = l,tre[x].r = r;
build(l,mid,ls);
build(mid + 1,r,rs);
pushup(x);
}
}
void add(int L,int R,int w,int l = 1,int r = n,int x = 1){
if(L <= l && r <= R) lazy(x,w);
else{
pushdown(x);
if(L <= mid)add(L,R,w,l,mid,ls);
if(R > mid)add(L,R,w,mid + 1,r,rs);
pushup(x);
}
}
int query(int L,int R,int l = 1,int r = n,int x = 1){
if(L <= l && r <= R) return tre[x].sum;
pushdown(x);
int res = 0;
if(L <= mid) res = query(L,R,l,mid,ls);
if(R > mid) res += query(L,R,mid + 1,r,rs);
return res;
}
}sgt;字符串
KMP
int nxt[N];
void kmp(){
for(int i = 1,j = 0;i < str2.size();i++){
while(j && str2[i] != str2[j])j = nxt[j - 1];
if(str2[i] == str2[j]) j++;
nxt[i] = j;
}
for(int i = 0,j = 0;i < str1.size();i++){
while(j && str1[i] != str2[j])j = nxt[j - 1];
if(str1[i] == str2[j]) j++;
if(j == str2.size()){
cout << i - str2.size() + 2 << "\n";
j = nxt[j - 1];
}
}
}manacher
char ch[MAXN];
int p[MAXN];
void manacher(){
int c = 0, r = 0, ans = 0;
for(int i = 0; i < n; i++){
int len;
len = ((i < r) ? min(p[2 * c - i], r - i) : 1);
while(i - len >= 0 && i + len < n && ch[i - len] == ch[i + len]) len++;
if(i + len > r) c = i,r = i + len;
p[i] = len;
ans = max(ans, len);
}
}gunmu
#include<bits/stdc++.h>
#include<windows.h>
#define uidi uniform_int_distribution<int>
using namespace std;
int n, ed = 1, ed2,spd = 1;
vector<char> y = {'a','e','i','o','u','a','e','i','o','e'};
vector<char> f = {'b','c','d','g','h','j','k','l','m','n','p','r','s','t','x','t','n','s','l','c','r','c','k','l','n','r','s','t','v','w','z','t','n','s','l','c','r'};
vector<int> le = {1,2,2,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,5,7,7,7,8,8,9,9,10,11,12,13};
int main(){
random_device rd;
seed_seq ss{rd(), (unsigned int)time(0)};
mt19937 rng(ss);
cin >> n;
for(int i = 1; i <= n; i++){
if(ed2 == 2)ed2 = 1;
uidi dist_le(0, le.size() - 1);
int len = le[dist_le(rng)];
int sx = 20;
for(int j = 1; j <= len; j++){
uidi dist_10(0, sx);
int choice = dist_10(rng);
bool l = 0;
if(choice < 6) l = 1,sx += 8;
else sx -= 6;
if(sx < 6)sx = 8;
char w;
uidi dst(0, (l) ? (y.size() - 1) : (f.size() - 1));
w = (l) ? y[dst(rng)] : f[dst(rng)];
if(!ed) cout << w;
else ed = 0, cout << (char)toupper(w);
uidi slptime(4, 15);
if(spd)Sleep(slptime(rng));
}
uidi dist_100(0, 99);
int _end = dist_100(rng);
if(_end < 17 || i == n){
ed = 1;
if(_end <= 6) cout << ". ";
else if(_end <= 12)ed = 0,cout << ", ";
else if(_end >= 15) cout << "? ";
else if(_end == 13 && !ed2) ed2 = 2, cout << ":\"";
else cout << "! ";
uidi dist_9(0, 8);
if(dist_9(rng) <= 2 && !ed2 && ed) cout << "\n";
if(ed2 == 1 && ed){ ed2 = 0; cout << "\" "; }
}
else if(_end == 91) cout << "-";
else cout << " ";
uidi slptime(4, 15);
if(spd)Sleep(slptime(rng));
}
return 0;
}#include<bits/stdc++.h>
//本工具用来删除注释,空行
const bool tab = 1;//当复制内容无缩进时设为1,会自动补充空行
using namespace std;
string str[1080],n1str[1080];int te[1080];
bool mainstart = 0,_end = 0;
int main(){
int line = 1,linn = 1;
int tm = 1;
for(;!_end;line++){
getline(cin,str[line]);
for(int i = 0;i < str[line].size() && mainstart;i++){
if(str[line][i] == '{')tm++;
if(str[line][i] == '}')tm--;
if(tm == 0)_end = 1;
}
if(str[line].size() < 6)continue;
for(int i = 0;i < str[line].size() - 6 && !mainstart;i++){
if(str[line][i] == 'm' && str[line][i + 1] == 'a' && str[line][i + 2] == 'i' && str[line][i + 3] == 'n' && str[line][i + 4] == '(' && str[line][i + 5] == ')' && str[line][i + 6] == '{'){
mainstart = 1;
}
}
}
te[0] = 0;
for(int i = 1;i <= line;i++){
if(str[i].size() == 0){
continue;
}
if(str[i].size() >= 2){
if(str[i][0] == '/' && str[i][1] == '/')continue;
}
int izhus = -1;
string mstr = "";
//cout << i << "\n";
if(str[i].size() >= 2){
for(int j = 0;j < str[i].size() - 1;j++){
if(str[i][j] == '/' && str[i][j + 1] == '/')izhus = j;
}
}
if(izhus != -1){
for(int j = 0;j < izhus;j++)mstr = mstr + str[i][j];
}
else mstr = str[i];
n1str[++linn] = mstr;
}
for(int i = 1,tag = 0;i <= linn && tab;i++){
te[i] = te[i - 1] + tag;
tag = 0;
for(int j = 0;j < n1str[i].size();j++){
if(n1str[i][j] == '{')tag++;
if(n1str[i][j] == '}'){
if(tag > 0)tag--;
else te[i]--;
}
}
//cout << te[i];
for(int j = 1;j <= te[i] && tab;j++){
n1str[i] = " " + n1str[i];
}
}
for(int i = 1;i <= linn;i++){
cout << n1str[i] << "\n";
}
return 0;
}