diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/README.md b/template-LaTeX-ECNU-F0RE1GNERS-main/README.md new file mode 100644 index 0000000..5c6efc6 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/README.md @@ -0,0 +1,6 @@ +# template-LaTeX-ECNU-F0RE1GNERS +Build Code Library with LaTeX, base on [ECNU F0RE1GNERS template](https://github.com/F0RE1GNERS/template/tree/master). + +[PDF 下载](https://github.com/XCPCIO/template-LaTeX-ECNU-F0RE1GNERS/raw/gh-pages/template.pdf) + +[使用指北](https://xcpcio.com/code-library/code-library-build/#latex-ecnu-f0re1gners) diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/0_to_latex.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/0_to_latex.cpp new file mode 100644 index 0000000..5e22e32 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/0_to_latex.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +namespace fs = std::filesystem; + +// 仅在下划线前面添加反斜杠进行转义 +std::string escape_filename(const std::string& filename) { + std::string safe_filename = filename; + size_t pos = 0; + while ((pos = safe_filename.find('_', pos)) != std::string::npos) { + safe_filename.insert(pos, "\\"); // 在下划线前面插入反斜杠 + pos += 2; // 更新位置,跳过新插入的字符 + } + return safe_filename; +} + +int main() { + const std::string output_filename = "listings.tex"; + std::ofstream outfile(output_filename); + + if (!outfile.is_open()) { + std::cerr << "Failed to open output file." << std::endl; + return 1; + } + + outfile << "% Generated LaTeX code for C++ file listings" << std::endl; + outfile << "\\section{All}\n"; + for (const auto& entry : fs::directory_iterator(".")) { + const auto& path = entry.path(); + if (entry.is_regular_file() && path.extension() == ".cpp") { + std::string filename = path.filename().string(); + std::string basename = escape_filename(filename); // 转义文件名 + + // 构造子章节标题,这里简单地使用转义后的文件名 + std::string subsection_title = basename.substr(0, basename.size() - 4); + + // 输出到LaTeX文件 + + outfile << "\\subsection{" << subsection_title << "}\n"; + outfile << "\\raggedbottom\\lstinputlisting[style=cpp]{assets/" << basename << "}\n"; // 假设.cpp文件在assets目录下 + outfile << "\\hrulefill\n\n"; + } + } + + outfile.close(); + std::cout << "LaTeX listings generated in " << output_filename << std::endl; + return 0; +} diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/AC-Automaton.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/AC-Automaton.cpp new file mode 100644 index 0000000..a75aa49 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/AC-Automaton.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +#define int long long +using namespace std; +const int N=1e6+5; +const int M=1e8+5; +const int INF=1e9; +const int p=998244353; +const double DARW=0.97; +int tree[N][30],bh,f[N],fail[N],ff[N],lst_[N]; +queueq; +void insert(string s){ + int p=0; + for(int i=0;i>n; + for(int i=1;i<=n;i++){ + string ss; + cin>>ss; + insert(ss); + } + build(); + string t; + cin>>t; + int ans=0; + for(int i=0,j=0;i>t; + while(t--){ + solve(); + } +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/BarrettReduction.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/BarrettReduction.cpp new file mode 100644 index 0000000..4d66dc8 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/BarrettReduction.cpp @@ -0,0 +1,8 @@ +struct Mod +{ + long long m, p; + void init(int pp) { m = ((__int128)1 << 64) / pp; p = pp; } + long long operator ()(long long x){ + return x - ((__int128(x) * m) >> 64) * p; + } +} mod; \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Binary heap.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Binary heap.cpp new file mode 100644 index 0000000..21d890b --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Binary heap.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +#define int long long +using namespace std; +const int N=1e6+5; +const int M=1e8+5; +const int INF=1e9; +const int p=998244353; +const double DARW=0.97; +int n,a[N]; +void up(int x){ + while(x/2&&a[x]=a[x])break; + swap(a[t],a[x]); + x=t; + } +} +void build(){ + for(int i=n;i>=1;i--)down(i); +} +void solve(){ + int q; + cin>>q; + while(q--){ + int op,x; + cin>>op; + if(op==1){ + cin>>x; + a[++n]=x; + up(n); + }else if(op==2)cout<>t; + while(t--){ + solve(); + } +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/CSC_dij.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/CSC_dij.cpp new file mode 100644 index 0000000..7bff68e --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/CSC_dij.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +#define int long long +#define pii pair +using namespace std; +const int N=2e5+5; +const int M=5e6+5; +const int INF=1e9; +//const int p=998244353; +const int MOD=1e9+7; +const double DARW=0.97; +const double eps=1e-12; +int ans[N],f[N]; +vectort[N]; +struct node{int x,val;bool operator<(const node& a)const{return val>a.val;}}; +struct edge{int v,w;}; +vectore[N]; +priority_queueq; +void dij(){ + while(q.size()&&f[q.top().x])q.pop(); + if(q.empty())return; + node x=q.top(); + q.pop(); + f[x.x]=1; + for(auto u:e[x.x]){ + if(u.w+ans[x.x]>h>>a>>b>>c; + if(a=ans[i]) + as+=(h-ans[i])/c+1; + } + cout<>t; + while(t--)solve(); +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/CSC_dp.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/CSC_dp.cpp new file mode 100644 index 0000000..7313c0c --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/CSC_dp.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +#define int long long +#define pii pair +using namespace std; +const int N=5e5+5; +const int M=5e6+5; +const int INF=1e9; +//const int p=998244353; +const int MOD=1e9+7; +const double DARW=0.97; +const double eps=1e-12; +int dp[N],a[20]; +int gcd(int a,int b){ + if(!b)return a; + return gcd(b,a%b); +} +void solve(){ + int n,l,r; + cin>>n>>l>>r; + for(int i=1;i<=n;i++)cin>>a[i]; + for(int i=1;i=dp[i])ans+=(r-dp[i])/a[1]+1; + if(l>dp[i])ans-=(l-1-dp[i])/a[1]+1; + } + cout<>t; + while(t--)solve(); +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Dinic.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Dinic.cpp new file mode 100644 index 0000000..7803d7a --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Dinic.cpp @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +#define int long long +#define pii pair +using namespace std; +const int N=2e3+5; +const int M=1e5+5; +const int INF=2e9; +//const int p=998244353; +const int MOD=1e9+7; +const double DARW=0.97; +int tot,m,n,s,t; +struct edge{ + int v,w,nxt; +}e[N<<2]; +int head[N],a[N],b[N],vis[N],d[N]; +setans; +void add(int u,int v,int w){ + e[tot].v=v; + e[tot].w=w; + e[tot].nxt=head[u]; + head[u]=tot++; +} +int bfs(){ + ans.clear(); + memset(vis,0,sizeof(vis)); + queueq; + q.push(s); + vis[s]=1; + d[s]=0; + while(!q.empty()){ + int x=q.front(); + q.pop(); + for(int i=head[x];i!=-1;i=e[i].nxt){ + if(vis[e[i].v]||e[i].w==0)continue; + ans.insert(e[i].v); + d[e[i].v]=d[x]+1; + vis[e[i].v]=1; + q.push(e[i].v); + } + } + //cout<0){ + e[i].w-=f; + e[i^1].w+=f; + a-=f; + flow+=f; + if(a==0)break; + } + } + return flow; +} +int Dinic(){ + int flow=0; + while(bfs()){ + flow+=dfs(s,INF); + } + return flow; +} +void solve(){ + cin>>m>>n; + int as=0;s=0,t=n+m+1; + memset(head,-1,sizeof(head)); + string str; + stringstream ss; + for(int i=1;i<=m;i++){ + cin>>a[i]; + as+=a[i]; + add(0,i,a[i]); + add(i,0,0); + ss.clear(); + getline(cin,str); + ss<>x){ + //cout<>b[i]; + add(i+m,n+m+1,b[i]); + add(n+m+1,i+m,0); + } + as-=Dinic(); + vectorans1,ans2; + for(auto u:ans){ + if(u<=m)ans1.push_back(u); + else ans2.push_back(u-m); + } + for(auto u:ans1)cout<>t; + while(tt--){ + solve(); + } +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/EXKMP_z-Fuction.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/EXKMP_z-Fuction.cpp new file mode 100644 index 0000000..2278b65 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/EXKMP_z-Fuction.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +#define int long long +using namespace std; +const int N=2e7+5; +const int M=1e8+5; +const int INF=1e9; +//const int p=998244353; +const int MOD=1e9+7; +const double DARW=0.97; +int z[N],p[N]; +void solve(){ + string a,b; + cin>>a>>b; + b=" "+b; + a=" "+a; + int ansz=b.length(),ansp=0; + for(int l=1,r=1,i=2;ir)r=i+z[i]-1,l=i; + } + //cout<r)r=i+p[i]-1,l=i; + } + ansp^=i*(p[i]+1); + } + cout<>t; + while(t--){ + solve(); + } +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Exgcd.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Exgcd.cpp new file mode 100644 index 0000000..26fa55c --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Exgcd.cpp @@ -0,0 +1,20 @@ +#include +#include +#define ll long long +using namespace std; +const int N=3e6 +5; +ll inv[N]; +void exgcd(ll a,ll b,ll &x,ll &y){ + if(!b)x=1,y=0; + else exgcd(b,a%b,y,x),y-=a/b*x; +} +int main(){ + ll n,p; + cin>>n>>p;inv[1]=1; + for(ll i=2;i<=n;i++){ + inv[i]=(((-p/i)*inv[p%i])%p+p)%p; + } + for(int i=1;i<=n;i++){ + cout< +#define int long long +#define double long double +using namespace std; +const double PI=acos(-1); +const int N=5e6+5; +namespace Poly{ + int len,Lim=1,Alen,Blen,rev[N],ans[N],p; + void setP(int x){p=x;} + struct Complex{ + double r,i; + Complex(){r=0,i=0;} + Complex(double real,double imag):r(real),i(imag){} + }; + inline Complex operator +(Complex A,Complex B){return Complex(A.r+B.r,A.i+B.i);} + inline Complex operator -(Complex A,Complex B){return Complex(A.r-B.r,A.i-B.i);} + inline Complex operator *(Complex A,Complex B){return Complex(A.r*B.r-A.i*B.i,A.r*B.i+A.i*B.r);} + inline void init(int Alen,int Blen){ + while(Lim<=Alen+Blen)Lim<<=1,++len; + for(int i=0;i>1]>>1)|((i&1)<<(len-1)); + } + inline void FFT(vector& a,int type){ + for(int i=0;i mul(vector f,vector g){ + int lf=f.size(),lg=g.size(); + init(lf,lg); + f.resize(Lim),g.resize(Lim); + vector h(Lim); + FFT(f,1);FFT(g,1); + for(int i=0;i mul(vector f,vector g){ + int lf=f.size(),lg=g.size(); + vectorff(lf); + vectorgg(lg); + for(int i=0;i hh=mul(ff,gg); + vector h(lf+lg-1); + for(int i=0;i pmul(vector f,vector g){ + int lf=f.size(),lg=g.size(); + init(lf,lg); + f.resize(Lim),g.resize(Lim); + vector v1(Lim),v2(Lim),v3(Lim),v4(Lim),h1(Lim),h2(Lim),h3(Lim); + for(int i=0;i>15; + v2[i].r=f[i]&((1<<15)-1); + v3[i].r=g[i]>>15; + v4[i].r=g[i]&((1<<15)-1); + } + FFT(v1,1);FFT(v2,1);FFT(v3,1);FFT(v4,1); + for(int i=0;i h(lf+lg-1); + for(int i=0,w1,w2,w3;i>n>>m>>p; + Poly::setP(p); + vectorA(n+1); + vectorB(m+1); + for(int i=0;i<=n;i++)cin>>A[i]; + for(int i=0;i<=m;i++)cin>>B[i]; + vectorh=Poly::pmul(A,B); + for(int i=0;i<=n+m;i++)cout<>t; + while(t--){ + solve(); + } +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/FHQ_treap.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/FHQ_treap.cpp new file mode 100644 index 0000000..8974c7b --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/FHQ_treap.cpp @@ -0,0 +1,168 @@ +#include +#define int long long +const int N=1e5+5; +using namespace std; + +struct Node{ + Node *ch[2]; + int val,prio; + int cnt; + int siz; + Node(int val):val(val),cnt(1),siz(1){ + ch[0]=ch[1]=nullptr; + prio=rand(); + } + Node(Node *node){ + val=node->val,prio=node->prio,cnt=node->cnt,siz=node->siz; + } + inline void upd_siz(){ + siz=cnt; + if(ch[0]!=nullptr)siz+=ch[0]->siz; + if(ch[1]!=nullptr)siz+=ch[1]->siz; + } +}; +struct none_rot_treap{ +#define _3 second.second +#define _2 second.first + vectorrt; + none_rot_treap(){rt.push_back(nullptr);} + pair split(Node* cur,int key){ + if(cur==nullptr)return {nullptr,nullptr}; + if(cur->val<=key){ + auto temp=split(cur->ch[1],key); + cur->ch[1]=temp.first; + cur->upd_siz(); + return {cur,temp.second}; + }else{ + auto temp=split(cur->ch[0],key); + cur->ch[0]=temp.second; + cur->upd_siz(); + return {temp.first,cur}; + } + } + tuplesplit_by_rk(Node* cur,int rk){ + if(cur==nullptr)return {nullptr,nullptr,nullptr}; + int ls_siz=cur->ch[0]==nullptr?0:cur->ch[0]->siz; + if(rk<=ls_siz){ + Node *l,*mid,*r; + tie(l,mid,r)=split_by_rk(cur->ch[0],rk); + cur->ch[0]=r; + cur->upd_siz(); + return {l,mid,cur}; + }else if(rk<=ls_siz+cur->cnt){ + Node *lt=cur->ch[0]; + Node *rt=cur->ch[1]; + cur->ch[0]=cur->ch[1]=nullptr; + return {lt,cur,rt}; + }else{ + Node *l,*mid,*r; + tie(l,mid,r)=split_by_rk(cur->ch[1],rk-ls_siz-cur->cnt); + cur->ch[1]=l; + cur->upd_siz(); + return {cur,mid,r}; + } + } + Node* merge(Node* u,Node* v){ + if(u==nullptr&&v==nullptr)return nullptr; + if(u!=nullptr&&v==nullptr)return u; + if(v!=nullptr&&u==nullptr)return v; + if(u->prioprio){ + Node* temp=new Node(u); + temp->ch[0]=u->ch[0]; + temp->ch[1]=merge(u->ch[1],v); + temp->upd_siz(); + return temp; + }else{ + Node* temp=new Node(v); + temp->ch[1]=v->ch[1]; + temp->ch[0]=merge(u,v->ch[0]); + temp->upd_siz(); + return temp; + } + } + void insert(int val){ + auto temp=split(root,val); + auto l_tr=split(temp.first,val-1); + Node *new_node; + if(l_tr.second==nullptr){ + new_node=new Node(val); + }else{ + l_tr.second->cnt++; + l_tr.second->upd_siz(); + } + Node *l_tr_combined=merge(l_tr.first,l_tr.second==nullptr?new_node:l_tr.second); + root=merge(l_tr_combined,temp.second); + } + void del(int val){ + auto temp=split(root,val); + auto l_tr=split(temp.first,val-1); + if(l_tr.second->cnt>1){ + l_tr.second->cnt--; + l_tr.second->upd_siz(); + l_tr.first=merge(l_tr.first,l_tr.second); + }else{ + if(temp.first==l_tr.second){ + temp.first=nullptr; + } + delete l_tr.second; + l_tr.second=nullptr; + } + root=merge(l_tr.first,temp.second); + } + int qrank_by_val(Node *cur,int val){ + auto temp=split(cur,val-1); + int ret=(temp.first==nullptr?0:temp.first->siz)+1; + root=merge(temp.first,temp.second); + return ret; + } + int qval_by_rank(Node *cur,int rk){ + Node *l,*mid,*r; + tie(l,mid,r)=split_by_rk(cur,rk); + int ret=mid->val; + root=merge(merge(l,mid),r); + return ret; + } + int qprev(int val){ + auto temp=split(root,val-1); + int ret=qval_by_rank(temp.first,temp.first->siz); + root=merge(temp.first,temp.second); + return ret; + } + int qnex(int val){ + auto temp=split(root,val); + int ret=qval_by_rank(temp.second,1); + root=merge(temp.first,temp.second); + return ret; + } +}; +none_rot_treap tr; +int a[N]; +void solve(){ + srand(time(0)); + int n,m,ans=0; + cin>>n>>m; + for(int i=1;i<=n;i++)cin>>a[i],tr.insert(a[i]); + int lst=0; + while(m--){ + int op,x; + cin>>op>>x; + x^=lst; + if(op==1)tr.insert(x); + else if(op==2)tr.del(x); + else if(op==3)ans^=(lst=tr.qrank_by_val(tr.root,x)); + else if(op==4)ans^=(lst=tr.qval_by_rank(tr.root,x)); + else if(op==5)ans^=(lst=tr.qprev(x)); + else ans^=(lst=tr.qnex(x)); + } + cout<>t; + while(t--){ + solve(); + } +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/FastRead.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/FastRead.cpp new file mode 100644 index 0000000..ea17869 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/FastRead.cpp @@ -0,0 +1,7 @@ +inline int read() +{ + int x=0,f=1;char ch=getchar(); + while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} + while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();} + return x*f; +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Inv_FFT.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Inv_FFT.cpp new file mode 100644 index 0000000..b5f581c --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Inv_FFT.cpp @@ -0,0 +1,95 @@ +#include +#define int long long +using namespace std; +const double PI=acos(-1); +const int N=5e6+5; +const int MOD=998244353; +int ksm(int x,int k){ + int ans=1; + while(k){ + if(k&1)ans=x*ans%MOD; + x=x*x%MOD; + k>>=1; + } + return ans; +} +namespace Poly{ + int len,Lim=1,Alen,Blen,rev[N],ans[N]; + struct Complex{ + double r,i; + Complex(){r=0,i=0;} + Complex(double real,double imag):r(real),i(imag){} + }; + inline Complex operator +(Complex A,Complex B){return Complex(A.r+B.r,A.i+B.i);} + inline Complex operator -(Complex A,Complex B){return Complex(A.r-B.r,A.i-B.i);} + inline Complex operator *(Complex A,Complex B){return Complex(A.r*B.r-A.i*B.i,A.r*B.i+A.i*B.r);} + inline void init(int Alen,int Blen){ + while(Lim<=Alen+Blen)Lim<<=1,++len; + for(int i=0;i>1]>>1)|((i&1)<<(len-1)); + } + inline void FFT(vector& a,int type){ + for(int i=0;i mul(vector f,vector g){ + int lf=f.size(),lg=g.size(); + init(lf,lg); + f.resize(Lim),g.resize(Lim); + vector h(Lim); + FFT(f,1);FFT(g,1); + for(int i=0;i Inv(int n,vector A){ + vector B(n); + B[0].r=ksm(A[0].r,MOD-2,MOD); + int deg=1; + while(deg<(n<<1)){ + deg<<=1; + vector C=(deg<=n?vector(A.begin(),A.begin()+deg):A); + init(deg,B.size()); + C.resize(Lim);B.resize(Lim); + FFT(C,1);FFT(B,1); + for(int i=0;i>n; + vectorA(n); + for(int i=0;i>A[i].r; + vectorans=Poly::Inv(n,A); + for(int i=0;i>t; + while(t--){ + solve(); + } +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Inv_NTT.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Inv_NTT.cpp new file mode 100644 index 0000000..89332a2 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Inv_NTT.cpp @@ -0,0 +1,85 @@ +#include +#define ll long long + +using namespace std; +const int N=3e6+5; +inline int ksm(int x,int k,int mod){ + int ans=1; + while(k){ + if(k&1)ans=1ll*ans*x%mod; + x=1ll*x*x%mod; + k>>=1; + } + return ans; +} +namespace Poly{ + const int MOD=998244353,G=3,INVG=332748118; + int lim,len,rev[N],invlim; + inline void init(int l1,int l2){ + lim=1,len=0; + while(lim<=l1+l2)lim<<=1,len++; + for(int i=0;i>1]>>1)|((i&1)<<(len-1)); + invlim=ksm(lim,MOD-2,MOD); + } + inline void NTT(vector &f,int type){ + for(int i=0;i mul(vector f,vector g){ + int lf=f.size(),lg=g.size(); + init(lf,lg); + f.resize(lim),g.resize(lim); + vector h(lim); + NTT(f,1);NTT(g,1); + for(int i=0;i Inv(int n,vector A){ + vector B(n); + B[0]=ksm(A[0],MOD-2,MOD); + int deg=1; + while(deg<(n<<1)){ + deg<<=1; + vector C=(deg<=n?vector(A.begin(),A.begin()+deg):A); + init(deg,B.size()); + C.resize(lim);B.resize(lim); + NTT(C,1);NTT(B,1); + for(int i=0;i>n; + vector f(n); + for(int i=0;i>f[i]; + vector g=Poly::Inv(n,f); + for(int i=0;i>t; + while(t--){ + solve(); + } +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Left partial tree.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Left partial tree.cpp new file mode 100644 index 0000000..1f39611 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Left partial tree.cpp @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +#define int long long +using namespace std; +const int N=1e6+5; +const int M=1e8+5; +const int INF=1e9; +const int p=998244353; +const double DARW=0.97; +struct node{int ch[2],d,val;}t[N]; +int f[N],ff[N]; +int find(int x){ + if(f[x]==x)return x; + return f[x]=find(f[x]); +} +int& rs(int x){return t[x].ch[t[t[x].ch[1]].dt[y].val||(t[x].val==t[y].val&&x>y))swap(x,y); + f[y]=find(x); + rs(x)=merge(rs(x),y); + t[x].d=t[rs(x)].d+1; + return x; +} +void solve(){ + int n,m; + cin>>n; + for(int i=1;i<=n;i++){ + cin>>t[i].val;t[i].d=1; + f[i]=i;ff[i]=1; + } + cin>>m; + while(m--){ + char op; + int x,y; + cin>>op; + if(op=='M'){ + cin>>x>>y; + if(!ff[x]||!ff[y]||find(x)==find(y))continue; + merge(find(x),find(y)); + }else { + cin>>x; + if(!ff[x]){ + cout<<"0\n"; + continue; + } + int k=find(x); + cout<>t; + while(t--){ + solve(); + } +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Linklist.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Linklist.cpp new file mode 100644 index 0000000..fd820c9 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Linklist.cpp @@ -0,0 +1,112 @@ +#include +using namespace std; +struct Node{ + int date; + Node* next; + Node(const int& d):date(d),next(0){} +}; +class LinkList{ + Node* pHead; +public: + LinkList():pHead(0){}; + ~LinkList(); + int IsEmpty(); + void Print(); + void Insert(int value); + void deletenode(int value); + Node* find(int value); + LinkList& operator=(const LinkList& a); +}; +LinkList::~LinkList(){ + Node* pNow; + while(pHead){ + pNow=pHead; + pHead=pHead->next; + delete pNow; + } +} +int LinkList::IsEmpty(){ + if(pHead)return 0;//首节点存在即非空 + else return 1; +} +void LinkList::Print(){ + for(Node* pNow=pHead;pNow;pNow=pNow->next){ + cout<date<<" "; + } + cout<<"\n"; +} +void LinkList::Insert(int value){ + Node* p=new Node(value); + p->next=pHead; + pHead=p; +} +void LinkList::deletenode(int value){ + Node *pLst=pHead,*pNow=pHead; + while(pNow&&pNow->date!=value)pLst=pNow,pNow=pNow->next; + if(!pNow)return;//不存在value + if(pNow==pHead){//删除节点为首节点 + pHead=pHead->next; + delete pNow; + }else {//删除节点非首节点 + pLst->next=pNow->next; + delete pNow; + } +} +Node* LinkList::find(int value){ + Node *pNow=pHead; + while(pNow&&pNow->date!=value)pNow=pNow->next; + return pNow; +} +LinkList& LinkList::operator=(const LinkList& a){ + if(this==&a)return *this;//为自身则返回 + this->~LinkList();//释放原来点 + pHead=0; + if(!a.pHead)return *this; + pHead=new Node(a.pHead->date); + pHead->next=0; + Node* p; + for(Node *pNow=a.pHead->next,*plst=pHead;pNow;pNow=pNow->next){ + p=new Node(pNow->date); + plst->next=p; + p->next=0; + plst=p; + } + return *this; +} +int main(){ + LinkList a; + int num,n; + cout<<"the size of list:"; + cin>>n; + while(n--){//测试输入 + cout<<"cin:"; + cin>>num; + a.Insert(num); + cout<<"list a:"; + a.Print(); + } + LinkList b; + b=a; + cout<<"list b:"; + b.Print(); + int finda; + cout<<"find:"; + cin>>finda; + Node* it=a.find(finda);//测试查找、= + cout<<"the address of findnum:"; + cout<date=0; + cout<<"list a:"; + a.Print(); + cout<<"list b:"; + b.Print(); + int del; + while(!a.IsEmpty()){//测试删除,判空 + cout<<"del:"; + cin>>del; + a.deletenode(del); + cout<<"list a:"; + a.Print(); + } + +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Linklist_template.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Linklist_template.cpp new file mode 100644 index 0000000..1a452b2 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Linklist_template.cpp @@ -0,0 +1,104 @@ +#include +using namespace std; +template +struct Node{ + T date; + Node* next; + Node(const T& d):date(d),next(0){} +}; +template +class LinkList{ +public: + Node* pHead; + LinkList():pHead(0){}; + ~LinkList(); + int IsEmpty(); + void Print(); + void Insert(const T& value); + void deletenode(const T& value); + Node* find(const T& value); + LinkList& operator=(const LinkList& a); +}; +template +LinkList::~LinkList(){ + Node* pNow; + while(pHead){ + pNow=pHead; + pHead=pHead->next; + delete pNow; + } +} +template +int LinkList::IsEmpty(){ + if(pHead)return 0;//首节点存在即非空 + else return 1; +} +template +void LinkList::Print(){ + for(Node* pNow=pHead;pNow;pNow=pNow->next){ + cout<date<<" "; + } + cout<<"\n"; +} +template +void LinkList::Insert(const T& value){ + Node* p=new Node(value); + p->next=pHead; + pHead=p; +} +template +void LinkList::deletenode(const T& value){ + Node *pLst=pHead,*pNow=pHead; + while(pNow&&pNow->date!=value)pLst=pNow,pNow=pNow->next; + if(!pNow)return;//不存在value + if(pNow==pHead){//删除节点为首节点 + pHead=pHead->next; + delete pNow; + }else {//删除节点非首节点 + pLst->next=pNow->next; + delete pNow; + } +} +template +Node* LinkList::find(const T& value){ + Node *pNow=pHead; + while(pNow&&pNow->date!=value)pNow=pNow->next; + return pNow; +} +template +LinkList& LinkList::operator=(const LinkList& a){ + if(this==&a)return *this;//为自身则返回 + this->~LinkList();//释放原来点 + pHead=0; + if(!a.pHead)return *this; + pHead=new Node(a.pHead->date); + pHead->next=0; + Node* p; + for(Node *pNow=a.pHead->next,*plst=pHead;pNow;pNow=pNow->next){ + p=new Node(pNow->date); + plst->next=p; + p->next=0; + plst=p; + } + return *this; +} +template +LinkList Get_same(const LinkList& a,const LinkList& b){ + Node *it1=a.pHead,*it2=b.pHead; + LinkList c; + while(it1&&it2){ + if(it1->date==it2->date)c.Insert(it1->date),it1=it1->next,it2=it2->next; + else if(it1->date>it2->date)it2=it2->next; + else it1=it1->next; + } + return c; +} +int main(){ + LinkList a; + LinkList b; + char a1[]{'A','C','D','G','H'},b1[]{'B','C','E','G','H','O'}; + for(int i=4;i>=0;i--)a.Insert(a1[i]); + for(int i=5;i>=0;i--)b.Insert(b1[i]); + LinkList c=Get_same(a,b); + c.Print(); +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/List.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/List.cpp new file mode 100644 index 0000000..0782b3a --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/List.cpp @@ -0,0 +1,236 @@ +#include +#include +using namespace std; +struct Node{ + int date; + Node *next; + Node(const int& d):date(d),next(0){} +}; + +bool cmp1(int a,int b){return anext)arr[i]=p->date;//存入数组 + sort(arr,arr+listSize,cmp);//排序 + p=first; + for(int i=0;inext)p->date=arr[i];//更新链表 + delete[] arr; +} +List operator+(const List& a,const List&b){ + List c(a); + c+=b; + return c; +} +List& List::operator+=(const List& a){ + for(Node *p=a.first;p;p=p->next){ + Node *now=new Node(p->date); + last->next=now; + last=now; + } + listSize+=a.listSize; + return *this; +} +List& List::operator=(const List& a){ + if(this==&a)return *this; + new(this) List(a); + return *this; +} +void List::remove_all(const int& x){//移除所有为x的数 + while(remove(x)); +} +void List::erase(Node *pos){//移除指针为pos的数 + if(pos==first)pop_front();//若指定为首地址则利用pop_front函数 + else { + Node *p=first; + while(p->next!=pos)p=p->next;//找到pos前指针 + p->next=pos->next; + if(pos==last)last=p; + delete pos; + --listSize; + } +} +void List::erase(const int& w){//移除第x个的数 + if(w>listSize)return;//若w大于链表大小则返回 + if(w==1)pop_front(); + else { + Node *now=first->next,*before=first; + for(int i=2;i<=w;i++)before=now,now=now->next;//找到第x数所对应指针和第x-1数所对//应指针 + before->next=now->next; + if(now==last)last=before; + delete now; + --listSize; + } +} +List::List(int a[],int num){//将数组转换为链表 + listSize=num; + if(!num){ + first=0; + last=0; + }else { + Node *p=new Node(a[0]); + first=last=p; + for(int i=1;inext=p; + last=p; + } + } +} +List::List(const List &a){//拷贝 + listSize=a.listSize; + if(!listSize){ + first=last=0; + return; + } + Node *p=new Node(a.first->date),*now=a.first->next; + first=last=p; + for(;now;now=now->next){ + p=new Node(now->date); + last->next=p; + last=p; + } +} +void List::push_back(const int& x){//在链表末添加x + Node *p=new Node(x); + if(!listSize)first=last=p; + else { + last->next=p; + last=p; + } + ++listSize; +} +void List::push_front(const int& x){//将x置入链表首 + Node *p=new Node(x); + if(!listSize)first=last=p; + else { + p->next=first; + first=p; + } + ++listSize; +} +bool List::pop_back(){//移除链表最后一个数 + if(!listSize)return 0; + if(listSize==1){ + delete[] first; + first=last=0; + }else { + Node *now=first; + while(now->next!=last)now=now->next; + last=now; + delete now->next; + now->next=0; + } + --listSize; + return 1; +} +bool List::pop_front(){//移除链表第一个数 + if(!listSize)return 0; + if(listSize==1){ + delete first; + first=last=0; + }else { + Node *now=first; + first=first->next; + delete now; + } + --listSize; + return 1; +} +bool List::remove(const int& x){//移除第一个值为x的数 + Node *now=first,*before=first; + while(now&&now->date!=x)before=now,now=now->next;//找到第一个值为x的数 + if(now){//若存在值为x的数 不存在则返回0 + if(listSize==1){ + delete now; + first=last=0; + }else { + if(now==first){ + first=first->next; + delete now; + } + else if(now==last){ + last=before; + delete now; + last->next=0; + } + else{ + before->next=now->next; + delete now; + } + } + --listSize; + return 1; + } + return 0; +} +void List::clear(){//清空链表 + this->~List(); + first=last=0; + listSize=0; +} +void List::insert(Node *pos,const int& x){//在pos后插入x + Node *p=new Node(x); + p->next=pos->next; + pos->next=p; + if(pos==last)last=p; + ++listSize; +} +List::~List(){ + for(Node *p=first;first!=0;p=first){ + first=first->next; + delete p; + } +} +void List::print()const{ + for(Node* now=first;now;now=now->next)cout<date<<" "; + cout<<"\n"; +} +Node* List::find(const int& x)const{//寻找第一个值为x的数 未找到则返回0 + for(Node* p=first;p;p=p->next) + if(p->date==x)return p; + return 0; +} +int main(){ + int n; + cin>>n; + List a; + while(n--){ + int num; + cin>>num; + a.push_front(num); + } + a.print(); + List b; + b=a; + b.print(); + cout< + +using namespace std; +#define int long long +const int N=2e5+5; +const int MOD=1e6+3; +const int logn=21; +const double PI=3.1415926535897932384626433832795; +int ksm(int x,int b){ + int ans=1; + while(b){ + if(b&1)ans=ans*x%MOD; + x=x*x%MOD; + b>>=1; + } + return ans; +} +int exgcd(int a,int b,int& x,int& y){ + if(!b){x=1,y=0;return a;} + int ret=exgcd(b,a%b,y,x); + y-=a/b*x; + return ret; +} +int Inv(int a,int p){ + int d,x,y; + d=exgcd(a,p,x,y); + if(d==1)return (x%p+p)%p; + return -1; +} +int Cm(int n,int m,int p){ + int a=1,b=1; + if(m>n)return 0; + while(m){ + a=(a*n)%p; + b=(b*m)%p; + m--; + n--; + } + return a*Inv(b,p)%p; +} +int Lucas(int n,int m,int p){ + if(m==0)return 1; + return Cm(n%p,m%p,p)*Lucas(n/p,m/p,p)%p; +} +void solve(){ + int n,l,r,sum; + cin>>n>>l>>r; + int len=r-l+1; + //cout<>t; + while(t--) + solve(); +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/NTT.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/NTT.cpp new file mode 100644 index 0000000..c716506 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/NTT.cpp @@ -0,0 +1,67 @@ +#include +#define ll long long + +using namespace std; +const int N=3e6+5; +inline int ksm(int x,int k,int mod){ + int ans=1; + while(k){ + if(k&1)ans=1ll*ans*x%mod; + x=1ll*x*x%mod; + k>>=1; + } + return ans; +} +namespace Poly{ + const int MOD=998244353,G=3,INVG=332748118; + int lim,len,rev[N],invlim; + inline void init(int l1,int l2){ + lim=1,len=0; + while(lim<=l1+l2)lim<<=1,len++; + for(int i=0;i>1]>>1)|((i&1)<<(len-1)); + invlim=ksm(lim,MOD-2,MOD); + } + inline void NTT(vector &f,int type){ + for(int i=0;i mul(vector f,vector g){ + int lf=f.size(),lg=g.size(); + init(lf,lg); + f.resize(lim),g.resize(lim); + vector h(lim); + NTT(f,1);NTT(g,1); + for(int i=0;i>n>>m; + vector f(n+1),g(m+1); + for(int i=0;i<=n;i++)cin>>f[i]; + for(int i=0;i<=m;i++)cin>>g[i]; + vector h=Poly::mul(f,g); + for(int i=0;i<=n+m;i++)cout<>t; + while(t--){ + solve(); + } +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/PDSU.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/PDSU.cpp new file mode 100644 index 0000000..3ef1e58 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/PDSU.cpp @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +#define int long long +#define pii pair +using namespace std; +const int N=2e5+5; +const int M=1e5+5; +const int INF=2e9; +//const int p=998244353; +const int MOD=1e9+7; +const double DARW=0.97; +struct node{int l,r,x,h;}tr[N<<6]; +int head[N],tot,n,m; +void build(int& p,int l,int r){ + if(!p)p=++tot; + if(l==r){tr[p].x=l;return;} + int mid=(l+r)>>1; + build(tr[p].l,l,mid); + build(tr[p].r,mid+1,r); +} +void change(int p1,int& p2,int l,int r,int x,int f,int h){ + if(!p2)p2=++tot; + if(l==r){tr[p2].x=f,tr[p2].h=h;return;} + int mid=(l+r)>>1; + if(x<=mid)change(tr[p1].l,tr[p2].l,l,mid,x,f,h),tr[p2].r=tr[p1].r; + else change(tr[p1].r,tr[p2].r,mid+1,r,x,f,h),tr[p2].l=tr[p1].l; +} +pii find(int p,int l,int r,int x){ + if(l==r)return {tr[p].x,tr[p].h}; + int mid=(l+r)>>1; + if(x<=mid)return find(tr[p].l,l,mid,x); + else return find(tr[p].r,mid+1,r,x); +} +pii findfa(int p,int x){ + pii y=find(p,1,n,x); + if(x==y.first)return y; + return findfa(p,y.first); +} +void merge(int p1,int& p2,int x,int y){ + pii px=findfa(p1,x),py=findfa(p1,y); + if(px.second>py.second)change(p1,p2,1,n,py.first,px.first,py.second); + else if(px.second>n>>m; + build(head[0],1,n); + for(int i=1;i<=m;i++){ + int op; + cin>>op; + if(op==1){ + int x,y; + cin>>x>>y; + merge(head[i-1],head[i],x,y); + }else if(op==2){ + int k; + cin>>k; + head[i]=head[k]; + }else { + int x,y; + cin>>x>>y; + head[i]=head[i-1]; + if(findfa(head[i],x).first==findfa(head[i],y).first)cout<<"1\n"; + else cout<<"0\n"; + } + } +} +signed main(){ + ios::sync_with_stdio(false); + cin.tie(0); + cout.tie(0); + int t=1,k=1; + //cin>>t; + while(t--){ + solve(); + } +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/RandomIncremeMethod.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/RandomIncremeMethod.cpp new file mode 100644 index 0000000..4073a2b --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/RandomIncremeMethod.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +#define int long long +#define pii pair +using namespace std; +const int N=3e5+5; +const int M=5e6+5; +const int INF=1e9; +//const int p=998244353; +const int MOD=1e9+7; +const double DARW=0.97; +const double eps=1e-12; +int cmp(double x,double y){ + if(x-y>eps)return 1; + if(x-y>n; + for(int i=1;i<=n;i++)cin>>a[i].x>>a[i].y; + random_shuffle(a+1,a+n+1); + c.o=a[1],c.r=0; + for(int i=1;i<=n;i++){ + if(cmp(dist(a[i],c.o),c.r)==1){ + c.o=a[i],c.r=0; + for(int j=1;j<=i-1;j++){ + if(cmp(dist(c.o,a[j]),c.r)==1){ + c.o=getmid(a[i],a[j]); + c.r=dist(c.o,a[j]); + for(int u=1;u<=j-1;u++){ + if(cmp(dist(c.o,a[u]),c.r)==1){ + c=getc(a[i],a[j],a[u]); + } + } + } + } + } + } + cout<>t; + while(t--)solve(); +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Seg_treap.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Seg_treap.cpp new file mode 100644 index 0000000..0fb7621 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/Seg_treap.cpp @@ -0,0 +1,106 @@ +#include +#define int long long +const int N=2e5+5; +using namespace std; +struct Node{ + Node *ch[2]; + int val,prio; + int cnt; + int siz; + int to_rev=0; + Node(int val):val(val),cnt(1),siz(1){ + ch[0]=ch[1]=nullptr; + prio=rand(); + } + inline int upd_siz(){ + siz=cnt; + if(ch[0]!=nullptr)siz+=ch[0]->siz; + if(ch[1]!=nullptr)siz+=ch[1]->siz; + return siz; + } + inline void pushdown(){ + swap(ch[0],ch[1]); + if(ch[0]!=nullptr)ch[0]->to_rev^=1; + if(ch[1]!=nullptr)ch[1]->to_rev^=1; + to_rev=0; + } + inline void cheak_tag(){ + if(to_rev)pushdown(); + } +}; +struct Seg_treap{ +#define siz(_) (_==nullptr?0:_->siz) + Node* root; + pairsplit(Node* cur,int sz){ + if(cur==nullptr)return {nullptr,nullptr}; + cur->cheak_tag(); + if(sz<=siz(cur->ch[0])){ + auto temp=split(cur->ch[0],sz); + cur->ch[0]=temp.second; + cur->upd_siz(); + return {temp.first,cur}; + }else{ + auto temp=split(cur->ch[1],sz-siz(cur->ch[0])-1); + cur->ch[1]=temp.first; + cur->upd_siz(); + return {cur,temp.second}; + } + } + Node* merge(Node* sm,Node* bg){ + if(sm==nullptr&&bg==nullptr)return nullptr; + if(sm!=nullptr&&bg==nullptr)return sm; + if(sm==nullptr&&bg!=nullptr)return bg; + sm->cheak_tag(),bg->cheak_tag(); + if(sm->prioprio){ + sm->ch[1]=merge(sm->ch[1],bg); + sm->upd_siz(); + return sm; + }else{ + bg->ch[0]=merge(sm,bg->ch[0]); + bg->upd_siz(); + return bg; + } + } + void insert(int val){ + auto temp=split(root,val); + auto l_tr=split(temp.first,val-1); + Node* new_node; + if(l_tr.second==nullptr)new_node=new Node(val); + Node* l_tr_combined=merge(l_tr.first,l_tr.second==nullptr?new_node:l_tr.second); + root=merge(l_tr_combined,temp.second); + } + void seg_rev(int l,int r){ + auto less=split(root,l-1); + auto more=split(less.second,r-l+1); + more.first->to_rev=1; + root=merge(less.first,merge(more.first,more.second)); + } + void print(Node* cur){ + if(cur==nullptr)return; + cur->cheak_tag(); + print(cur->ch[0]); + cout<val<<" "; + print(cur->ch[1]); + } +}; +Seg_treap tr; +void solve(){ + srand(time(0)); + int n,m; + cin>>n>>m; + for(int i=1;i<=n;i++)tr.insert(i); + while(m--){ + int l,r; + cin>>l>>r; + tr.seg_rev(l,r); + } + tr.print(tr.root); +} +signed main(){ + ios::sync_with_stdio(false); + cin.tie(0); + cout.tie(0); + int t=1,k=1; + //cin>>t; + while(t--)solve(); +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/TCS.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/TCS.cpp new file mode 100644 index 0000000..1679663 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/TCS.cpp @@ -0,0 +1,138 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +#define int long long +#define pii pair +using namespace std; +const int N=1e5+5; +const int M=1e5+5; +const int INF=2e9; +//const int p=998244353; +const int MOD=1e9+7; +const double DARW=0.97; +int n,m,r,p,dfn; +int a[N],tr[N<<2],f[N],son[N],sz[N],idx[N],rnk[N],top[N],bj[N<<2],dep[N]; +vectore[N]; +void dfs1(int x,int fa){ + f[x]=fa; + sz[x]=1; + dep[x]=dep[fa]+1; + for(auto u:e[x]){ + if(u==fa)continue; + dfs1(u,x); + sz[x]+=sz[u]; + if(sz[u]>sz[son[x]])son[x]=u; + } +} +void dfs2(int x,int fa){ + idx[x]=++dfn; + rnk[dfn]=x; + top[x]=fa; + if(!son[x])return; + dfs2(son[x],fa); + for(auto u:e[x]){ + if(!idx[u])dfs2(u,u); + } +} +void pushdown(int l,int r,int bh){ + if(l==r)return; + int mid=(l+r)>>1; + (tr[bh<<1]+=(mid-l+1)*bj[bh])%=p; + (tr[(bh<<1)|1]+=(r-mid)*bj[bh])%=p; + (bj[bh<<1]+=bj[bh])%=p; + (bj[(bh<<1)|1]+=bj[bh])%=p; + bj[bh]=0; +} +void build(int l,int r,int bh){ + if(l==r){tr[bh]=a[rnk[l]]%p;return;} + int mid=(l+r)>>1; + build(l,mid,bh<<1); + build(mid+1,r,(bh<<1)|1); + tr[bh]=(tr[bh<<1]+tr[(bh<<1)|1])%p; +} +void add(int l,int r,int x,int y,int bh,int k){ + if(x<=l&&y>=r){(tr[bh]+=(r-l+1)*k)%=p,(bj[bh]+=k)%=p;return;} + pushdown(l,r,bh); + int mid=(l+r)>>1; + if(x<=mid)add(l,mid,x,y,bh<<1,k); + if(y>mid)add(mid+1,r,x,y,(bh<<1)|1,k); + tr[bh]=(tr[bh<<1]+tr[(bh<<1)|1])%p; +} +int find(int l,int r,int x,int y,int bh){ + if(x<=l&&y>=r)return tr[bh]; + pushdown(l,r,bh); + int mid=(l+r)>>1,ans=0; + if(x<=mid)(ans+=find(l,mid,x,y,bh<<1))%=p; + if(y>mid)(ans+=find(mid+1,r,x,y,(bh<<1)|1))%=p; + return ans; +} +void add(int x,int y,int z){ + while(top[x]!=top[y]){ + if(dep[top[x]]dep[y])swap(x,y); + add(1,n,idx[x],idx[y],1,z); +} +int find(int x,int y){ + int ans=0; + while(top[x]!=top[y]){ + if(dep[top[x]]dep[y])swap(x,y); + (ans+=find(1,n,idx[x],idx[y],1))%=p; + return ans; +} +void solve(){ + cin>>n>>m>>r>>p; + for(int i=1;i<=n;i++)cin>>a[i]; + for(int i=1,u,v;i>u>>v,e[u].push_back(v),e[v].push_back(u); + dfs1(r,0); + dfs2(r,r); + build(1,n,1); + for(int i=1;i<=m;i++){ + int op; + cin>>op; + if(op==1){ + int x,y,z; + cin>>x>>y>>z; + add(x,y,z); + }else if(op==2){ + int x,y; + cin>>x>>y; + cout<>x>>z; + add(1,n,idx[x],idx[x]+sz[x]-1,1,z); + }else { + int x; + cin>>x; + cout<>t; + while(t--){ + solve(); + } +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/VirtualTree.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/VirtualTree.cpp new file mode 100644 index 0000000..7ca6cf5 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/VirtualTree.cpp @@ -0,0 +1,116 @@ +#include +#define int long long +#define pii pair +using namespace std; +const int N=5e5+5; +int n,tot,idx[N],rth[N],d[N],f[N][100],lg[N],w[N][100]; +vectore[N]; +vectora; +mapmp; +bool cmp(int x,int y){return idx[x]s; + s.push_back(1); + e[1].clear(); + for(auto x:a){ + if(x==1)continue; + //cout<>n;d[1]=1; + for(int i=1,u,v,w;i>u>>v>>w; + e[u].push_back({v,w}); + e[v].push_back({u,w}); + } + table_log(); + dfs0(1,0); + int q; + cin>>q; + while(q--){ + int k; + cin>>k; + a.clear();mp.clear(); + for(int i=1,z;i<=k;i++)cin>>z,a.push_back(z),mp[z]=1; + sort(a.begin(),a.end(),cmp); + //for(auto u:a)cout<>t; + while(t--)solve(); +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/a.out b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/a.out new file mode 100644 index 0000000..9ec7550 Binary files /dev/null and b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/a.out differ diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/bsgs.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/bsgs.cpp new file mode 100644 index 0000000..af8aea6 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/bsgs.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#define ll long long +using namespace std; +ll bsgs(ll a,ll b,ll p){ + mapmp; + ll cur=1,t=sqrt(p)+1,now; + for(int B=0;B<=t;B++){ + mp[b*cur%p]=B; + now=cur; + cur=cur*a%p; + } + cur=now; + for(int A=1;A<=t;A++){ + if(mp[now])return (ll)A*t-mp[now]; + now=now*cur%p; + } + return -1; +} +int main(){ + ll p,b,n; + cin>>p>>b>>n; + ll ans=bsgs(b,n,p); + if(ans==-1)cout<<"no solution\n"; + else cout< +#define int long long +using namespace std; +const int N=2e5+5; +vectore[N]; +int n,tot; +int a[N],cnt[N],sz[N],son[N],idx[N],r[N],rth[N],num[N],ans[N]; +multisets; +void dfs1(int x,int fa){ + sz[x]=1; + idx[x]=++tot; + rth[tot]=x; + for(auto u:e[x]){ + if(u==fa)continue; + dfs1(u,x); + if(!son[x]||sz[son[x]]>n; + for(int i=1;i<=n;i++)cin>>a[i]; + for(int i=1,u,v;i>u>>v,e[u].push_back(v),e[v].push_back(u); + dfs1(1,0); + dfs2(1,0,0); + for(int i=1;i<=n;i++)cout<>t; + while(t--)solve(); +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/lucas..cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/lucas..cpp new file mode 100644 index 0000000..5132494 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/lucas..cpp @@ -0,0 +1,36 @@ +#include +#define ll long long +using namespace std; +ll ini[100005]; +ll apow(ll a,ll b,ll p){ + ll ans=1;a%=p; + while(b){ + if(b&1)ans=ans*a%p; + a=a*a%p; + b>>=1; + } + return ans; +} +ll C(ll n,ll m,ll p){ + if(n>t; + while(t--){ + int n,m,p; + cin>>n>>m>>p; + table(p); + cout< +#define int long long +const int N=1e5+5; +using namespace std; + +struct Node{ + Node *ch[2]; + int val,prio; + int cnt; + int siz; + Node(int val):val(val),cnt(1),siz(1){ + ch[0]=ch[1]=nullptr; + prio=rand(); + } + Node(Node *node){ + val=node->val,prio=node->prio,cnt=node->cnt,siz=node->siz; + } + inline void upd_siz(){ + siz=cnt; + if(ch[0]!=nullptr)siz+=ch[0]->siz; + if(ch[1]!=nullptr)siz+=ch[1]->siz; + } +}; +struct none_rot_treap{ +#define _3 second.second +#define _2 second.first + Node* root; + pair split(Node* cur,int key){ + if(cur==nullptr)return {nullptr,nullptr}; + if(cur->val<=key){ + auto temp=split(cur->ch[1],key); + cur->ch[1]=temp.first; + cur->upd_siz(); + return {cur,temp.second}; + }else{ + auto temp=split(cur->ch[0],key); + cur->ch[0]=temp.second; + cur->upd_siz(); + return {temp.first,cur}; + } + } + tuplesplit_by_rk(Node* cur,int rk){ + if(cur==nullptr)return {nullptr,nullptr,nullptr}; + int ls_siz=cur->ch[0]==nullptr?0:cur->ch[0]->siz; + if(rk<=ls_siz){ + Node *l,*mid,*r; + tie(l,mid,r)=split_by_rk(cur->ch[0],rk); + cur->ch[0]=r; + cur->upd_siz(); + return {l,mid,cur}; + }else if(rk<=ls_siz+cur->cnt){ + Node *lt=cur->ch[0]; + Node *rt=cur->ch[1]; + cur->ch[0]=cur->ch[1]=nullptr; + return {lt,cur,rt}; + }else{ + Node *l,*mid,*r; + tie(l,mid,r)=split_by_rk(cur->ch[1],rk-ls_siz-cur->cnt); + cur->ch[1]=l; + cur->upd_siz(); + return {cur,mid,r}; + } + } + Node* merge(Node* u,Node* v){ + if(u==nullptr&&v==nullptr)return nullptr; + if(u!=nullptr&&v==nullptr)return u; + if(v!=nullptr&&u==nullptr)return v; + if(u->prioprio){ + u->ch[1]=merge(u->ch[1],v); + u->upd_siz(); + return u; + }else{ + v->ch[0]=merge(u,v->ch[0]); + v->upd_siz(); + return v; + } + } + void insert(int val){ + auto temp=split(root,val); + auto l_tr=split(temp.first,val-1); + Node *new_node; + if(l_tr.second==nullptr){ + new_node=new Node(val); + }else{ + l_tr.second->cnt++; + l_tr.second->upd_siz(); + } + Node *l_tr_combined=merge(l_tr.first,l_tr.second==nullptr?new_node:l_tr.second); + root=merge(l_tr_combined,temp.second); + } + void del(int val){ + auto temp=split(root,val); + auto l_tr=split(temp.first,val-1); + if(l_tr.second->cnt>1){ + l_tr.second->cnt--; + l_tr.second->upd_siz(); + l_tr.first=merge(l_tr.first,l_tr.second); + }else{ + if(temp.first==l_tr.second){ + temp.first=nullptr; + } + delete l_tr.second; + l_tr.second=nullptr; + } + root=merge(l_tr.first,temp.second); + } + int qrank_by_val(Node *cur,int val){ + auto temp=split(cur,val-1); + int ret=(temp.first==nullptr?0:temp.first->siz)+1; + root=merge(temp.first,temp.second); + return ret; + } + int qval_by_rank(Node *cur,int rk){ + Node *l,*mid,*r; + tie(l,mid,r)=split_by_rk(cur,rk); + int ret=mid->val; + root=merge(merge(l,mid),r); + return ret; + } + int qprev(int val){ + auto temp=split(root,val-1); + int ret=qval_by_rank(temp.first,temp.first->siz); + root=merge(temp.first,temp.second); + return ret; + } + int qnex(int val){ + auto temp=split(root,val); + int ret=qval_by_rank(temp.second,1); + root=merge(temp.first,temp.second); + return ret; + } +}; +none_rot_treap tr; +int a[N]; +void solve(){ + srand(time(0)); + int n,m,ans=0; + cin>>n>>m; + for(int i=1;i<=n;i++)cin>>a[i],tr.insert(a[i]); + int lst=0; + while(m--){ + int op,x; + cin>>op>>x; + x^=lst; + if(op==1)tr.insert(x); + else if(op==2)tr.del(x); + else if(op==3)ans^=(lst=tr.qrank_by_val(tr.root,x)); + else if(op==4)ans^=(lst=tr.qval_by_rank(tr.root,x)); + else if(op==5)ans^=(lst=tr.qprev(x)); + else ans^=(lst=tr.qnex(x)); + } + cout<>t; + while(t--){ + solve(); + } +} \ No newline at end of file diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/sam.png b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/sam.png new file mode 100644 index 0000000..80280b0 Binary files /dev/null and b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/sam.png differ diff --git a/template-LaTeX-ECNU-F0RE1GNERS-main/assets/splay.cpp b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/splay.cpp new file mode 100644 index 0000000..44bdf02 --- /dev/null +++ b/template-LaTeX-ECNU-F0RE1GNERS-main/assets/splay.cpp @@ -0,0 +1,174 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +const int N=1e5+5; +using namespace std; +int root,tot; +struct splay{ + int ch[2],fa,val,cnt,size; +}a[N]; +void maintain(int x){ + a[x].size=a[a[x].ch[0]].size+a[a[x].ch[1]].size+a[x].cnt; +} +bool get(int x){ + return a[a[x].fa].ch[1]==x; +} +void clear(int x){ + a[x].ch[0]=a[x].ch[1]=a[x].fa=a[x].val=a[x].cnt=a[x].size=0; +} +void rotate(int x){ + int y=a[x].fa,z=a[y].fa,chk=get(x); + a[y].ch[chk]=a[x].ch[chk^1]; + if(a[x].ch[chk^1])a[a[x].ch[chk^1]].fa=y; + a[y].fa=x; + a[x].ch[chk^1]=y; + a[x].fa=z; + if(z)a[z].ch[y==a[z].ch[1]]=x; + maintain(y); + maintain(x); +} +void splay(int x){ + for(int f=a[x].fa;f=a[x].fa,f;rotate(x)){ + if(a[f].fa)rotate(get(x)==get(f)?f:x); + } + root=x; +} +void insert(int k){ + if(!root){ + a[++tot].val=k; + a[tot].cnt++; + root=tot; + maintain(root); + return; + } + int cur=root,f=0; + while(1){ + if(a[cur].val==k){ + a[cur].cnt++; + maintain(cur); + maintain(f); + splay(cur); + return; + } + f=cur; + cur=a[f].ch[a[f].val1){ + a[root].cnt--; + maintain(root); + return; + } + if(!a[root].ch[0]&&!a[root].ch[1]){ + clear(root); + root=0; + return; + } + if(!a[root].ch[0]){ + int cur=root; + root=a[root].ch[1]; + a[root].fa=0; + clear(cur); + return; + } + if(!a[root].ch[1]){ + int cur=root; + root=a[root].ch[0]; + a[root].fa=0; + clear(cur); + return; + } + int cur=root; + int x=pre(); + a[a[cur].ch[1]].fa=root; + a[root].ch[1]=a[cur].ch[1]; + clear(cur); + maintain(root); +} +int main(){ + int n; + cin>>n; + for(int i=1;i<=n;i++){ + int x,k; + cin>>x>>k; + if(x==1){ + insert(k); + }else if(x==2){ + del(k); + }else if(x==3){ + cout< +#include +#include +using namespace std; +const int N=1e5+5; +int a[N],f[N][25]; +inline int read() +{ + int x=0,f=1;char ch=getchar(); + while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} + while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();} + return x*f; +} +void st(int n){ + for(int u=1;u<=n;u++)f[u][0]=a[u]; + for(int i=1;(1<>n>>m; + for(int i=1;i<=n;i++)a[i]=read(); + st(n); + while(m--){ + int l,r; + l=read(); + r=read(); + int k=log2(r-l+1); + cout<