"BZOJ3038", "Codevs2492", seven minutes of God-made questions 2

Source: Internet
Author: User

Double Experience
2492 God-made questions for seven minutes 2

Time limit: 1 s
Space limit: 64000 KB
Topic rank: Master Master

Title Description Description

Xlk that "God made the seven minutes of the problem" is not very enjoyable, so there is the second part.

"In the first minute, X says, to have a sequence, a positive integer sequence is given."
The second minute, L said, to be able to modify, so there is a number of each number in the square (the next rounding) operation.
The third minute, K said, to be able to query, so there is to seek a number of operations.
Four minutes, Rainbow Meow said, if Noip difficulty, so there is the data range.
Five minutes, the poet said, to have rhyme, so there is time limit and memory limit.
Six minutes, and the snow said, to save things, so there is a guarantee in the process and the final result does not exceed the 64-bit signed integer type of the range of the limit.
The first seven minutes, the problem was finally finished, however, the god of the cows do not want to write the problem of the program. ”
--seven minutes of God's problems • Part II
So this sacred mission is yours.
Enter a description input Description

The first line is an integer n, which represents the number of numbers in the sequence.
The second row n positive integers that represent the number in the initial state of the sequence.
The third line, an integer m, indicates that there is an M operation.
The next m line is three integers per line k,l,r,k=0 for each number in [l,r] squared (rounded down), and K=1 is asking for the sum of each number in [L,r].
UPD: Note that the data may be l>r, so in this case, swap L and R.
Outputs description Output Description

For the inquiry operation, each line outputs an answer.
Sample input to sample

10
1 2 3 4 5 6 7 8 9 10
5
0 1 10
1 1 10
1 1 5
0 5 8
1 4 8
Sample output Sample Outputs

19
7
6
Data Size & Hint

For 30% of data, 1 ≤ Nm ≤ 1000, the number in the series does not exceed 32767.
For 100% of data, 1 ≤ Nm ≤ 100000,1 ≤ L,r ≤ N, the number in the sequence is greater than 0, and no more than 1e12.
Note that L may be greater than r, and in this case please exchange l,r.

Source: Nescafe 20
It's exactly the same as a flower God travels around 233
Direct code (in fact, again this article I was to visit the volume and experience)

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#define MAXN 100100#define MAXM 201000#define Lchild Rt<<1,l,mid#define Rchild Rt<<1|1,mid+1,r#define LN rt<<1#define RN Rt<<1|1using namespace STD;structseg{intL,r;Long LongSUM,MAXN;} tree[maxn<<4];intN,m;intOp,l,r;voidPUSH_UP (intRT) {Tree[rt].sum=tree[ln].sum+tree[rn].sum; Tree[rt].maxn=max (TREE[LN].MAXN,TREE[RN].MAXN);}voidBuildintrt=1,intL=1,intR=n) {intMid= (l+r) >>1; Tree[rt].l=l;tree[rt].r=r;if(L==R) {scanf("%lld", &tree[rt].sum); Tree[rt].maxn=tree[rt].sum;return;    } build (Lchild); build (Rchild); PUSH_UP (RT);}voidModifyintRtintLintR) {if(tree[rt].maxn<=1)return;intL=tree[rt].l,r=tree[rt].r,mid= (l+r) >>1;if(L==R) {tree[rt].sum= Floor(sqrt(Tree[rt].sum)); Tree[rt].maxn=tree[rt].sum;return; }if(l<=mid) modify (LN,L,R);if(r>mid) modify (RN,L,R); PUSH_UP (RT);}Long LongQueryintRtintLintR) {intL=tree[rt].l,r=tree[rt].r,mid= (l+r) >>1;if(L==L&AMP;&AMP;R==R)returnTree[rt].sum;if(R<=mid)returnQuery (LN,L,R);Else    if(L>mid)returnQuery (RN,L,R);Else returnQuery (Ln,l,mid) +query (rn,mid+1, r);}intMain () {scanf("%d", &n); Build ();scanf("%d", &m); for(intI=1; i<=m;i++) {scanf("%d%d%d", &op,&l,&r);if(l>r) swap (L,R);if(op==1)printf("%lld\n", Query (1, l,r));ElseModify1, l,r); }}

"BZOJ3038", "Codevs2492", seven minutes of God-made questions 2

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.