Title: http://www.lydsy.com/JudgeOnline/problem.php?id=3853
The puzzle: We find that direct modification is certainly not possible. Because it is possible to modify a lot at once. And the number is not continuous.
Handling:
{
Notice that the number plus V for all gcd (x,n) ==d is equivalent to giving each number plus [GCD (x,n) ==d]*v, which we can find:
[GCD (x,n) ==d]*v =
[GCD (X/D,N/D) ==1] *v=>
Sigma (Mu[q] * v) (q | n/d && Q | x/d)
+ Sigma (Mu[q] * v) (q | n/d && q*d | x)
Where Mu is the Möbius function
We can construct an array F, let a[i] = = Sigma (F[j]) (j | i), and then modify the operation to become: to all satisfy the condition of Q, let F[q*d] plus mu[q] * V, then according to the nature of the F array, we each a[i] can be smoothly added [GCD (x,n) It's ==d]*v.
}
In fact, this is quite the same as we pushed the changes and queries forward, pushed to a common section, and then found that this part of the maintenance time required within the allowable range. So ...
The thought of this question also needs to comprehend ...
Code:
1#include <cstdio>2 3#include <cstdlib>4 5#include <cmath>6 7#include <cstring>8 9#include <algorithm>Ten One#include <iostream> A -#include <vector> - the#include <map> - -#include <Set> - +#include <queue> - +#include <string> A at #defineINF 1000000000 - - #defineMAXN 200000 - - #defineMAXM 200000+5 - in #defineEPS 1e-10 - to #definell Long Long + - #definePA pair<int,int> the * #defineFor0 (i,n) for (int i=0;i<= (n); i++) $ Panax Notoginseng #defineFor1 (i,n) for (int i=1;i<= (n); i++) - the #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + A #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) the + #defineFor4 (i,x) for (int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) - $ #defineFor5 (N,M) for (int. i=1;i<=n;i++) for (int j=1;j<=m;j++) $ - #defineMoD 1000000007 - the using namespacestd; - WuyiInlineintRead () the - { Wu - intx=0, f=1;CharCh=GetChar (); About $ while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - - while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} - A returnx*F; + the } - intn,m,mu[maxn+1],p[maxn],tot; $ ll S[MAXN]; the BOOLv[maxn+1]; thevector<int>fac[maxn+1]; theInlinevoidAddintXinty) the { - for(;x<=n;x+=x& (-X)) s[x]+=y; in } theinline ll sum (intx) the { Aboutll t=0; the for(;x;x-=x& (-X)) t+=S[x]; the returnT; the } +Inlinevoid Get() - { themu[1]=1;BayiFor2 (I,2, MAXN) the { the if(!v[i]) p[++tot]=i,mu[i]=-1; - For1 (J,tot) - { the intk=i*P[j]; the if(K>MAXN) Break; thev[k]=1; the if(I%p[j]) mu[k]=-Mu[i]; - Else{mu[k]=0; Break;} the } the //cout<<i<< ' <<mu[i]<<endl; the }94 For1 (I,MAXN) the for(intj=i;j<=maxn;j+=i) the Fac[j].push_back (i); the }98 About intMain () - 101 {102 103Freopen ("Input.txt","R", stdin);104 theFreopen ("output.txt","W", stdout);106 Get();107 108 For1 (Cs,inf)109 { theN=read (); m=read ();111 if(!n&&!m) Break; theprintf"Case #%d:\n", CS);113memset (s),0,sizeof(s)); the while(m--) the { the intop=read ();117 if(op==1)118 {119 intX=read (), Y=read (), z=read (); - if(x%y)Continue;121X/=y;122For3 (I,fac[x].size ()-1,0) Add (fac[x][i]*y,mu[fac[x][i]]*z);123}Else124 { the intT=read (); ll ans=0;126 for(intI=1, j;i<=t;i=j+1)127 { -j=t/(t/i);129ans+= (LL) t/i* (sum (j)-sum (I-1)); the }131printf"%lld\n", ans); the }133 }134 }135 136 return 0;137 138}
View Code
BZOJ3853:GCD Array