配置
vscode
运行
g++ -o a a.cpp && ./a
越界检测加设置 c++14 加 O2 加警告加显示运行时间
g++ -O2 -std=c++14 -Wall -fsanitize=address,undefined -o a a.cpp && time ./a
设置
{
"workbench.colorTheme": "Solarized Light",
"files.autoSave": "afterDelay",
"editor.cursorSmoothCaretAnimation": "on",
"workbench.list.smoothScrolling": true,
"editor.smoothScrolling": true,
"terminal.integrated.smoothScrolling": true,
"workbench.iconTheme": "vscode-icons",
"editor.minimap.enabled": false,
"editor.cursorBlinking": "smooth",
"terminal.integrated.enableMultiLinePasteWarning": false,
"explorer.confirmDelete": false
}
freopen
#ifndef ONLINE_JUDGE
freopen("rand.out","r",stdin);
freopen("a.out","w",stdout);
#endif
快读快写
template<typename Tp> inline void read(Tp&x)
{
x=0;register bool z=true;
register char c=getchar_unlocked();
for(;!isdigit(c);c=getchar_unlocked()) if(c=='-') z=0;
for(;isdigit(c);c=getchar_unlocked()) x=(x<<1)+(x<<3)+(c^48);
x=(z?x:~x+1);
}
template<typename T,typename ...Tp> inline void read(T &x,Tp &...y){read(x);read(y...);}
template<typename Tp> inline void wt(Tp x){if(x>9)wt(x/10);putchar_unlocked((x%10)+'0');}
template<typename Tp> inline void write(Tp x){if(x<0)putchar_unlocked('-'),x=~x+1;wt(x);}
template<typename T,typename ...Tp> inline void write(T x,Tp ...y){write(x);putchar_unlocked(' ');write(y...);}
解绑cin、cout
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
模板
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define sort stable_sort
using namespace std;
const int N=1e5+10;
template<typename Tp> inline void read(Tp&x)
{
x=0;register bool z=true;
register char c=getchar_unlocked();
for(;!isdigit(c);c=getchar_unlocked()) if(c=='-') z=0;
for(;isdigit(c);c=getchar_unlocked()) x=(x<<1)+(x<<3)+(c^48);
x=(z?x:~x+1);
}
template<typename T,typename ...Tp> inline void read(T &x,Tp &...y){read(x);read(y...);}
template<typename Tp> inline void wt(Tp x){if(x>9)wt(x/10);putchar_unlocked((x%10)+'0');}
template<typename Tp> inline void write(Tp x){if(x<0)putchar_unlocked('-'),x=~x+1;wt(x);}
template<typename T,typename ...Tp> inline void write(T x,Tp ...y){write(x);putchar_unlocked(' ');write(y...);}
signed main()
{
}
计算数组空间大小
void array_space() {cerr<<(sizeof(a))/1024./1024<<endl;}
对拍
#include<bits/stdc++.h>
using namespace std;
signed main()
{
freopen("rand.out","r",stdin);
freopen("a.out","w",stdout);
}
#include<bits/stdc++.h>
using namespace std;
signed main()
{
freopen("rand.out","r",stdin);
freopen("std.out","w",stdout);
}
#include<bits/stdc++.h>
using namespace std;
signed main()
{
freopen("/dev/urandom","r",stdin);
freopen("rand.out","w",stdout);
srand(getchar()*getchar()*getchar()*time(0));
int n=rand()%100+1;
printf("%d\n",n);
while(n--)
{
int a=rand()%100+1;
printf("%d ",a);
}
}
#include<bits/stdc++.h>
using namespace std;
signed main()
{
int T=10000,tot=0;
while(T--)
{
tot++;
printf("%d ",tot);
system("./rand; ./a; ./std");
if(system("diff a.out std.out -Z"))
{
puts("WA");
return 0;
}
puts("AC");
}
}
linux 系统防死机
watch -n 1 "/usr/bin/free | awk 'NR > 1{ if (\$3 / \$2 > 0.35) system(\"killall5\") }'"