Bzoj 3211: Flower Gods travel across countries (line tree)

Source: Internet
Author: User

Segment Tree ... Interval prescribe ... is obviously to be processed to the leaf node

Before the CF do the aisle zone to take the mold ... Almost, only the root, then each number of the root number is also limited (0, 1 o'clock will stop), the largest number of 10^9, the root of the root will not move. Then we can count more than one Max in the line segment tree to lose a lot of unnecessary action

--------------------------------------------------------------------------------------------

#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <iostream> #define REP (i, n) for (int i = 0; i < n; i++)#define M (L, R) (((L) + (R)) >> 1)#define CLR (x, C) memset (x, C, sizeof (x))using namespace std;typedef long Long ll;const int MAXN = 100009;struct Node {Node *l, *r;int V, MX;ll sum;Node (): MX (0) {L = r = NULL;}inline void Update () {if (l) {mx = max (l->mx, r->mx);sum = l->sum + r->sum;} elsesum = mx = v;}} POOL[MAXN << 1], *pt = Pool, *root;int L, R, N, SEQ[MAXN]; void Build (node* t, int l, int r) {if (R > L) {int m = m (l, R);Build (T->l = pt++, L, m);Build (T->r = pt++, M + 1, R);} elset->v = seq[l];t->update ();}void Modify (node* t, int l, int r) {if (t->mx <= 1) return;if (L = = r)t->v = Floor (sqrt (t->v));else {int m = m (l, R);if (l <= m) modify (T->l, L, m);if (M < R) Modify (T->r, M + 1, R);}t->update ();} ll query (node* t, int l, int r) {if (l <= l && R <= R)return t->sum;int m = m (l, R);return (l <= m? Query (T->l, L, m): 0) + (M < R? query (T->r, M + 1, R): 0);}  int main () {//freopen ("test.in", "R", stdin);cin >> N;for (int i = 1; I <= n; i++)scanf ("%d", seq + i);Build (Root = pt++, 1, n);int m, op;cin >> m;While (m--) {scanf ("%d%d%d", &op, &l, &r);if (op = = 1)printf ("%lld\n", Query (root, 1, n));ElseModify (root, 1, n);}return 0;}

--------------------------------------------------------------------------------------------

3211: The flower God travels all countries time limit: 5 Sec Memory Limit: MB
Submit: 1414 Solved: 546
[Submit] [Status] [Discuss] Description

Input

Output

every x=1 , each line is an integer that indicates the pleasure of this trip

Sample Input4

1 100 5 5

5

1 1 2

2 1 2

1 1 2

2 2 3

1 1 4

Sample Output101

11

11

HINT

For 100% data, n≤100000,m≤200000, Data[i] is non-negative and less than 10^9


Source

SPOJ2713 GSS4 data has been enhanced

Bzoj 3211: Flower Gods travel across countries (line tree)

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.