"Line Tree" "Bzoj 3211" flower Gods travel around the world

Source: Internet
Author: User

3211: The flower God travels the country
Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 1508  Solved: 573

Description

Input

Output

Each time x=1, an integer per line indicates the pleasure of this trip

Sample Input

41 100 5 551 1 22 1 21 1 22 2 31 1 4

Sample Output

1011111

HINT

For 100% data, n≤100000,m≤200000, Data[i] is non-negative and less than 10^9

Source

SPOJ2713 GSS4 data has been enhanced

Exercises

The interval open square root obviously can not mark, but for a number, several times after open roots will become 1, so we can mark whether the interval is 1, change the violence can be, because if one interval has become 1, then the next time will not access it, so the complexity is not a problem.

Code:

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <algorithm>usingnamespace Std;#define N 100100#Define LL long long#Define root 1,1,n#define LCH Rt<<1,l,mid#define rch rt<<1|1,mid+1,rstructtree{LL S;BOOLF;} tree[n<<2];intN,m;int inch(){intx=0;CharCh=getchar (); while(ch<' 0 '|| Ch>' 9 ') Ch=getchar (); while(ch>=' 0 '&& ch<=' 9 ') x=x*Ten+ch-' 0 ', Ch=getchar ();returnx;}voidPUSH_UP (intRT) {if(tree[rt<<1].F | | tree[rt<<1|1].F) tree[rt].f=1;Elsetree[rt].f=0; tree[rt].s=tree[rt<<1].s+tree[rt<<1|1].S;}voidPush_down (intRtintLintR) {if(!TREE[RT].F)return;if(L==R) {tree[rt].s=sqrt (TREE[RT].S);if(tree[rt].s<=1) tree[rt].f=0;return; }intMid= (l+r) >>1; Push_down (LCH);    Push_down (RCH); PUSH_UP (RT);}voidBuildintRtintLintR) {if(L==R) {tree[rt].s= (LL)inch();if(tree[rt].s<=1) tree[rt].f=0;Elsetree[rt].f=1;return; }intMid= (l+r) >>1; Build (LCH);    Build (RCH); PUSH_UP (RT);}voidChangeintRtintLintRintllintRR) {if(!TREE[RT].F)return;if(Ll<=l && R&LT;=RR) {Push_down (rt,l,r);return; }intMid= (l+r) >>1;if(ll<=mid) Change (LCH,LL,RR);if(rr>mid) Change (RCH,LL,RR); PUSH_UP (RT);} LL Query (intRtintLintRintllintRR) {if(Ll<=l && R&LT;=RR)returnTREE[RT].S;intMid= (l+r) >>1; LL k=0;if(Ll<=mid) K+=query (LCH,LL,RR);if(Rr>mid) K+=query (RCH,LL,RR);returnK;}intMain () {n=inch(); Build (root); m=inch(); while(m--) {intopt=inch(), x=inch(), y=inch();if(opt==1) printf ("%lld\n", query (root,x,y));ElseChange (root,x,y); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Line Tree" "Bzoj 3211" flower Gods travel around the world

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.