[Kuangbin take you to fly] thematic seven-segment tree

 
A rival country C country's ongoing military exercises this time, the country's spy chief C Derek and his men began to busy Tidy up. A country coastline arranged along a line of the N engineering camps, Derek and Tidy task is to monitor the activities of these engineers camps. As a result of some kind of advanced monitoring tools, so the number of engineers in each camp C crystal clear grasp States, the number of engineers in each camp are likely to occur change, may increase or decrease the number of staff, but they can not escape C monitor the country.
CIA to study enemy tactics exactly what exercises, so Derek Tidy to keep the report a certain period of continuous engineering camp a total of how many people, such as Derek asked: "Tidy, immediately report the first three camps to many people of a total of 10 camps ! "Tidy will immediately begin to calculate the total number of this paragraph and report. But the number of enemy camps often change, and Derek asked each segment is different, so every time a Tidy had to go to a number of camps, soon exhausted, Derek to calculate the speed of the Tidy increasingly dissatisfied: "! you a dead fat boy, considered so slow, I fire you" Tidy thought: "you do the math yourself, which is really a tiring job I wish you fire me too!! "In desperation, Tidy had to call a computer expert to help Windbreaker, Windbreaker, said:"! dead fat boy, do you usually called multi-point acm title and see multi-point arithmetic book, now tasted the bitter fruit of it "Tidy said:" I admitted the mistake ... "but Windbreaker has hung up the phone. Tidy very upset, so he really will count crash, the intelligent reader, you can write a program to help him finish the job? But if your program efficiency is not high enough, Tidy will still be scolded Derek's.

Input a first line integer T, T set of data expressed.
Data of the first line of each a positive integer N (N <= 50000), there are N represents the enemy camps engineer, the next positive integers with N, has the i ai positive integer representing the i-th ai start engineering camp personal (1 <= ai <= 50 ).
Next, each row having a command, command has four forms:
(. 1) ij of the Add, i, and j is a positive integer, denotes the i th camp increase personal j (j is not more than 30)
(2) Sub ij of, i and j It is a positive integer, denotes the i th camps reduce j individuals (j does not exceed 30);
(. 3) Query ij of, i and j are positive integers, i <= j, presents to ask the total number of i-th to j-th camps;
(4) end indicates the end, the last command that appears in each set of data;
up to 40,000 commands each data
output of the i-th group of data, first outputs "Case i:" and enter,
for each query Query output the total number of integer and a carriage return, indicating an inquiry segment, this number remains within int.
Sample Input
1
10
1 2 3 4 5 6 7 8 9 10
Query 1 3
Add 3 6
Query 2 7
Sub 10 2
Add 6 3
Query 3 10
End 
Sample Output
Case 1:
6
33
59

#define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
#define lc now<<1
#define rc now<<1|1
#define ls now<<1,l,mid
#define rs now<<1|1,mid+1,r
#define half no[now].l+((no[now].r-no[now].l)>>1)
const int mxn = 50000+5;
struct node
{
    int l,r,val,lazy;
}no[mxn<<2];
void pushup(int now) { no[now].val = no[lc].val+no[rc].val; return ;}
void build(int now , int l,int r)
{
    no[now].l = l;no[now].r = r;
    if(l==r)
    {
        cin>>no[now].val;
        //cout<<no[now].val<<" ";
        return ;
    }
    int mid = l+((r-l)>>1);
    build(lc,l,mid);
    build(rc,mid+1,r);
    pushup(now);
}
int query(int now,int l,int r)
{
    if(no[now].l>=l && r>=no[now].r)
        return no[now].val;
    int mid = no[now].l+((no[now].r-no[now].l)>>1),cnt = 0;
    if(l<=mid)
        cnt+=query(lc,l,r);
    if(r>mid)
        cnt+=query(rc,l,r);
    return cnt;
}
void updata(int now,int pos,int key)
{
    if(no[now].l==no[now].r)
    {
        no[now].val+=key;
        return ;
    }
    int mid = half;
    if(pos<=mid)
        updata(lc,pos,key);
    else
        updata(rc,pos,key);
    pushup(now);
}
int main()
{
    TLE;
    int t,n,l,r;
    string str;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        cout<<"Case "<<i<<":"<<endl;
        cin>>n;
        build(1,1,n);
        while(cin>>str&&(str[0]!='E'))
        {
            if(str[0]=='Q')
            {
                cin>>l>>r;
                cout<<query(1,l,r)<<endl;
            }
            else if(str[0]=='A')
            {
                cin>>l>>r;
                updata(1,l,r);
            }

            else if(str[0]=='S')
            {
                cin>>l>>r;
                updata(1,l,-1*r);
            }
        }
    }
    return 0;
}

 

