其他
VSCode
{
"workbench.colorTheme": "Default High Contrast Light",
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 10,
"editor.cursorBlinking": "expand",
"workbench.list.smoothScrolling": true,
"editor.smoothScrolling": true,
"terminal.integrated.smoothScrolling": true,
"editor.cursorSmoothCaretAnimation": true,
"terminal.integrated.enableMultiLinePasteWarning": false
}
Ubontu 编译运行指令
g++ test.cpp -o test
g++ test.cpp -o test && ./test
g++ test.cpp -o test && ./test < test.in > test.out
Windows 编译运行指令
get-content .\test.in | .\test.exe > test.out
.\test.exe
扩大堆栈空间(本地 RE 时使用)
ulimit -s 1048576
cpp
基础版
#include <bits/stdc++.h>
namespace {
#define filein(x) freopen(x".in", "r", stdin)
#define fileout(x) freopen(x".out", "w", stdout)
#define files(x) filein(x), fileout(x)
using namespace std;
#define ll long long
#define db double
const int man = 5e4+10, mam = 5e4+10, mmp = 1e9+1;
}
int n, m;
int a[man];
int main () {
#ifndef ONLINE_JUDGE
files("test");
#endif
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++ i) {
scanf("%d", a+i);
}
return 0;
}
// ---
void () {
return ;
}
方向(dist)
const int dist[5][3] = {{1, 0}, {-1, 0}, {0, 1}, {0, 1}};
二元组(pair)
template <typename T>
using pr = pair<T, T>;
#define pii pr<int>
#define pll pr<ll>
#define pdd pr<db>
#define mp(x, y) make_pair(x, y)
#define fir first
#define sec second
#undef cT
图(Graph)
class Graph {
public:
int len = 1;
int hed[man];
int nxt[mam<<1], ver[mam<<1], dis[mam<<1];
template <typename T>
void DIns (T u, T v, T w) {
Ins(u, v, w), Ins(v, u, w);
return ;
}
template <typename T>
void Ins (T u, T v, T w) {
ver[++len] = v;
dis[len] = w;
nxt[len] = hed[u];
hed[u] = len;
}
} G;
二叉查找树(BST)
class BST {
public:
int tot;
struct node {
int l, r, val, siz, cnt;
} tr[man];
#define ls tr[x].l
#define rs tr[x].r
void ins (int x, int val) {
++ tr[x].siz;
if (tr[x].val == val) ++ tr[x].cnt;
else if (tr[x].val > val)
if (ls) ins(ls, val);
else ls = ++ tot, tr[tot] = {0, 0, val, 1, 1};
else
if (rs) ins(rs, val);
else rs = ++ tot, tr[tot] = {0, 0, val, 1, 1};
return ;
}
int querk (int x, int val) {
if (!x) return 0;
if (tr[x].val == val) return tr[ls].siz;
else if (tr[x].val > val) return querk(ls, val);
else return tr[ls].siz + tr[x].cnt + querk(rs, val);
}
int find (int x, int rk) {
if (!x) return 0;
if (tr[ls].siz >= rk) return find(ls, rk);
else if (tr[ls].siz+tr[x].cnt >= rk) return tr[x].val;
else return find(rs, rk-tr[ls].siz-tr[x].cnt);
}
int finlst (int val) {
int res = miv, x = 1;
while (x) {
if (val == tr[x].val) {
if (ls) {
x = ls;
while (rs) x = rs;
res = tr[x].val;
} break;
} if (tr[x].val<val && tr[x].val>res) res = tr[x].val;
x = val<tr[x].val? ls : rs;
} return res;
}
int finext (int val) {
int res = mav, x = 1;
while (x) {
if (val == tr[x].val) {
if (rs) {
x = rs;
while (ls) x = ls;
res = tr[x].val;
} break;
} if (tr[x].val>val && tr[x].val<res) res = tr[x].val;
x = val<tr[x].val? ls: rs;
} return res;
}
#undef ls
#undef rs
} B;
线段树(SMT)
const int man = 2e6+10;
class SMT {
public:
struct node {
int lt, rt, lth, mid;
ll sum, tag;
} tr[man<<2];
#define ls (p<<1)
#define rs (p<<1|1)
#define upd tr[p].sum = tr[ls].sum+tr[rs].sum
void build (int st, int ed, int p) {
tr[p].lt = st, tr[p].rt = ed,
tr[p].lth = ed-st+1, tr[p].mid = (st+ed)>>1;
if (st == ed) scanf("%lld", &tr[p].sum);
else {
build(st, (st+ed)>>1, ls);
build(((st+ed)>>1)+1, ed, rs);
upd;
} return ;
}
void pushdown (int p) {
ll tg = tr[p].tag;
if (tg) {
tr[ls].sum += tg*tr[ls].lth;
tr[rs].sum += tg*tr[rs].lth;
tr[ls].tag += tg;
tr[rs].tag += tg;
tr[p].tag = 0;
} return ;
}
void add (int st, int ed, int p, ll pls) {
if (st<=tr[p].lt && tr[p].rt<=ed)
tr[p].sum += tr[p].lth*pls, tr[p].tag += pls;
else {
pushdown(p);
if (st <= tr[p].mid) add(st, ed, ls, pls);
if (tr[p].mid+1 <= ed) add(st, ed, rs, pls);
upd;
} return ;
}
ll ges (int st, int ed, int p) {
if (st<=tr[p].lt && tr[p].rt<=ed) return tr[p].sum;
pushdown(p);
ll sum = 0;
if (st <= tr[p].mid) sum += ges(st, ed, ls);
if (tr[p].mid+1 <= ed) sum += ges(st, ed, rs);
return sum;
}
#undef ls
#undef rs
#undef upd
} ;
STL(手写)
双端队列(deque)
class _deque {
public:
int hd = 1, tl = 1;
int a[man];
int size () { return tl-hd;}
bool empty () { return !(tl-hd);}
int front () {return size()? a[hd]: 0;}
int back () {return size()? a[tl-1]: 0;}
void push_front (int x) { return a[--hd] = x, void();}
void push_back (int x) { return a[tl++] = x, void();}
void pop_front () { return ++ hd, void();}
void pop_back () { return -- tl, void();}
} dq;