914D Bash and a Tough Math Puzzle

Source: Internet
Author: User

Transmission Door

Analysis

Using the segment tree to maintain the interval GCD, each query finds the first point that is not a multiple of x, and if there is an interval that gcd cannot be divisible by x, the interval is illegal.

Code

#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<cctype>#include<cmath>#include<cstdlib>#include<queue>#include<ctime>#include<vector>#include<Set>#include<map>#include<stack>using namespacestd;intd[2000100],cnt,a[500100];inlineintgcdintXintY) {returny==0? X:GCD (y,x%y);} InlinevoidBuildintLeintRiintwh) {      if(le==RI) {D[WH]=A[le]; return; }      intMid= (Le+ri) >>1; Build (Le,mid,wh<<1); Build (Mid+1,ri,wh<<1|1); D[WH]=GCD (d[wh<<1],d[wh<<1|1]); return;} InlinevoidUpdateintLeintRiintWhintPlintk) {      if(le==RI) {D[WH]=K; return; }      intMid= (Le+ri) >>1; if(MID&GT;=PL) Update (le,mid,wh<<1, pl,k); ElseUpdate (mid+1,ri,wh<<1|1, pl,k); D[WH]=GCD (d[wh<<1],d[wh<<1|1]); return; } InlinevoidQintLeintRiintWhintXintYintk) {      if(le>=x&&ri<=y) {          if(d[wh]%k==0)return; if(cnt>=1) {CNT++; return; }      }      if(le==RI) {CNT++; return; }      intMid= (Le+ri) >>1; if(mid>=x) Q (le,mid,wh<<1, x,y,k); if(mid<y) Q (mid+1,ri,wh<<1|1, x,y,k); return;}intMain () {intn,m,i,j,k,x,y,z; scanf ("%d",&N);  for(i=1; i<=n;i++) scanf ("%d\n",&A[i]); Build (1N1); scanf ("%d",&m);  for(i=1; i<=m;i++) {scanf ("%d",&k); if(k==1) {scanf ("%d%d%d",&x,&y,&z); CNT=0; Q (1N1, x, Y, z); if(cnt>1) puts ("NO"); ElsePuts"YES"); }Else{scanf ("%d%d",&x,&y); Update (1N1, x, y); }      }      return 0;}

914D Bash and a Tough Math Puzzle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.