缺省源
#include<bits/stdc++.h>
using namespace std;using ll=long long;using ull=unsigned long long;using uint=unsigned int;mt19937_64 rnd(time(0));
constexpr int N=3e5+9,R=998244353;
signed main(){
cin.tie(0)->sync_with_stdio(0);
return 0;
}编译选项
-O2 -std=c++26 -static -Wall -Wextra -Wl,--stack,566777216哈希相关
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
struct custom_hash{
ull operator() (ull x) const{
static const ull r1=rnd(),r2=rnd(),r3=rnd();
x+=r1;
x=(x^x>>30)*r2;
x=(x^x>>33)*r3;
return x;
}
};简易 ODT:
void split(int x){
auto it=prev(tr.upper_bound(x));
if(it->first!=x) tr[x]=it->second,it->second.first=x-1;
}
void assign(int l,int r,ull k){
split(l),split(r+1);
tr.erase(tr.find(l),tr.find(r+1));
tr[l]={r,k};
}树状数组(带权):
template<int N> struct fenwick_tree{
ll a[N];fenwick_tree(){memset(a,0,sizeof(a));}
void insert(int x,ll k){for(;x>0&&x<N;x+=lowbit(x)) a[x]+=k;}
ll sum(int x){ll res=0;for(x=min(max(x,0),N-1);x;x-=lowbit(x)) res+=a[x];return res;}
ll sum(int l,int r){return sum(r)-sum(l-1);}
};树状数组(不带权):
struct fenwick_tree{
int c1[64],sz;char c2[4096];ull bmp[4096];
inline ull lm(int x){return -1ull>>(63^x);}
fenwick_tree(){memset(c1,0,sizeof(c1));memset(c2,0,sizeof(c2));memset(bmp,0,sizeof(bmp));}
void insert(int x){sz++;c1[x>>12]++;c2[x>>6]++;bmp[x>>6]^=1ull<<(x&63);}
void erase(int x){sz--;c1[x>>12]--;c2[x>>6]--;bmp[x>>6]^=1ull<<(x&63);}
int sum(int x){int l=0,r=x>>12,res=accumulate(c1+l,c1+r,0);l=r<<6,r=x>>6;res+=accumulate(c2+l,c2+r,0);l=r,r=x&63;return res+__builtin_popcountll(bmp[l]&lm(r));};
};