HDU-4027-Can you answer these queries

Source: Internet
Author: User

HDU-4027-Can you answer these queries

Segment segments are updated. n is relatively small. It is updated to each leaf node. Note that after the root number is 1, it is still 1 and does not need to be updated.


[Cpp]
# Include <iostream>
# Include <cstring>
# Include <cstdlib>
# Include <cstdio>
# Include <cmath>
Using namespace std;
Typedef _ int64 LL;
# Define N 100010
Struct cam
{
Int x;
Int y;
LL sum;
} List [N * 5];
Void build (int k, int x, int y)
{
List [k]. x = x;
List [k]. y = y;
If (x = y)
{
Scanf ("% I64d", & list [k]. sum );
Return;
}
Int mid;
Mid = (x + y)/2;
Build (k <1, x, mid );
Build (k <1 | 1, mid + 1, y );
List [k]. sum = list [k <1]. sum + list [k <1 | 1]. sum;
}
Void update (int k, int x, int y)
{
If (list [k]. sum = list [k]. y-list [k]. x + 1) // The root number of 1 is not 1 and does not need to be updated.
Return;
If (list [k]. x = list [k]. y)
{
List [k]. sum = (LL) sqrt (double) list [k]. sum );
Return;
}
Int mid = (list [k]. x + list [k]. y)/2;
If (x> mid)
Update (k <1 | 1, x, y );
Else if (y <= mid)
Update (k <1, x, y );
Else
{
Update (k <1, x, mid );
Update (k <1 | 1, mid + 1, y );
}
List [k]. sum = list [k <1]. sum + list [k <1 | 1]. sum;
}
LL find (int k, int x, int y)
{
Int mid;
If (list [k]. x = x & list [k]. y = y)
Return list [k]. sum;
Mid = (list [k]. x + list [k]. y)/2;
If (x> mid)
Return find (k <1 | 1, x, y );
Else if (y <= mid)
Return find (k <1, x, y );
Else
Return find (k <1, x, mid) + find (k <1 | 1, mid + 1, y );
}
Int main ()
{
Int n, m, t, x, y;
Int cnt = 0;
While (scanf ("% d", & n )! = EOF)
{
Cnt ++;
Printf ("Case # % d: \ n", cnt );
Build (1, 1, n );
Scanf ("% d", & m );
While (m --)
{
Scanf ("% d", & t, & x, & y );
If (x> y)
Swap (x, y );
If (t = 0)
Update (1, x, y );
Else
Printf ("% I64d \ n", find (1, x, y ));
}
Printf ("\ n ");
}
Return 0;
}
 
By Cambridgeacm

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.