Test instructions is this, given a 1000x1000 lattice, the M-group asks for a weight and a point that is surrounded by a right triangle (a. 0,0), a (x,0) point, and a direction vector (a, a, A, b) from the origin.
The weighted value of the point is (x+a) (y+b), where a, b is the given constant
It is also obvious that the query is taken offline and ordered by the direction vector, and then the operation is equivalent to using an endpoint at the origin of the line from the x-axis to the y-axis sweep, constantly the sweep of the point of the weight of the tree array. Each time you sweep the direction vector of a query, use the bottom edge of the triangle to prefix and record it.
The weight will explode int, just be careful.
#include <map> #include <string> #include <cstring> #include <cstdio> #include <cstdlib># include<cmath> #include <queue> #include <vector> #include <iostream> #include <algorithm > #include <bitset> #include <climits> #include <list> #include <iomanip> #include <stack > #include <set>using namespace std;typedef long long ll;ll bit[1010];void update (int pos,ll val) {for (int i=pos;i <=1000;i+=i&-i) Bit[i]+=val;} ll psum (int pos) {ll ans=0;for (int i=pos;i>0;i-=i&-i) Ans+=bit[i];return ans;} struct Point{int X,y;bool operator < (point one) Const{return y*one.x<=one.y*x;} Point[1000010];struct qu{int X,y,len,no;bool operator < (Qu one) Const{return ll (y*one.x) <ll (one.y*x);}} Qu[1000010];ll Ans[1000010];int Main () {int n=0;for (int i=1;i<=1000;i++) for (int j=1;j<=1000;j++) {point[n].x=i; Point[n++].y=j;} Sort (point,point+n), int t;scanf ("%d", &t), for (int cs=1;cs<=t;cs++) {int a,b,m;scanf ("%d%d%d", &a,&b, &m); for (int i=0;i<m;i++) {scanf ("%d%d%d", &qu[i].x,&qu[i].y,&qu[i].len); qu[i].no=i;} Sort (qu,qu+m); memset (bit,0,sizeof (bit)); for (int. i=0,j=0;i<m;i++) {Point T;t.x=qu[i].x;t.y=qu[i].y;while (j<n &&point[j]<t) {update (POINT[J].X,LL (point[j].x+a) * (point[j].y+b); j + +;} Ans[qu[i].no]=psum (Qu[i].len);} printf ("Case #%d:\n", CS); for (int i=0;i<m;i++) Cout<<ans[i]<<endl;}}
Time limit:10000/5000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 518 Accepted Submission (s): 157
Problem Descriptionmatt have a company, always Cook Mushroom (ACM), which produces high-quality mushrooms.
ACM has a large field to grow their mushrooms. The field can be considered as a-a-mushrooms-grid where the is grown in grid points numbered from (1, 1) to (1000, Because of humidity and sunshine, the productions in different grid points is not the same. Further, the production in the grid points (x, y) was (x + A) (y + B) where A, B is the constant.
Matt,the owner of ACM have some queries where he wants to know the sum of the productions in a given scope (include the MUSH The growing on the boundary). In each query, the scope Matt asks was a right angled triangle whose apexes was (0, 0), (p, 0), (p, Q) 1<=p, q<=1000.
As the employee of ACM, can you answer Matt ' s queries?
Inputthe first line contains one integer T, indicating the number of test cases.
For each test case, the first line contains Integers:a, B (0<=a, b<=1000).
The second line contains one integer M (1<=m<=10^5), denoting the number of queries.
In the following M lines, the i-th line contains three integers a, b, X (1<=a, B<=10^6, 1<=x<=1000), denoting One apex of the given right angled triangle are (x, 0) and the slope of its base are (A, b). It is guaranteed the gird points in the given right angled triangle be all in valid area, numbered from (1, 1) to (1 000, 1000).
Outputfor each test case, output M + 1 lines.
The first line contains ' case #x: ', where x is the case number (starting from 1)
In the following M lines, the i-th line contains one integer, denoting the answer of the i-th query.
Sample Input
20 033 5 82 4 71 2 31 233 5 82 4 71 2 3
Sample Output
Case #1:1842170886Case #2:29012688200
Source2014 ACM/ICPC Asia Regional Beijing Online
Recommendhujie | We have carefully selected several similar problems for you:5287 5286 5285 5284 5283
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
hdu5032 always Cook Mushroom