C++の常用模板
神秘头文件
#include<iostream>
using namespace std;
signed main()
{
return 0;
}数据结构Data Structure
Segment Tree 线段树
template <typename typ>
struct ST_Dat
{
int l,r;
typ size,lazy;
void change(typ k)
{
size += (r - l + 1) * k;
lazy += k;
}
ST_Dat (int L = 0,int R = 0,typ Size = 0,typ Lazy = 0)
{
l = L,r = R,size = Size,lazy = Lazy;
}
};
template <typename typ>
struct SegTree
{
ST_Dat <typ> Tree[N << 2];
void update(int p)
{
Tree[p].size = Tree[p << 1].size + Tree[p << 1 | 1].size;
}
void build(int left,int right,typ *arr,int p = 1)
{
Tree[p] = ST_Dat <typ> (left,right);
if(left == right)
{
Tree[p].size = arr[left];
return;
}
int mid = (left + right) >> 1;
build(left,mid,arr,p << 1);
build(mid + 1,right,arr,p << 1 | 1);
update(p);
}
void pushdown(int p)
{
if(Tree[p].lazy)
{
Tree[p << 1].change(Tree[p].lazy);
Tree[p << 1 | 1].change(Tree[p].lazy);
Tree[p].lazy = 0;
}
}
void change(typ value,int left,int right,int p = 1)
{
if(left <= Tree[p].l && Tree[p].r <= right)
{
Tree[p].change(value);
return;
}
pushdown(p);
int mid = (Tree[p].l + Tree[p].r) >> 1;
if(left <= mid)
change(value,left,right,p << 1);
if(mid < right)
change(value,left,right,p << 1 | 1);
upd(p);
}
typ query(int left,int right,int p = 1)
{
if(left <= Tree[p].l && Tree[p].r <= right)
return Tree[p].size;
pushdown(p);
int mid = (Tree[p].l + Tree[p].r) >> 1;
typ ans = 0;
if(left <= mid)
ans += query(left,right,p << 1);
if(mid < right)
ans += query(left,right,p << 1 | 1);
return ans;
}
};BIT 树状数组
这个东西名字贼多,有 Binary Index Tree ( 简称BIT,也称作01字典树 ),Frenwick Tree 等,但核心是一样的。
int __lowbit_for_BIT__(int x)
{
return x & -x;
}
template <typename typ>
struct BinIndTree
{
int n;
typ Tree[N];
void change(typ value,int left,bool only_give_one = false)
{
int tmp = left + 1;
for(;left <= n;left += __lowbit_for_BIT__(left))
Tree[left] += value;
if(!only_give_one)
return;
for(;tmp <= n;tmp += __lowbit_for_BIT__(tmp))
Tree[tmp] -= value;
}
void build(typ *arr,int left,int right,bool only_give_one = false)
{
n = right - left + 1;
for(int i = left;i <= right;i++)
change(arr[i],i - left + 1,only_give_one);
}
typ query(int right)
{
typ sum = 0;
for(;right;right -= __lowbit_for_BIT__(right))
sum += Tree[right];
return sum;
}
};Hash Table 哈希表
开放选址法(也称作散列表的线性探查法)哈希表
const int HASHMAX = 1e7 + 10;
template <typename KEY,typename VALUE>
struct HashTable
{
VALUE val[HASHMAX];
KEY id[HASHMAX];
bool vis[HASHMAX];
Hash ()
{
memset(val,0,sizeof(val));
memset(id,0,sizeof(id));
memset(vis,0,sizeof(vis));
}
VALUE& operator [] (KEY ky)
{
int t = ky % HASHMAX;
while(vis[t])
{
if(id[t] == ky)
return val[t];
t++;
if(t >= HASHMAX)
t = 0;
}
return val[t];
}
bool find(KEY ky)
{
int t = ky % HASHMAX;
while(vis[t])
{
if(id[t] == ky)
return true;
t++;
if(t >= HASHMAX)
t = 0;
}
return false;
}
void ins(KEY ky,VALUE va)
{
int t = ky % HASHMAX;
while(vis[t])
{
if(id[t] == ky)
break;
t++;
if(t >= HASHMAX)
t = 0;
}
id[t] = ky,val[t] = va;
vis[t] = true;
}
};BST 二叉搜索树
template <typename typ>
struct BSTDat
{
int l,r,siz,num,cnt,fa;
BSTDat (int _l = 0,int _r = 0)
{
l = _l,r = _r;
siz = num = cnt = 0;
}
void build(int x)
{
num = x;
cnt = siz = 1;
}
};
int BST_ROOT__ = 1;
template <typename typ>
struct BST
{
BSTDat <typ> tre[N];
int len;
BST ()
{
len = 1;
}
void upd(int p)
{
if(!p)
return;
tre[p].siz = tre[tre[p].l].siz + tre[tre[p].r].siz + tre[p].cnt;
}
void ins(typ x,int p = BST_ROOT__)
{
if(!tre[p].cnt)
{
tre[p].build(x);
return;
}
if(x < tre[p].num)
{
if(!tre[p].l)
{
tre[p].l = ++len;
tre[len].fa = p;
}
ins(x,tre[p].l);
}
else if(x > tre[p].num)
{
if(!tre[p].r)
{
tre[p].r = ++len;
tre[len].fa = p;
}
ins(x,tre[p].r);
}
else
tre[p].cnt++;
upd(p);
}
int queryrnk(typ x,int p = BST_ROOT__)
{
if(!tre[p].cnt)
return 0;
if(x == tre[p].num)
return tre[tre[p].l].siz;
else if(x < tre[p].num)
return queryrnk(x,tre[p].l);
return queryrnk(x,tre[p].r) + tre[p].cnt + tre[tre[p].l].siz;
}
int queryrnknum(int rnk,int p = BST_ROOT__)
{
if(!tre[p].cnt)
return 0;
if(tre[tre[p].l].siz >= rnk)
return queryrnknum(rnk,tre[p].l);
else if(tre[tre[p].l].siz + tre[p].cnt >= rnk)
return tre[p].num;
return queryrnknum(rnk - tre[tre[p].l].siz - tre[p].cnt,tre[p].r);
}
int querypre(typ x,int p = BST_ROOT__,int ans = -inf)
{
if(!tre[p].cnt)
return ans;
if(tre[p].num >= x)
return tre[p].l ? querypre(x,tre[p].l,ans) : ans;
if(!tre[p].r)
return tre[p].num;
return querypre(x,tre[p].r,tre[p].num);
}
int querynxt(typ x,int p = BST_ROOT__,int ans = inf)
{
if(!tre[p].cnt)
return ans;
if(tre[p].num <= x)
return tre[p].r ? querynxt(x,tre[p].r,ans) : ans;
if(!tre[p].l)
return tre[p].num;
return querynxt(x,tre[p].l,tre[p].num);
}
}t;DSU 启发式合并的可撤销并查集
struct DSU
{
int tot,f[(N << 1) + Q],siz[(N << 1) + Q];
void clr(int MAX = ((N - 10) << 1) + Q)
{
tot = N - 10;
for(int i = 1;i <= tot;i++)
{
f[i] = i + tot;
siz[i] = 1;
}
for(int i = tot;i <= (tot << 1);i++)
{
f[i] = i;
siz[i] = 1;
}
}
DSU (int MAX = ((N - 10) << 1) + Q)
{
clr(MAX);
}
int fa(int p)
{
return p == f[p] ? p : f[p] = fa(f[p]);
}
bool uni(int p1,int p2)
{
int f1 = fa(p1),f2 = fa(p2);
if(f1 == f2)
return false;
if(siz[f1] > siz[f2])
swap(f1,f2);
f[f1] = f2;
siz[f2] += siz[f1];
return true;
}
bool isuni(int p1,int p2)
{
return fa(p1) == fa(p2);
}
void del(int p)
{
int f1 = fa(p);
siz[f1]--;
f[p] = ++tot;
}
};AVLTree AVL平衡树
删除操作(del函数)有点 bug。
const int inf = 2147483647;
template <typename typ>
struct AVLDat
{
int l,r,siz,cnt,fa,mxdep;
typ num;
AVLDat (int _l = 0,int _r = 0)
{
l = _l,r = _r;
siz = cnt = mxdep = 0;
num = 0;
}
void build(int x)
{
num = x;
cnt = siz = mxdep = 1;
}
};
int AVLTree_ROOT__ = 1;
template <typename typ>
struct AVLTree
{
AVLDat <typ> tre[N];
int len;
AVLTree ()
{
len = 1;
}
void upd(int p)
{
tre[p].siz = tre[tre[p].l].siz + tre[tre[p].r].siz + tre[p].cnt;
tre[p].mxdep = max(tre[tre[p].l].mxdep,tre[tre[p].r].mxdep) + 1;
}
void LeftTurn(int p)
{
int f = tre[p].fa,grf = tre[f].fa;
if(f == AVLTree_ROOT__)
AVLTree_ROOT__ = p;
tre[f].r = tre[p].l;
if(tre[p].l)
tre[tre[p].l].fa = f;
tre[p].l = f,tre[f].fa = p,tre[p].fa = grf;
if(grf)
{
if(tre[grf].l == f)
tre[grf].l = p;
else
tre[grf].r = p;
}
upd(tre[p].l),upd(p),upd(f);
if(grf)
upd(grf);
}
void RightTurn(int p)
{
int f = tre[p].fa,grf = tre[f].fa;
if(f == AVLTree_ROOT__)
AVLTree_ROOT__ = p;
tre[f].l = tre[p].r;
if(tre[p].r)
tre[tre[p].r].fa = f;
tre[p].r = f,tre[f].fa = p,tre[p].fa = grf;
if(grf)
{
if(tre[grf].l == f)
tre[grf].l = p;
else
tre[grf].r = p;
}
upd(tre[p].r),upd(p),upd(f);
if(grf)
upd(grf);
}
void AVLTurn(int p,bool delmode = false)
{
if(!p)
return;
upd(p);
int ldep = (tre[p].l ? tre[tre[p].l].mxdep : 0),rdep = (tre[p].r ? tre[tre[p].r].mxdep : 0),t1 = ldep - rdep,t2;
if(t1 == 2)
{
t2 = tre[tre[tre[p].l].l].mxdep - tre[tre[tre[p].l].r].mxdep;
if(t2 == 1)
{
RightTurn(tre[p].l);
if(!delmode)
return;
}
else if(t2 == -1)
{
LeftTurn(tre[tre[p].l].r);
RightTurn(tre[p].l);
if(!delmode)
return;
}
}
else if(t1 == -2)
{
t2 = tre[tre[tre[p].r].l].mxdep - tre[tre[tre[p].r].r].mxdep;
if(t2 == 1)
{
RightTurn(tre[tre[p].r].l);
LeftTurn(tre[p].r);
if(!delmode)
return;
}
else if(t2 == -1)
{
LeftTurn(tre[p].r);
if(!delmode)
return;
}
}
upd(p);
AVLTurn(tre[p].fa,delmode);
}
void ins(typ x,int p = AVLTree_ROOT__)
{
if(!tre[p].cnt)
{
tre[p].build(x);
AVLTurn(p);
return;
}
if(x < tre[p].num)
{
if(!tre[p].l)
{
tre[p].l = ++len;
tre[len].fa = p;
}
ins(x,tre[p].l);
}
else if(x > tre[p].num)
{
if(!tre[p].r)
{
tre[p].r = ++len;
tre[len].fa = p;
}
ins(x,tre[p].r);
}
else
tre[p].cnt++;
upd(p);
}
void del(typ x,int p = AVLTree_ROOT__)
{
if(!p || !tre[p].cnt)
return;
if(x < tre[p].num)
del(x,tre[p].l);
else if(x > tre[p].num)
del(x,tre[p].r);
else
{
if(tre[p].cnt > 1)
{
tre[p].cnt--;
upd(p);
AVLTurn(p,true);
return;
}
else
{
if(tre[p].l && tre[p].r)
{
int pos = tre[p].r;
while(tre[pos].l)
pos = tre[pos].l;
int tmp1 = tre[pos].num,tmp2 = tre[pos].cnt;
tre[p].num = tmp1,tre[p].cnt = tmp2;
tre[pos].cnt = 1;
del(tmp1,tre[p].r);
upd(p);
AVLTurn(p,true);
return;
}
else if(!tre[p].l || !tre[p].r)
{
int ch = tre[p].l ? tre[p].l : tre[p].r,f = tre[p].fa;
if(f)
{
if(tre[f].l == p)
tre[f].l = ch;
else
tre[f].r = ch;
}
tre[ch].fa = f;
if(p == root)
AVLTree_ROOT__ = ch;
tre[p] = AVLDat ();
if(f)
{
upd(f);
AVLTurn(f,true);
}
return;
}
else
{
int f = tre[p].fa;
if(f)
{
if(tre[f].l == p)
tre[f].l = 0;
else
tre[f].r = 0;
upd(f);
AVLTurn(f,true);
}
else
{
tre[p] = AVLDat();
AVLTree_ROOT__ = p;
}
return;
}
}
}
if(p)
{
upd(p);
AVLTurn(p,true);
}
}
int queryrnk(typ x,int p = AVLTree_ROOT__)
{
if(!p || !tre[p].cnt)
return 0;
if(x == tre[p].num)
return tre[tre[p].l].siz;
else if(x < tre[p].num)
return queryrnk(x,tre[p].l);
return queryrnk(x,tre[p].r) + tre[p].cnt + tre[tre[p].l].siz;
}
typ queryrnknum(int rnk,int p = AVLTree_ROOT__)
{
if(!p || !tre[p].cnt)
return 0;
if(tre[tre[p].l].siz >= rnk)
return queryrnknum(rnk,tre[p].l);
else if(tre[tre[p].l].siz + tre[p].cnt >= rnk)
return tre[p].num;
return queryrnknum(rnk - tre[tre[p].l].siz - tre[p].cnt,tre[p].r);
}
int querypre(typ x,int p = AVLTree_ROOT__,int ans = -inf)
{
if(!p || !tre[p].cnt)
return ans;
if(tre[p].num >= x)
return tre[p].l ? querypre(x,tre[p].l,ans) : ans;
if(!tre[p].r)
return tre[p].num;
return querypre(x,tre[p].r,tre[p].num);
}
int querynxt(typ x,int p = AVLTree_ROOT__,int ans = inf)
{
if(!p || !tre[p].cnt)
return ans;
if(tre[p].num <= x)
return tre[p].r ? querynxt(x,tre[p].r,ans) : ans;
if(!tre[p].l)
return tre[p].num;
return querynxt(x,tre[p].l,tre[p].num);
}
};高精度
还没写完…
#include<iostream>
using namespace std;
const int BigIntMaxLen = 2e4 + 10;
struct BigInt
{
short num[BigIntMaxLen];
int len;
BigInt ()
{
len = 0;
}
int size()
{
return len;
}
short& operator [] (int p)
{
return num[p];
}
void prt()
{
for(int i = len;i > 0;i--)
cout << num[i];
}
void flat()
{
for(int i = 1;i <= len;i++)
{
num[i + 1] += num[i] / 10;
num[i] %= 10;
}
if(num[len + 1])
len++;
while(!num[len])
len--;
}
};
BigInt operator + (BigInt A,BigInt B)
{
BigInt ans;
ans.len = max(A.len,B.len);
for(int i = 1;i <= ans.len;i++)
ans[i] = A[i] + B[i];
ans.flat();
return ans;
}
BigInt operator += (BigInt &A,BigInt B)
{
return A = A + B;
}部分算法
(不怎么用)
康托展开
typedef long long ll;
const int N = 2e5 + 10;
int __lowbit_for_BIT__(int x)
{
return x & -x;
}
template <typename typ>
struct BinIndTree
{
int n;
typ Tree[N];
void clr()
{
memset(Tree,0,sizeof(Tree));
}
void change(typ value,int left,bool only_give_one = false)
{
int tmp = left + 1;
for(;left <= n;left += __lowbit_for_BIT__(left))
Tree[left] += value;
if(!only_give_one)
return;
for(;tmp <= n;tmp += __lowbit_for_BIT__(tmp))
Tree[tmp] -= value;
}
void build(typ *arr,int left,int right,bool only_give_one = false)
{
n = right - left + 1;
for(int i = left;i <= right;i++)
change(arr[i],i - left + 1,only_give_one);
}
typ query(int right)
{
typ sum = 0;
for(;right;right -= __lowbit_for_BIT__(right))
sum += Tree[right];
return sum;
}
};
// 阶乘初始化
ll fac[N];
void ini()
{
fac[0] = 1ll;
for(int i = 1;i < N;i++)
fac[i] = fac[i - 1] * i;
}
// 康托展开的树状数组优化与实现
BinIndTree <int> CantBIT;
ll Cantor(int *arr,int n)
{
CantBIT.clr();
ll ans = 0;
for(int i = 1;i <= n;i++)
{
ans += fac[n - i] * (a[i] - CantBIT.query(a[i] - 1) - 1);
CantBIT.change(1,a[i]);
}
return ans + 1;
}欧拉降幂
ll EulerPhi(ll Num)
{
ll ans = 1;
for(ll i = 2;i * i <= Num;i++)
{
if(Num % i == 0)
{
while(Num % i == 0)
Num /= i;
ans *= (i - 1);
}
}
return ans;
}
// 欧拉函数phi 1~n
void fillPhi(int MAX = N - 10)
{
phi[1] = 1;
for(int i = 2;i <= MAX;i++)
{
if(!vis[i])
{
phi[i] = i - 1;
pri[++len] = i;
}
for(int j = 1;j <= len && i * pri[j] <= MAX;j++)
{
vis[i * pri[j]] = true;
if(i % pri[j] == 0)
{
phi[i * pri[j]] = phi[i] * pri[j];
break;
}
else
phi[i * pri[j]] = phi[i] * (pri[j] - 1);
}
}
}
// 二进制优化乘法
ll BinaryMulti(ll a,ll b,ll p)
{
ll sum = 0;
while(b)
{
if(b & 1)
sum = (sum + a) % p;
a = (a + a) % p;
b >>= 1;
}
return sum;
}
// 二进制优化幂
ll BinaryPow(ll a,ll b,ll p)
{
ll ans = 1;
while(b)
{
if(b & 1)
ans = BinaryMulti(ans,a,p);
a = BinaryMulti(a,a,p);
b >>= 1;
}
return ans;
}
// 欧拉降幂
ll EulerPow(ll a,string b,ll p)
{
ll EulP = EulerPhi(p),PowerNum = 0;
for(int i = 0;i < b.size();i++)
PowerNum = (BinaryMulti(PowerNum,10,EulP) + (b[i] - '0')) % EulP;
return BinaryPow(a,(PowerNum % EulP + EulP) % EulP,p);
}倍增斐波那契
#define pll pair <ll,ll>
#define fi first
#define se second
#define mp make_pair
#define SQ(x) ((x) * (x))
const ll mod = 998244353ll;
pll Fib(ll n)
{
if(n == 0)
return mp(0ll,1ll);
pll p = Fib(n >> 1);
ll F1 = p.fi * ((2 * p.se - p.fi + mod) % mod) % mod,F2 = ((SQ(p.fi) % mod) + (SQ(p.se) % mod)) % mod;
if(n & 1)
return mp(F2,F1 + F2);
else
return mp(F1,F2);
}K-D Tree by GPT 5-mini
// kd_tree.h
// Simple header-only k-d tree for fixed dimension K and scalar type T.
// Requires C++17 (for std::array, structured bindings, etc.)
//
// Features:
// - Build from vector<array<T,K>> points (O(n log n) median-split)
// - Nearest neighbor search (exact)
// - k-NN search (exact)
// - Radius search
//
// Usage:
// using Point3 = std::array<double, 3>;
// kd::KDTree<double,3> tree(points);
// auto [pt, dist2] = tree.nearest(query);
// auto knn = tree.knn(query, 5);
// auto radius = tree.radius_search(query, r);
#pragma once
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <queue>
#include <cmath>
#include <optional>
#include <stdexcept>
namespace kd {
template<typename T, std::size_t K>
struct KDTree {
using Point = std::array<T, K>;
struct Node {
Point pt;
int left = -1;
int right = -1;
};
KDTree() = default;
explicit KDTree(const std::vector<Point>& pts) {
build(pts);
}
// Build tree from points (reorders into internal nodes vector)
void build(const std::vector<Point>& pts) {
if (pts.empty()) {
nodes.clear();
root = -1;
return;
}
// Create index list
indices.resize(pts.size());
for (std::size_t i = 0; i < pts.size(); ++i) indices[i] = static_cast<int>(i);
points = pts;
nodes.clear();
root = build_recursive(0, static_cast<int>(pts.size()) - 1, 0);
}
bool empty() const noexcept { return root == -1; }
// Exact nearest neighbor. Returns pair of point and squared distance.
// If tree is empty, returns std::nullopt.
std::optional<std::pair<Point, T>> nearest(const Point& query) const {
if (empty()) return std::nullopt;
T best_dist2 = std::numeric_limits<T>::max();
int best_idx = -1;
nearest_recursive(root, query, 0, best_idx, best_dist2);
if (best_idx == -1) return std::nullopt;
return std::make_pair(nodes[best_idx].pt, best_dist2);
}
// k nearest neighbors. Returns vector of pairs (point, squared distance), sorted by increasing distance.
// If k <= 0, returns empty vector.
std::vector<std::pair<Point, T>> knn(const Point& query, std::size_t k) const {
std::vector<std::pair<Point, T>> result;
if (empty() || k == 0) return result;
// Max-heap keeping at most k smallest distances
using PQItem = std::pair<T, int>; // dist2, idx
std::priority_queue<PQItem> pq;
knn_recursive(root, query, 0, k, pq);
result.reserve(pq.size());
while (!pq.empty()) {
auto [d2, idx] = pq.top(); pq.pop();
result.emplace_back(nodes[idx].pt, d2);
}
// pq gives farthest-first, so reverse to get increasing distance
std::reverse(result.begin(), result.end());
return result;
}
// Radius search: returns all points whose squared distance <= radius^2 (unsorted)
std::vector<std::pair<Point, T>> radius_search(const Point& query, T radius) const {
std::vector<std::pair<Point, T>> out;
if (empty() || radius < T(0)) return out;
T r2 = radius * radius;
radius_recursive(root, query, 0, r2, out);
return out;
}
private:
std::vector<Point> points; // original points (accessible by index stored in indices)
std::vector<int> indices; // permutation of indices used during build (temporary)
std::vector<Node> nodes; // nodes stored in build order
int root = -1;
static inline T sqdist(const Point& a, const Point& b) {
T s = 0;
for (std::size_t i = 0; i < K; ++i) {
T d = a[i] - b[i];
s += d * d;
}
return s;
}
// Build returns index into nodes vector of subtree root.
int build_recursive(int l, int r, int depth) {
if (l > r) return -1;
int axis = depth % static_cast<int>(K);
int mid = l + (r - l) / 2;
// nth_element on indices based on points[indices[idx]][axis]
std::nth_element(indices.begin() + l, indices.begin() + mid, indices.begin() + r + 1,
[&](int a, int b) {
return points[a][axis] < points[b][axis];
});
int idx_point = indices[mid];
int node_idx = static_cast<int>(nodes.size());
nodes.push_back(Node{points[idx_point], -1, -1});
// Build children
nodes[node_idx].left = build_recursive(l, mid - 1, depth + 1);
nodes[node_idx].right = build_recursive(mid + 1, r, depth + 1);
return node_idx;
}
void nearest_recursive(int node_idx, const Point& query, int depth, int& best_idx, T& best_dist2) const {
if (node_idx == -1) return;
const Node& node = nodes[node_idx];
T d2 = sqdist(query, node.pt);
if (d2 < best_dist2) {
best_dist2 = d2;
best_idx = node_idx;
}
int axis = depth % static_cast<int>(K);
int first = node.left, second = node.right;
// Choose closer side first
if (query[axis] > node.pt[axis]) std::swap(first, second);
if (first != -1) nearest_recursive(first, query, depth + 1, best_idx, best_dist2);
// Distance to splitting plane
T diff = query[axis] - node.pt[axis];
T diff2 = diff * diff;
if (second != -1 && diff2 <= best_dist2) {
nearest_recursive(second, query, depth + 1, best_idx, best_dist2);
}
}
void knn_recursive(int node_idx, const Point& query, int depth, std::size_t k,
std::priority_queue<std::pair<T,int>>& pq) const {
if (node_idx == -1) return;
const Node& node = nodes[node_idx];
T d2 = sqdist(query, node.pt);
if (pq.size() < k) {
pq.emplace(d2, node_idx);
} else if (d2 < pq.top().first) {
pq.pop();
pq.emplace(d2, node_idx);
}
int axis = depth % static_cast<int>(K);
int first = node.left, second = node.right;
if (query[axis] > node.pt[axis]) std::swap(first, second);
if (first != -1) knn_recursive(first, query, depth + 1, k, pq);
T diff = query[axis] - node.pt[axis];
T diff2 = diff * diff;
if (second != -1) {
if (pq.size() < k || diff2 <= pq.top().first) {
knn_recursive(second, query, depth + 1, k, pq);
}
}
}
void radius_recursive(int node_idx, const Point& query, int depth, T radius2,
std::vector<std::pair<Point, T>>& out) const {
if (node_idx == -1) return;
const Node& node = nodes[node_idx];
T d2 = sqdist(query, node.pt);
if (d2 <= radius2) out.emplace_back(node.pt, d2);
int axis = depth % static_cast<int>(K);
T diff = query[axis] - node.pt[axis];
T diff2 = diff * diff;
if (diff <= T(0)) {
if (node.left != -1) radius_recursive(node.left, query, depth + 1, radius2, out);
if (node.right != -1 && diff2 <= radius2) radius_recursive(node.right, query, depth + 1, radius2, out);
} else {
if (node.right != -1) radius_recursive(node.right, query, depth + 1, radius2, out);
if (node.left != -1 && diff2 <= radius2) radius_recursive(node.left, query, depth + 1, radius2, out);
}
}
};
} // namespace kdC++の小工具
电脑室の秘技
请小心使用
#include<bits/stdc++.h>
using namespace std;
int main()
{
system("title gg");
while(1)
{
system("taskkill /f /im studentmain.exe");
system("taskkill /f /im veyon-server.exe");
system("taskkill /f /im veyon-service.exe");
system("taskkill /f /im veyon-wcli.exe");
system("taskkill /f /im veyon-worker.exe");
system("taskkill /f /im DeploymentAgent.exe /t");
}
return 0;
}键盘自动按下工具
好东西
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
#define KeyDn(x) keybd_event((x),0,0,0)
#define KeyUp(x) keybd_event((x),0,KEYEVENTF_KEYUP,0)
bool ispr(int _k) {
return GetAsyncKeyState(_k) & 0x8000;
}
const int N = 1e5 + 10;
ifstream FileIn;
int n;
struct KeyHit {
string HitKey;
char ToggleKey;
bool Toggled,ChoseToggled;
KeyHit (string _HitKey = "",char _ToggleKey = 0,bool _Toggled = false,bool _ChoseToggled = true) {
HitKey = _HitKey;
ToggleKey = _ToggleKey;
Toggled = _Toggled;
ChoseToggled = _ChoseToggled;
}
}List[N];
void Upper(char &x) {
if('a' <= x && x <= 'z') {
x -= 32;
}
}
void MsClick(int Type,bool type) {
POINT a;
GetCursorPos(&a);
switch(Type) {
case 0: {
mouse_event(type ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP,a.x,a.y,0,0);
break;
}
case 1: {
mouse_event(type ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP,a.x,a.y,0,0);
break;
}
case 2: {
mouse_event(type ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP,a.x,a.y,0,0);
break;
}
}
}
int main() {
FileIn.open("AutoKeyHitter.txt");
FileIn >> n;
for(int i = 1;i <= n;i++) {
FileIn >> List[i].HitKey >> List[i].ToggleKey;
Upper(List[i].ToggleKey);
int len = List[i].HitKey.size();
for(int j = 0;j < len;j++) {
Upper(List[i].HitKey[j]);
}
for(int j = 0;j < len;j++) {
if(List[i].HitKey[j] == '_') {
j++;
string t = "";
while(j < len && List[i].HitKey[j] != '_') {
t += List[i].HitKey[j];
j++;
}
if(t == "PUSH") {
List[i].ChoseToggled = false;
}
}
}
}
while(true) {
for(int i = 1;i <= n;i++) {
int len = List[i].HitKey.size();
if(ispr(List[i].ToggleKey)) {
if(List[i].ChoseToggled) {
List[i].Toggled = !List[i].Toggled;
Sleep(150);
}
else {
for(int j = 0;j < len;j++) {
if(List[i].HitKey[j] == '_') {
j++;
string t = "";
while(j < len && List[i].HitKey[j] != '_') {
t += List[i].HitKey[j];
j++;
}
if(t == "LEFT") {
MsClick(0,1);
MsClick(0,0);
}
if(t == "RIGHT") {
MsClick(2,1);
MsClick(2,0);
}
if(t == "MIDDLE") {
MsClick(1,1);
MsClick(1,0);
}
}
else {
KeyDn(List[i].HitKey[j]);
KeyUp(List[i].HitKey[j]);
}
}
Sleep(30);
}
}
}
for(int i = 1;i <= n;i++) {
int len = List[i].HitKey.size();
if(List[i].Toggled) {
for(int j = 0;j < len;j++) {
if(List[i].HitKey[j] == '_') {
j++;
string t = "";
while(j < len && List[i].HitKey[j] != '_') {
t += List[i].HitKey[j];
j++;
}
if(t == "LEFT") {
MsClick(0,1);
MsClick(0,0);
}
if(t == "RIGHT") {
MsClick(2,1);
MsClick(2,0);
}
if(t == "MIDDLE") {
MsClick(1,1);
MsClick(1,0);
}
}
else {
KeyDn(List[i].HitKey[j]);
KeyUp(List[i].HitKey[j]);
}
}
Sleep(30);
}
}
}
return 0;
}
/*
2
_LEFT__PUSH_ C
_RIGHT__PUSH_ Z
*/