68820
--
# Include
Int sum [3000000]; void build (int B, int e, int index) {if (B = e) {scanf ("% d ", & sum [index]); return;} int mid = (B + e)/2, lchild = index <1, rchild = lchild | 1; build (B, mid, lchild); build (mid + 1, e, rchild); sum [index] = sum [lchild] + sum [rchild];} int query (int qb, int qe, int B, int e, int index) {if (qb <= B & e <= qe) return sum [index]; int mid = (B + e)/2, lchild = index <1, rchild = lchild | 1, lr = 0, rr = 0; if (qb <= mid) lr = query (qb, qe, B, mid, lchild); if (qe> mid) rr = query (qb, qe, mid + 1, e, rchild); return lr + rr;} void update (int B, int e, int node, int num, int index) {if (B = e & e = node) {sum [index] + = num; return ;} int mid = (B + e)/2, lchild = index <1, rchild = lchild | 1; if (node <= mid) update (B, mid, node, num, lchild); else update (mid + 1, e, node, num, rchild); sum [index] + = num;} int main () {int n, k, b, e; char str [10]; scanf ("% d", & n, & k); build (1, n, 1 ); for (int I = 0; I
Question: questions about the blue bridge cup exercise-combining the largest interval and
Algorithm training operation lattice time limit: 1.0 s memory limit: 256.0MB Problem Description
There are n grids in a row numbered 1-n from left to right.
There are a total of m operations, there are 3 types of operations:
1. Modify the weight of a grid,
2. Calculate the sum of consecutive lattice values,
3. Calculate the maximum value of a consecutive grid.
Output the result of each 2 or 3 operation.
Input Format
The first row has two integers, n and m.
The n integers in the next row represent the initial weights of n grids.
In the next m row, each row has three integers, p, x, y, and p, indicating the operation type. When p = 1, it indicates changing the weight of grid x to y, when p = 2, it indicates the sum of the grid weights in the range [x, y], and when p = 3, it indicates the maximum weight of the grid in the range [x, y.
Output Format
There are several rows. The number of rows equals the total number of operations with p = 2 or 3.
Each row has one integer, corresponding to the result of each p = 2 or 3 operation.
Example input 4 3
1 2 3 4
2 1 3
1 4 3
3 1 4 sample output 6
3. Data scale and conventions
For 20% of data, n <= 100, m <= 200.
For 50% of data, n <= 5000, m <= 5000.
For 100% of data 1 <= n <= 100000, m <= 100000,0 <= grid weight <= 10000.
# Include
# Include
Using namespace std; const int MAX = 100110; # define lson l, m, rt <1 # define rson m + 1, r, rt <1 | 1int sum [MAX <2], segs [MAX <2], maxv [MAX <2]; // interval and-interval value-Interval Maximum inline void push_up (int rt) {sum [rt] = sum [rt <1] + sum [rt <1 | 1]; maxv [rt] = max (maxv [rt <1], maxv [rt <1 | 1]);} void build_up (int l, int r, int rt) {if (l = r) {scanf ("% d ", & segs [rt]); sum [rt] = segs [rt]; maxv [rt] = segs [rt]; return;} int m = (l + r)> 1; build_up (lson); build_up (rson); push_up (rt);} void update (int l, int r, int rt, int p, int v) {if (l = r) {segs [rt] = v; maxv [rt] = v; sum [rt] = v; return ;} int m = (l + r)> 1; if (p <= m) update (lson, p, v); else update (rson, p, v ); push_up (rt);} int query_sum (int L, int R, int l, int r, int rt) {if (L <= l & r <= R) {return sum [rt];} int ret = 0; int m = (l + r)> 1; if (L <= m) ret + = query_sum (L, r, lson); if (R> m) ret + = query_sum (L, R, rson); return ret;} int query_max (int L, int R, int l, int r, int rt) {if (L <= l & r <= R) {return maxv [rt];} int ret =-1; int m = (l + r)> 1; if (L <= m) ret = max (ret, query_max (L, R, lson )); if (R> m) ret = max (ret, query_max (L, R, rson); return ret;} int main () {int n, m; cin> n> m; build_up (1, n, 1); while (m --) {int p, x, y; scanf ("% d", & p, & x, & y); if (p = 1) {update (1, n, 1, x, y);} else if (p = 2) {printf ("% d \ n", query_sum (x, y, 1, n, 1 ));} else {printf ("% d \ n", query_max (x, y, 1, n, 1) ;}} return 0 ;}
Question:
Doped geometric knowledge
Crane
Time Limit:2000 MS |
|
Memory Limit:65536 K |
Total Submissions:3012 |
|
Accepted:806 |
|
Special Judge |
Description
ACM has bought a new crane (crane -- je? Áb ). the crane consists of n segments of various lengths, connected by flexible joints. the end of the I-th segment is joined to the beginning of the I + 1-th one, for 1 ≤ I <n. the beginning of the first segment is fixed at point with coordinates (0, 0) and its end at point with coordinates (0, w), where w is the length of the first segment. all of the segments lie always in one plane, and the joints allow arbitrary rotation in that plane. after series of unpleasant accidents, it was decided that software that controls the crane must contain a piece of code that constantly checks the position of the end of crane, and stops the crane if a collision shoshould happen.
Your task is to write a part of this software that determines the position of the end of the n-th segment after each command. the state of the crane is determined by the angles between consecutive segments. initially, all of the angles are straight, I. e ., 180o. the operator issues commands that change the angle in exactly one joint.
Input
The input consists of several instances, separated by single empty lines.
The first line of each instance consists of two integers 1 ≤ n ≤ 10 000 and c 0 separated by a single space -- the number of segments of the crane and the number of commands. the second line consists of n integers l1 ,..., ln (1 li 100) separated by single spaces. the length of the I-th segment of the crane is li. the following c lines specify the commands of the operator. each line describing the command consists of two integers s and a (1 ≤ s <n, 0 ≤ a ≤359) separated by a single space -- the order to change the angle between the s-th and the s + 1-th segment to a degrees (the angle is measured counterclockwise from the s-th to the s + 1-th segment ).
Output
The output for each instance consists of c lines. the I-th of the lines consists of two rational numbers x and y separated by a single space -- the coordinates of the end of the n-th segment after the I-th command, rounded to two digits after the decimal point.
The outputs for each two consecutive instances must be separated by a single empty line.
Sample Input
2 110 51 903 25 5 51 2702 90
Sample Output
5.00 10.00-10.00 5.00-5.00 10.00
# Include
# Include
# Include
Using namespace std; # define lson I <1 # define rson I <1 | 1 # define lc l, mid, I <1 # define rc mid + 1, r, I <1 | 1 const int L = 100000 + 10; const double pi = acos (-1.0); struct node {double x, y; int deg; int flag ;} a [L <2]; double set (int x) {return x * pi/180;} void work (int I, int deg) // obtain the new coordinate formula {double r = set (deg); double x = a [I]. x; double y = a [I]. y; a [I]. x = x * cos (r)-y * sin (r); a [I]. y = x * sin (r) + y * cos (r); a [I]. deg = (A [I]. deg + deg) % 360;} void pushup (int I) {a [I]. x = a [lson]. x + a [rson]. x; a [I]. y = a [lson]. y + a [rson]. y;} void pushdown (int I) {if (a [I]. flag) {work (lson, a [I]. flag); work (rson, a [I]. flag); a [lson]. flag + = a [I]. flag; a [rson]. flag + = a [I]. flag; a [I]. flag = 0 ;}} void init (int l, int r, int I) {a [I]. x = a [I]. y = 0; a [I]. flag = a [I]. deg = 0; if (l = r) {scanf ("% lf", & a [I]. y); return;} int mid = (l + r)> 1; init (l C); init (rc); pushup (I);} void insert (int l, int r, int I, int L, int R, int z) {if (L <= l & r <= R) {work (I, z); a [I]. flag + = z; return;} pushdown (I); int mid = (l + r)> 1; if (L <= mid) insert (lc, L, R, z); if (R> mid) insert (rc, L, R, z); pushup (I);} int query (int l, int r, int I, int x) {if (l = r) return a [I]. deg; pushdown (I); int mid = (l + r)> 1; if (x <= mid) return query (lc, x); else return query (rc, x);} int main () {int N, m, x, y, flag = 1, I, j; while (~ Scanf ("% d", & n, & m) {init (0, n-1, 1); if (! Flag) printf ("\ n"); flag = 0; while (m --) {scanf ("% d", & x, & y); int deg; deg = query (0, n-1, 1, x-1) + 180 + y-query (0, n-1, 1, x); // since the question is clockwise, this computation is clockwise and requires an additional 180 degrees. It regards the following rod as still on the Y axis. Therefore, we need to subtract the angle insert (0, n-1, 1, x, n-1, deg); printf ("%. 2f %. 2f \ n ", a [1]. x, a [1]. y) ;}} return 0 ;}