A-Qiushi brother and children Time Limit:3000/1000ms (java/others) Memory limit:65535/65535kb (java/others)SubmitStatus
Qiushi Big Brother to give alms to the world, justice responsibility, he often heaved to the sky: "Ann to Guangsha tens of thousands of, the World scholars Furniture smile solutions."
So today he's giving sugar to a bunch of kids.
He had all the children lined up, numbered from left to right. In the next time, he will sometimes give a section of the children each v Sugar, sometimes asked the number of x Children have a few sugar in their hands.
This is too difficult for a child who has not gone to school, so you can not look down, please help the children to answer all the questions.
Input
The first line contains two integers n,m, which indicates the number of children, and the number of operands you want to handle next.
The next m -line, each line represents one of the following two actions:
0: Qiushi elder brother to [l,R] This interval of the children of each v sugar 1: Qiushi Big Brother want to know the first x There are a few candies in the hands of a little friend now.
1≤m,v≤100000 ,1≤l≤r≤n , 1≤x≤n,1≤n≤100000000 .
Output
For each 1 x operation, output an integer that represents the number of candies present in the hands of the x child.
Sample Input and output
Sample Input |
Sample Output |
3 40 1 3 11 20 2 3 31 3 |
14 |
Problem Solving Report
First of all, because the number of children can be as high as 1e8, so we first read all points, discretization.
After that, the line tree or the tree-like array is random.
I am using a tree-like array: Here my discrete write water, each time to check the location (OK, don't care about these details)
1#include <iostream>2#include <algorithm>3#include <cstring>4#include <cstdio>5#include <queue>6#include <Set>7 using namespacestd;8typedefLong Longll;9 Const intMAXN = 2e5 + -;Ten intsize; One Set<int>CV; A intPOINT[MAXN]; - -typedefstructOper the { - intL,r,v,ope; -OperConst int&ope,Const int&l,Const int&r,Const int&v) - { + This->ope = Ope, This->l = L, This->r = R, This->v =v; - } + }; A atQueue<oper>query; - ll C[MAXN]; - -InlineintLowbit (intcur) - { - returncur& (-cur); in } - to voidAddintL,ll v) + { - if(!l) the return; * while(L >0) $ {Panax NotoginsengC[l] + =v; -L-=lowbit (l); the } + } A thell find (intx) + { -ll res =0; $ while(x <=size) $ { -Res + =C[x]; -X + =lowbit (x); the } - returnRes;Wuyi } the - Wu intMainintargcChar*argv[]) - { AboutMemset (c,0,sizeof(c)); $ intn,m; -scanf"%d%d",&n,&m); -Size =0; - while(m--) A { + intOpe; thescanf"%d",&ope); - if(Ope &1) $ { the inttemp; thescanf"%d",&temp); the if(!Cv.count (temp)) the { - Cv.insert (temp); inPoint[++size] =temp; the } theQuery.push (Oper (ope,0,0, temp)); About } the Else the { the intl,r,v; +scanf"%d%d%d",&l,&r,&v); - if(!Cv.count (l)) the {Bayi Cv.insert (l); thePoint[++size] =l; the } - if(!Cv.count (R)) - { the Cv.insert (r); thePoint[++size] =R; the } the Query.push (Oper (ope,l,r,v)); - } the } theSort (point+1, point+1+size); the while(!query.empty ())94 { theOper SS =Query.front (); Query.pop (); the if(Ss.ope &1) the {98 intpos = Lower_bound (point+1, POINT+SIZE,SS.V)-Point ; Aboutprintf"%lld\n", find (POS)); - }101 Else102 {103ll v =(ll) ss.v;104 intpos = Lower_bound (point+1, POINT+SIZE,SS.L)-Point ; theAdd (pos-1,-v);106pos = Lower_bound (point+1, POINT+SIZE,SS.R)-Point ;107 Add (pos,v);108 }109 } the return 0;111}
Uestc_ Qiushi brother and children UESTC Training for Data Structures<problem a>