[Bzoj 3995] [SDOI2015] Road Construction "segment Tree Maintenance Connectivity"

Source: Internet
Author: User

Title Link: BZOJ-3995

Problem analysis

This question. is the memory of my sadness.

The segment tree maintains connectivity, similar to BZOJ-1018, but I haven't done 1018 before, even though it's on the first page of Problemset.

More sadly, the problem has 40 points of violence, write a kruskal can be obtained, but I wrote a faster DP.

It wasn't a problem, but my DP transfer was less of a situation, so ... Explode zero. Yes, the top 20 in the provincial election. Maybe I didn't get the 40 points?

Don't want to say anything more ... Hope in the future do not such a SB, if there is still a chance.

Let's just say the question.

First Orz LZR god Ben, I wrote his practice.

For a period of time, we only need to know that its four corners of the four lattice between the connectivity is possible, a total of 10 possible cases, however, some of the 10 cases are the same species, so can be divided into 5 kinds.

Then pay attention to dividing the interval is the selection of the red lattice, rather than the use of the title directly described in the black lattice. That is, a range of length 1 actually contains 4 lattice points of 2 * 2.

The advantage of this is that it is very good to write! When the answer of a new interval is synthesized with two sub-intervals, the left end of the right and right interval of the left interval is actually the same column point, which is coincident and seamless, so as long as the connecting state of the two ends interval is determined, the whole interval of the Unicom state is determined.

Unlike a different approach, it is very, very complex to consider the middle edge of the merge.

This merges up to 5 * 5 = 25, in fact some mergers are illegal, and finally there are only 17 merges. It would be nice to write them manually into a table.

Then use the line tree maintenance is good, when modifying a vertical edge of the Benquan, the adjacent two grid will be recalculated.

Code
#include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath  > #include <algorithm>using namespace std;inline void Read (int &num) {char c = getchar (); bool Neg = False;while (C < ' 0 ' | | c > ' 9 ') {if (c = = '-') Neg = True;c = GetChar ();} Num = C-' 0 '; c = GetChar (); while (c >= ' 0 ' && C <= ' 9 ') {num = num * + C-' 0 '; c = GetChar ();} if (Neg) Num =-num;} inline int gmin (int a, int b) {return a < b a:b;} inline int gmax (int a, int b) {return a > b a:b;} const int MAXN = 60000 + 5, INF = 999999999;const int magic[20][5] = {{1, 1, 1}, {1, 2, 2}, {1, 3, 3}, {1, 4, 4},{1, 5, 5} , {2, 1, 2}, {2, 3, 2}, {2, 5, 4},{3, 1, 3}, {3, 3, 3}, {3, 5, 5}, {4, 1, 4},{4, 2, 2}, {4, 4, 4}, {5, 1, 5}, {5, 2, 3},{5 , 4, 5}};int N, m;int a[maxn][3];struct es{int x[6];} T[MAXN * 4];es operator + (es e1, es E2) {es ret;for (int i = 1; I <= 5; ++i) ret. X[i] = inf;for (int i = 0; i <; ++i) ret. X[MAGIC[I][2]] = Gmin (rEt. X[MAGIC[I][2]], E1. X[MAGIC[I][0]] + E2. X[MAGIC[I][1]]); return ret;} ES Calc (int s) {es ret;ret. X[1] = a[s][1] + a[s][2];ret. X[2] = a[s][1] + a[s][2] + a[s][0] + a[s + 1][0]-gmax (Gmax (a[s][1], a[s][2]), Gmax (A[s][0], A[s + 1][0]); ret. X[3] = A[s + 1][0] + gmin (a[s][1], a[s][2]); ret. X[4] = a[s][0] + gmin (a[s][1], a[s][2]); ret. X[5] = Gmin (a[s][1], a[s][2]); return ret;} void Build (int x, int s, int t) {if (s = = t) {t[x] = Calc (s); return;} int m = (s + t) >> 1; Build (x << 1, S, m); Build (x << 1 | 1, M + 1, t); T[X] = t[x << 1] + t[x << 1 | 1];} void change (int x, int s, int t, int Pos) {if (s = = t) {t[x] = Calc (s); return;} int m = (s + t) >> 1;if (pos <= m) Change (x << 1, S, M, POS); Else change (x << 1 | 1, M + 1, T, POS); t [x] = t[x << 1] + t[x << 1 | 1];} ES Get (int x, int s, int t, int l, int r) {if (L <= s && r >= t) return t[x];int m = (s + t) >> 1;es RE T;if (R <= m) ret = Get (x << 1, S, M, L, R); else if (L >= m + 1) ret = Get (x << 1 | 1, M + 1, T, L, R); else ret = Get (x << 1, S, M, L, R) + get (x << 1 | 1 , M + 1, T, L, R); return ret;} int main () {scanf ("%d%d", &n, &m), for (int i = 1; I <= n-1; ++i) Read (a[i][1]); for (int i = 1; I <= n-1; ++i) read (a[i][2]); for (int i = 1; I <= n; ++i) read (a[i][0]); Build (1, 1, n-1), char str[3];es ans;int x, y, xx, yy, Num, L, R; for (int i = 1; I <= m; ++i) {scanf ("%s", Str), if (str[0] = = ' C ') {Read (x); Read (y); Read (XX); Read (yy); Read (num), if (x = = xx) {a[gmin (Y, yy)][x] = Num; Change (1, 1, n-1, Gmin (y, yy));} Else{a[y][0] = num;if (Y! = 1) Change (1, 1, n-1, y-1), if (Y! = N) Change (1, 1, n-1, y);}} Else{read (l); Read (R), if (L = = r) printf ("%d\n", A[l][0]), Else{ans = Get (1, 1, n-1, L, r-1);p rintf ("%d\n", Ans.x[2]);}} return 0;}

  

[Bzoj 3995] [SDOI2015] Road Construction "segment Tree Maintenance Connectivity"

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.