Title Address: Zju 3886
This problem needs to think of a point, because of a number x constant modulus, and set him less than the modulus will take the remainder of the operation, then at most only LOGX times, because each time the modulo will make x binary. And then it's good to think of it. For interval mode update operation can be directly violent update, maintain a maximum value, if the maximum value of this interval is less than the model, you do not have to continue to update the leaves. Then the other greater than the modulus is updated to the leaf node.
Then for Niconumber, only 6, 2 of the power and prime is in line. So it can be preprocessed. Then you can use the line tree to maintain it.
The code is as follows:
#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>#include <time.h>using namespace STD;#define LL Long Long#define PI ACOs ( -1.0)#pragma COMMENT (linker, "/stack:1024000000")#define Root 1, N, 1#define Lson L, Mid, rt<<1#define Rson mid+1, R, Rt<<1|1Const intMod=1e9+7;Const intinf=0x3f3f3f3f;Const Doubleeqs=1e-9;Const intmaxn=100000+Ten;BOOLisprime[maxn* -], ok[maxn* -];intprime[maxn*Ten];intmax[maxn<<2], sum[maxn<<2];voidInit () {inttot=0, I, J; ok[0]=ok[1]=1; ok[6]=1; for(i=2; i<=10000000; i++) {if(!isprime[i]) {prime[tot++]=i; ok[i]=true; } for(j=0; j<tot;j++) {if(i*prime[j]>10000000) Break; isprime[i*prime[j]]=true;if(i%prime[j]==0) Break; } }intx=2; while(x<=10000000) {ok[x]=true; x<<=1; }}voidPushup (intRT) {Max[rt]=max (max[rt<<1],max[rt<<1|1]); sum[rt]=sum[rt<<1]+sum[rt<<1|1];}voidBuild (intLintRintRT) {if(L==R) {scanf("%d", &max[rt]); SUM[RT]=OK[MAX[RT]];return; }intMid=l+r>>1; Build (Lson); Build (Rson); Pushup (RT);}voidUpdate1 (intPintXintLintRintRT) {if(L==R) {max[rt]=x; SUM[RT]=OK[X];return; }intMid=l+r>>1;if(P<=mid) Update1 (P,x,lson);ElseUpdate1 (P,x,rson); Pushup (RT);}voidUpdate2 (intllintRrintXintLintRintRT) {if(LL<=L&&RR>=R) {if(max[rt]<x)return; }if(L==R) {max[rt]%=x; SUM[RT]=OK[MAX[RT]];return; }intMid=l+r>>1;if(Ll<=mid) Update2 (Ll,rr,x,lson);if(Rr>mid) Update2 (Ll,rr,x,rson); Pushup (RT);}intQuery (intllintRrintLintRintRT) {if(LL<=L&&RR>=R) {returnSUM[RT]; }intMid=l+r>>1, ans=0;if(Ll<=mid) Ans+=query (Ll,rr,lson);if(Rr>mid) Ans+=query (Ll,rr,rson);returnAns;}intMain () {intN, I, J, L, R, p, V, q, x; Init (); while(scanf("%d", &n)!=eof) {memset(Max,0,sizeof(Max));memset(Sum,0,sizeof(sum)); Build (root);scanf("%d", &q); while(q--) {scanf("%d", &x);if(x==1){scanf("%d%d", &l,&r);printf("%d\n", Query (L,r,root)); }Else if(x==2){scanf("%d%d%d", &l,&r,&v); Update2 (L,r,v,root); }Else{scanf("%d%d", &p,&v); Update1 (P,v,root); } } }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
ZOJ 3886 Nico Number (segment tree)