LCT
int c[N][2],st[N],size[N],fa[N],rev[N],next[N]; bool isroot(int x){ return c[fa[x]][0]!=x&&c[fa[x]][1]!=x; } void pushup(int x){ size[x]=size[c[x][0]]+size[c[x][1]]+1; } void pushdown(int x){ int l=c[x][0],r=c[x][1]; if(rev[x]){ rev[x]^=1;rev[l]^=1;rev[r]^=1; swap(c[x][0],c[x][1]); } } void ratate(int x){ int y=fa[x],z=fa[y],l,r; l=(c[y][0]==x?0:1);r=l^1; if(!isroot(y)){ c[z][0]==y?c[z][0]=x:c[z][1]=x; } fa[x]=z;fa[y]=x;fa[c[x][r]]=y; c[y][l]=c[x][r];c[x][r]=y; pushup(y),pushup(x); } void spaly(int x){ int top=1;st[top]=x; for(int i=x;!isroot(i);i=fa[i])st[++top]=fa[i]; for(int i=top;i;i--)pushdown(st[i]); while(!isroot(x)){ int y=fa[x],z=fa[y]; if(!isroot(y)){ if(c[z][0]==y^c[y][0]==x)ratate(x); else ratate(y); } ratate(x); } } void access(int x){ if(x==0)return; for(int t=0;x;x=fa[x]){ spaly(x);c[x][1]=t;t=x; } } void rever(int x){ access(x);spaly(x);rev[x]^=1; } void link(int x,int y){ rever(x);fa[x]=y;spaly(y); } void cut(int x,int y){ rever(x);access(y);spaly(y);c[y][0]=fa[x]=0; }链剖
void dfs(int now,int dep){ deep[now]=dep;size[now]=1; for(int u=first[now];u;u=edge[u].next){ if(!deep[edge[u].to]){ dfs(edge[u].to,dep+1); size[now]+=size[edge[u].to]; fa[edge[u].to]=now; } } } void dfs2(int now,bool lim){ if(lim)top[now]=top[fa[now]]; else top[now]=now;int p=0,q=0; sub[now]=++tot;modify(1,n,1,sub[now],sub[now],a[now]); for(int u=first[now];u;u=edge[u].next){ if(edge[u].to==fa[now])continue; if(size[edge[u].to]>p)p=size[edge[u].to],q=edge[u].to; } if(q)dfs2(q,1); for(int u=first[now];u;u=edge[u].next){ if(edge[u].to==fa[now]||edge[u].to==q)continue; dfs2(edge[u].to,0); } } int query(int l,int r){ while(top[l]!=top[r]){ if(deep[top[l]]>deep[top[r]]){ } else{ } } if(deep[l]>deep[r]){ } else{ } return ret; }
#define inf 1000000000 #define o(e) ((((e)-1)^1)+1) struct Edge{ int to,next,flow; }edge[100010]; int first[1700],size; int dl[1700],deep[1700]; void addedge(int x,int y,int z){ size++; edge[size].to=y; edge[size].flow=z; edge[size].next=first[x]; first[x]=size; } int dfs(int now,int aim,int flow){ if(now==aim)return flow; int F=0; for(int u=first[now];u&&flow;u=edge[u].next){ if(deep[edge[u].to]==deep[now]+1&&edge[u].flow){ int ret=dfs(edge[u].to,aim,min(flow,edge[u].flow)); F+=ret;flow-=ret;edge[u].flow-=ret,edge[o(u)].flow+=ret; } } if(!F)deep[now]=-1; return F; } bool bfs(int sta,int end){ int head=0,tail=1; memset(deep,0,sizeof deep); dl[1]=sta;deep[sta]=1; while(head!=tail){ int v=dl[++head]; for(int u=first[v];u;u=edge[u].next){ if(!deep[edge[u].to]&&edge[u].flow>0){ deep[edge[u].to]=deep[v]+1; dl[++tail]=edge[u].to; } } } return deep[end]; } int maxflow(int sta,int end){ int ret=0; while(bfs(sta,end)){ ret+=dfs(sta,end,inf); } return ret; }
#include<ext/pb_ds/priority_queue.hpp> #include<ext/pb_ds/tree_policy.hpp> #include<ext/pb_ds/assoc_container.hpp> typedef __gnu_pbds::tree<int,int,std::less<int>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update> mytree; mytree t;
#include<set> #include<map> #include<ctime> #include<queue> #include<cmath> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define N 131072 #define pi acos(-1) #define ll long long using namespace std; struct E{ double imag,real;E(double _r=0,double _i=0){real=_r,imag=_i;} friend E operator+(E a,E b){return E(a.real+b.real,a.imag+b.imag);} friend E operator-(E a,E b){return E(a.real-b.real,a.imag-b.imag);} friend E operator*(E a,E b){return E(a.real*b.real-a.imag*b.imag,a.real*b.imag+b.real*a.imag);} }; int n,m,L; char ch[N]; int R[N],c[N]; E a[N],b[N]; void fft(E *a,int f) for(int i=0;i<n;i++)if(i<R[i])swap(a[i],a[R[i]]); for(int i=1;i<n;i<<=1) { E wn(cos(pi/i),f*sin(pi/i)); for(int j=0;j<n;j+=(i<<1)) { E w(1,0); for(int k=0;k<i;k++,w=w*wn) { E x=a[j+k],y=w*a[j+k+i]; a[j+k]=x+y;a[j+k+i]=x-y; } } } if(f==-1)for(int i=0;i<n;i++)a[i].real=a[i].real/n; } int main() { scanf("%d",&n);n--; scanf("%s",ch); for(int i=0;i<=n;i++)a[i]=ch[n-i]-'0'; scanf("%s",ch); for(int i=0;i<=n;i++)b[i]=ch[n-i]-'0'; m=2*n;for(n=1;n<=m;n<<=1)L++; for(int i=0;i<n;i++)R[i]=(R[i>>1]>>1)|((i&1)<<(L-1)); fft(a,1);fft(b,1); for(int i=0;i<=n;i++)a[i]=a[i]*b[i]; fft(a,-1); for(int i=0;i<=m;i++)c[i]=(int)(a[i].real+0.1); for(int i=0;i<=m;i++) if(c[i]>=10) { c[i+1]+=c[i]/10,c[i]%=10; if(i==m)m++; } for(int i=m;i>=0;i--)printf("%d",c[i]); return 0; }
#include<limits> using namespace std; const int MAXD = 300, DIG = 9, BASE = 1000000000; const unsigned long long BOUND = numeric_limits <unsigned long long> :: max () - (unsigned long long) BASE * BASE; class bignum{private:int digits[MAXD];int D; public:friend ostream &operator<<(ostream &out,bignum &c); inline void trim(){while(D>1&&digits[D-1]==0)D--;} inline void dealint(long long x){memset(digits,0,sizeof(digits));D=0;do{digits[D++]=x%BASE;x/=BASE;}while(x>0); } inline void dealstr(char *s){memset(digits,0,sizeof(digits));int len=strlen(s),first=(len+DIG-1)%DIG+1;D=(len+DIG-1)/DIG;for(int i=0;i<first;i++)digits[D-1]=digits[D-1]*10+s[i]-'0';for(int i=first,d=D-2;i<len;i+=DIG,d--)for(int j=i;j<i+DIG;j++)digits[d]=digits[d]*10+s[j]-'0';trim();} inline char *print(){trim();char *cdigits=new char[DIG*D+1];int pos=0,d=digits[D-1];do{cdigits[pos++]=d%10+'0';d/=10;}while(d > 0);reverse(cdigits,cdigits+pos);for(int i=D-2;i>=0;i--,pos += DIG) for(int j=DIG-1,t=digits[i];j>= 0;j--){cdigits[pos+j]=t%10+'0';t/=10;}cdigits[pos]='\0';return cdigits;} bignum(){dealint(0);} bignum(long long x){dealint(x);} bignum(int x){dealint(x);} bignum(char *s){dealstr(s);} inline bool operator < (const bignum &o) const{if(D != o.D)return D < o.D;for(int i = D-1; i>=0; i--)if(digits[i] != o.digits[i])return digits[i] < o.digits[i];return false;} bool operator > (const bignum & o)const{return o < *this;} bool operator <= (const bignum & o)const{return !(o < *this);} bool operator >= (const bignum & o)const{return !(*this < o);} bool operator != (const bignum & o)const{return o < *this || *this < o;} bool operator == (const bignum & o)const{return !(o < *this) && !(*this < o);} bignum &operator++(){*this = *this + 1;return *this;} bignum operator ++(int){bignum old = *this;++(*this);return old;} bignum &operator--(){*this = *this - 1;return *this;} bignum operator --(int){bignum old = *this;--(*this);return old;} inline bignum operator << (int p) const{bignum temp;temp.D=D+p;for(int i=0;i<D;i++)temp.digits [i + p] = digits [i];for (int i = 0; i < p; i++)temp.digits [i] = 0;return temp;} inline bignum operator >> (int p)const{bignum temp;temp.D=D-p;for(int i=0;i<D-p;i++)temp.digits[i]=digits[i+p];for(int i=D-p;i<D;i++)temp.digits[i]=0;return temp;} bignum &operator += (const bignum &b){ *this = *this + b; return *this;} bignum &operator -= (const bignum &b){ *this = *this - b; return *this; } bignum &operator *= (const bignum &b){ *this = *this * b; return *this; } bignum &operator /= (const bignum &b){ *this = *this / b; return *this; } bignum &operator %= (const bignum &b){ *this = *this % b; return *this; } inline bignum operator + (const bignum &o) const { bignum sum = o; int carry = 0; for (sum.D = 0; sum.D < D || carry > 0; sum.D++) { sum.digits [sum.D] += (sum.D < D ? digits [sum.D] : 0) + carry; if (sum.digits [sum.D] >= BASE) { sum.digits [sum.D] -= BASE; carry = 1; } else carry = 0; } sum.D = max (sum.D, o.D); sum.trim (); return sum; } inline bignum operator - (const bignum &o) const { bignum diff = *this; for (int i = 0, carry = 0; i < o.D || carry > 0; i++) { diff.digits [i] -= (i < o.D ? o.digits [i] : 0) + carry; if (diff.digits [i] < 0) { diff.digits [i] += BASE; carry = 1; } else carry = 0; } diff.trim (); return diff; } inline bignum operator * (const bignum &o) const { bignum prod = 0; unsigned long long sum = 0, carry = 0; for (prod.D = 0; prod.D < D + o.D - 1 || carry > 0; prod.D++) { sum = carry % BASE; carry /= BASE; for (int j = max (prod.D - o.D + 1, 0); j <= min (D - 1, prod.D); j++) { sum += (unsigned long long) digits [j] * o.digits [prod.D - j]; if (sum >= BOUND) { carry += sum / BASE; sum %= BASE;}}carry += sum / BASE;prod.digits [prod.D] = sum % BASE;}prod.trim ();return prod;} inline bignum range (int a, int b) const{ bignum temp = 0; temp.D = b - a; for (int i = 0; i < temp.D; i++) temp.digits [i] = digits [i + a]; return temp; } inline double double_div (const bignum &o) const { double val = 0, oval = 0; int num = 0, onum = 0; for (int i = D - 1; i >= max (D - 3, 0); i--, num++) val = val * BASE + digits [i]; for (int i = o.D - 1; i >= max (o.D - 3, 0); i--, onum++) oval = oval * BASE + o.digits [i]; return val / oval * (D - num > o.D - onum ? BASE : 1); } inline pair <bignum, bignum> divmod (const bignum &o) const { bignum quot = 0, rem = *this, temp; for (int i = D - o.D; i >= 0; i--) { temp = rem.range (i, rem.D); int div = (int) temp.double_div (o); bignum mult = o * div; while (div > 0 && temp < mult) { mult = mult - o; div--; } while (div + 1 < BASE && !(temp < mult + o)) { mult = mult + o; div++; } rem = rem - (o * div << i); if (div > 0) { quot.digits [i] = div; quot.D = max (quot.D, i + 1); } } quot.trim (); rem.trim (); return make_pair (quot, rem); } inline bignum operator / (const bignum &o) const { return divmod (o).first; } inline bignum operator % (const bignum &o) const { return divmod (o).second; } inline bignum power (int exp) const { bignum p = 1, temp = *this; while (exp > 0) { if (exp & 1) p = p * temp; if (exp > 1) temp = temp * temp; exp >>= 1; } return p; } inline bignum factorial() const { bignum ans = 1, num = *this; if (num == 0 || num == 1) return ans; while (!(num < 0 || num == 0)) { ans = ans * num; num = num - 1; } return ans; } }; ostream &operator<<(ostream &out, bignum &c) { out<<c.print(); return out; } istream &operator >> (istream &in,bignum &c) { char s[10000]; in>>s; c = s; return in; } bignum gcd(bignum a,bignum b) { return b==0?a:gcd(b,a%b); }