[CF914D] Bash and a Tough Math Puzzle

Source: Internet
Author: User
Tags gcd greatest common divisor

Given a series of $a_1,a_2,..., a_n$< Span class= "vlist-s" >< Span class= "Mord" > ? supports two actions

1 l r x, guessing the greatest common divisor $x$ of the number in the [l,r] position in the sequence, determines if the guess is close to correct. If we can change at most one number in the sequence [l,r] so that their greatest common divisor is x, then this speculation is considered to be close to correct (note that we do not need to make actual changes in the series). If the guess is close to correct, output "YES", otherwise output "no" (all without quotation marks).

2 I y, change the value of $a_i$ to Y.

If the interval has more than one number is not a multiple of $x$, according to this one directly written on the line, put gcd wrong really stupid cry

Code:

1#include <iostream>2#include <cstdio>3#include <cstring>4 #defineM 5000105 #defineLS node<<16 #defineRS Node<<1|17 using namespacestd;8 9 intn,q;Ten intval[m<<2],a[m]; One  A intgcdintXintY) {returny==0? X:GCD (y,x%y);} -  - voidUpdateintnode) the { -     if(!val[ls]| |! VAL[RS]) val[node]=val[ls]+Val[rs]; -     Elseval[node]=gcd (Val[ls],val[rs]); - } +  - voidBuildintNodeintLintR) + { A     if(L==R) {Val[node]=a[l];return;} at     intMid= (L+R)/2; -Build (Ls,l,mid); Build (rs,mid+1, R); - Update (node); - } -  - intQueryintNodeintLintRintL1,intR1,intx) in { -     if(l1<=l&&r1>=R) to     { +         if(val[node]%x==0)return 0; -         if(L==R)return(val[node]%x!=0); the     } *     if(l1>r| | R1&LT;L)return 0; $     intans=0;Panax Notoginseng     intMid= (L+R)/2; -ans+=query (ls,l,mid,l1,r1,x); the     if(ans>1)returnans; +     returnAns+query (rs,mid+1, r,l1,r1,x); A } the  + voidChangeintNodeintLintRintXintk) - { $     if(L==R) {val[node]=k;return;} $     intMid= (L+R)/2; -     if(x<=mid) Change (ls,l,mid,x,k); -     ElseChange (rs,mid+1, r,x,k); the Update (node); - }Wuyi  the intMain () - { Wuscanf"%d",&n); -      for(intI=1; i<=n;i++) scanf ("%d",&a[i]); AboutBuild1,1, n); $scanf"%d",&q); -      while(q--) -     { -         intopt; Ascanf"%d",&opt); +         if(opt==1) the         { -             intL,R,X;SCANF ("%d%d%d",&l,&r,&x); $printf (Query (1,1, n,l,r,x) >1?"no\n":"yes\n"); the         } the         Else the         { the             intX,k; scanf"%d%d",&x,&k); -Change1,1, n,x,k); in         } the     } the     return 0; About}

[CF914D] 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.