B - I Hate It

A more popular habit of many schools. The teachers really like to ask, so and so to so and so from among the highest score is.
This allows many students are disgusted.

Whether you like it or not, now you need to do is, it is in accordance with the requirements of the teacher, to write a program to simulate the teacher asked. Of course, teachers sometimes need to update certain students achievements.

Input本题目包含多组测试,请处理到文件结束。
在每个测试的第一行,有两个正整数 N 和 M ( 0<N<=200000,0<M<5000 ),分别代表学生的数目和操作的数目。
学生ID编号分别从1编到N。
第二行包含N个整数,代表这N个学生的初始成绩,其中第i个数代表ID为i的学生的成绩。
接下来有M行。每一行有一个字符 C (只取'Q'或'U') ,和两个正整数A,B。
当C为'Q'的时候,表示这是一条询问操作,它询问ID从A到B(包括A,B)的学生当中,成绩最高的是多少。
当C为'U'的时候,表示这是一条更新操作,要求把ID为A的学生的成绩更改为B。
Output对于每一次询问操作,在一行里面输出最高成绩。Sample Input
5 6
1 2 3 4 5
Q 1 5
U 3 6
Q 3 4
Q 4 5
U 2 9
Q 1 5
Sample Output
5
6
5
9


        
 
Hint
Huge input,the C function scanf() will work better than cin
        
 
#define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
#define lc now<<1
#define rc now<<1|1
#define ls now<<1,l,mid
#define rs now<<1|1,mid+1,r
#define half no[now].l+((no[now].r-no[now].l)>>1)
const int mxn = 200000+5; int mx;
struct node
{
    int l,r,val,lazy;
}no[mxn<<2];
void pushup(int now) { no[now].val = max( no[lc].val,no[rc].val); return ;}
void build(int now , int l,int r)
{
    no[now].l = l;no[now].r = r;
    if(l==r)
    {
        cin>>no[now].val;
        return ;
    }
    int mid = l+((r-l)>>1);
    build(lc,l,mid);
    build(rc,mid+1,r);
    pushup(now);
}
void query(int now,int l,int r)
{
    if(no[now].l>=l && r>=no[now].r)
        {mx = max(mx,no[now].val);return ;}
    int mid = no[now].l+((no[now].r-no[now].l)>>1);
    if(l<=mid)
        query(lc,l,r);
    if(r>mid)
        query(rc,l,r);
}
void updata(int now,int pos,int key)
{
    if(no[now].l==no[now].r&&no[now].l==pos)
    {
        no[now].val = key;
        return ;
    }
    int mid = half;
    if(pos<=mid)
        updata(lc,pos,key);
    else
        updata(rc,pos,key);
    pushup(now);
}
int main()
{
    TLE;
    int t,n,l,r;
    while(cin>>n>>t)
    {
        build(1,1,n);
        while(t--)
        {
            mx = -1;
            char ch;
            cin>>ch>>l>>r;
            if(ch=='Q')
            {
                query(1,l,r);
                cout<<mx<<endl;
            }
            else
                updata(1,l,r);
        }
        
    }
    return 0;
}

 

K - Atlantis

There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of the island. But unfortunately, these maps describe different regions of Atlantis. Your friend Bill has to know the total area for which maps exist. You (unwisely) volunteered to write a program that calculates this quantity.

InputThe input file consists of several test cases. Each test case starts with a line containing a single integer n (1<=n<=100) of available maps. The n following lines describe one map each. Each of these lines contains four numbers x1;y1;x2;y2 (0<=x1<x2<=100000;0<=y1<y2<=100000), not necessarily integers. The values (x1; y1) and (x2;y2) are the coordinates of the top-left resp. bottom-right corner of the mapped area.

The input file is terminated by a line containing a single 0. Don’t process it.OutputFor each test case, your program should output one section. The first line of each section must be “Test case #k”, where k is the number of the test case (starting with 1). The second one must be “Total explored area: a”, where a is the total explored area (i.e. the area of the union of all rectangles in this test case), printed exact to two digits to the right of the decimal point.

Output a blank line after each test case.
Sample Input
2
10 10 20 20
15 15 25 25.5
0
Sample Output
Test case #1
Total explored area: 180.00 


明天更新吧,到了睡觉时间了

Guess you like

Origin www.cnblogs.com/Shallow-dream/p/11741472.html