{"id":83,"date":"2011-03-03T07:56:14","date_gmt":"2011-03-02T23:56:14","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=83"},"modified":"2012-03-03T07:56:27","modified_gmt":"2012-03-02T23:56:27","slug":"zju-1391-horizontally-visible-segments","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/zju-1391-horizontally-visible-segments\/","title":{"rendered":"ZJU 1391. Horizontally Visible Segments"},"content":{"rendered":"<h3>Brief description :<\/h3>\n<p>\u7ed9\u5b9a\u4e00\u7ec4\u5782\u76f4\u7ebf\u6bb5\uff0c\u6c42\u5176\u4e2d\u5e73\u884c\u53ef\u89c1\u4e09\u89d2\u7684\u7ec4\u6570\u3002\u6240\u8c13\u7684\u53ef\u89c1\u4e09\u89d2\uff0c\u6307\u4e09\u7ec4\u7ebf\u6bb5\u4e4b\u95f4\u76f8\u4e92\u53ef\u89c1\u3002<\/p>\n<h3>Analyse :<\/h3>\n<p>\u6b64\u9898\u8f83\u96be\u7f20\uff0c\u901a\u5e38\u53ef\u5206\u4e3a\u4ee5\u4e0b\u4e24\u4e2a\u4e3b\u8981\u6b65\u9aa4\u3002<br \/>\n1. \u6839\u636e\u51e0\u4f55\u53ef\u89c6\u5173\u7cfb\uff0c\u6784\u56fe\u3002<br \/>\n2. \u7edf\u8ba1\u53ef\u89c1\u4e09\u89d2\u7684\u7ec4\u6570\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u4e0b\u9762\u4e3b\u8981\u8ba8\u8bba\u6b65\u9aa4\u4e00\u3002\u9887\u4e3a\u610f\u5916\uff0c\u8fd9\u9898\u6839\u636e\u626b\u63cf\u7ebf\u6216\u5782\u76f4\u6216\u6c34\u5e73\u65b9\u5411\u7684\u4e0d\u540c\uff0c\u7b97\u6cd5\u7684\u8868\u73b0\u4f1a\u51fa\u73b0\u8fd9\u4e48\u5927\u7684\u5dee\u522b &#8230;<\/p>\n<h4>1.\u7eb5\u5411<\/h4>\n<p>\u5bf9\u4e8e\u6bcf\u4e00\u96bb\u7ebf\u6bb5\uff0c\u5efa\u7acb\u4e00\u4e2a\u63d2\u5165\u4e8b\u4ef6\u548c\u4e00\u4e2a\u5220\u9664\u4e8b\u4ef6\uff0c\u6392\u5e8f\u4e4b\u540e\u4ece\u4e0b\u5411\u4e0a\u626b\u63cf&#8230; \u6b64\u5904\u9700\u8981\u53ef\u4ee5\u652f\u6301\u63d2\u5165\uff08Insert\uff09\uff0c\u5220\u9664\uff08Delete\uff09&#8230;\u4ee5\u53ca\u8fd4\u56de\u524d\u9a71\uff08Predecessor\uff09\u3001\u540e\u7ee7\uff08Successor\uff09\u7684\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<p><bk><bk><br \/>\n<div id=\"attachment_2153\" style=\"width: 490px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/03\/2146Illustration_1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2153\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/03\/2146Illustration_1.png\" alt=\"Illustration 1\" title=\"[2146]Illustration_1\" width=\"480\" height=\"320\" class=\"size-full wp-image-2153\" \/><\/a><p id=\"caption-attachment-2153\" class=\"wp-caption-text\">Illustration 1. \u7eb5\u5411\u626b\u63cf\uff0c\u6ce8\u610f\u5bf9\u63d2\u5165\u4e8b\u4ef6\u548c\u5220\u9664\u4e8b\u4ef6\u533a\u522b\u5bf9\u5f85\u3002<\/p><\/div><br \/>\n<bk><\/p>\n<h4>2.\u6a2a\u5411<\/h4>\n<p>\u5982\u679c\u60f3\u5230\u5148\u5c06\u7aef\u70b9\u00d72\uff0c\u518d\u62c6\u300c\u7ebf\u6bb5\u6811\u300d\u4e3a\u300c\u70b9\u6811\u300d\u7684\u8bdd\uff0c\u8fdb\u800c\u5316\u5f52\u6210\u300c\u533a\u95f4\u63d2\u5165\uff0c\u533a\u95f4\u8be2\u95ee\u7684\u7ebf\u6bb5\u67d3\u8272\u95ee\u9898\u300d\uff0c\u601d\u7ef4\u590d\u6742\u5ea6\u548c\u4ee3\u7801\u91cf\u9a6c\u4e0a\u5c31\u4f1a\u660e\u663e\u51cf\u5c11\uff0c\u8fd9\u91cc\u5b9e\u9645\u4e0a\u5c31\u5c06\u4e00\u96bb\u7ebf\u6bb5\u5206\u6210\u4e86\u4e09\u4e2a\u5224\u5b9a\u70b9\uff0c\u7ebf\u6bb5\u53f3\u7aef\u7684\u70b9\u548c\u53f3\u8fb9\u90bb\u5c45\u7684\u5de6\u7aef\u70b9\u76f8\u4e92\u91cd\u53e0\uff0c\u8bf7\u770b\u4e0b\u56fe\u3002<\/p>\n<p><bk><bk><br \/>\n<div id=\"attachment_2154\" style=\"width: 490px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/03\/2146Illustration_2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2154\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2011\/03\/2146Illustration_2.png\" alt=\"Illustration 2\" title=\"[2146]Illustration_2\" width=\"480\" height=\"320\" class=\"size-full wp-image-2154\" \/><\/a><p id=\"caption-attachment-2154\" class=\"wp-caption-text\">Illustration 2. \u5c06\u4e00\u6761\u7ebf\u6bb5\u5206\u5272\u6210\u4e09\u5757\uff0c\u8fd9\u5f20\u56fe\u5e94\u8be5\u53ef\u8bf4\u660e\u8fd9\u4e48\u505a\u7684\u5965\u5999\u3002<\/p><\/div><br \/>\n<bk><\/p>\n<pre lang=\"cpp\" file=\"1.cpp\">\r\n#include <iostream>\r\n#include <cstdio>\r\n#include <vector>\r\n#include <stack>\r\n#include <set>\r\n#include <algorithm>\r\nusing namespace std;\r\nconst int N = 8000;\r\n\r\nstruct Tnode{\r\n\tint l, r, c;\r\n\tint left, right;\r\n} _T[2*N+1]; \/\/?\r\n\r\nint root, total;\r\n\r\nstruct Seg{\r\n    int key, pos, sign;\r\n    int id;\r\n    friend bool operator <(Seg a, Seg b){\r\n        return a.key < b.key || a.key == b.key &#038;&#038; a.sign > b.sign;\r\n    }\r\n} L[2*N+1];\r\nstruct Re{\r\n    int key, id;\r\n\tRe(): key(0), id(0) {}\r\n\tRe(int a, int b) :key(a), id(b) {}\r\n    friend bool operator <(Re a, Re b){\r\n        return a.key < b.key;\r\n    }\r\n} A[N];\r\n\r\n\r\nset<int> hash;\r\nvector<int> adj[N];\r\nbool removed[N];\r\nint n ,ans;\r\n\r\nvoid _build(int &now, int a, int b){\r\n\tnow = total++;\r\n\t\r\n\t_T[now].l = a, _T[now].r = b, _T[now].c = -1;\r\n\tif (a<b){\r\n\t\tint m = (a + b) \/ 2;\r\n\t\t_build(_T[now].left, a, m);\r\n\t\t_build(_T[now].right, m+1, b);\r\n\t}\r\n}\r\n\r\nvoid _insert(int now, int x, int id){\r\n\t\r\n\t\/\/cout << _T[now].l << \" \" << _T[now].r << endl;\r\n\t\r\n\tif (_T[now].l == _T[now].r)\r\n\t\t_T[now].c = id;\r\n\telse {\r\n\t\tint m = (_T[now].l + _T[now].r) \/ 2;\r\n\t\tif (x <= m) _insert(_T[now].left, x, id);\r\n\t\telse _insert(_T[now].right, x, id);\r\n\t\t\r\n\t\t_T[now].c = (_T[_T[now].left].c==-1 &#038;&#038; _T[_T[now].right].c==-1) ? -1 : 1;\r\n\t}\r\n}\r\n\r\n\r\nint _predecessor(int now, int x){\r\n\tif (_T[now].c == -1) return -1;\r\n\tif (_T[now].l == _T[now].r)\r\n\t\treturn _T[now].c;\r\n\telse {\r\n\t\tint m = (_T[now].l + _T[now].r) \/ 2;\r\n\t\tif (x <= m) return _predecessor(_T[now].left, x);\r\n\t\telse {\r\n\t\t\tint _Right = _predecessor(_T[now].right, x);\r\n\t\t\tif (_Right == -1) return _predecessor(_T[now].left, x);\r\n\t\t\telse return _Right;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nint _successor(int now, int x){\r\n\tif (_T[now].c == -1) return -1;\r\n\tif (_T[now].l == _T[now].r)\r\n\t\treturn _T[now].c;\r\n\telse {\r\n\t\tint m = (_T[now].l + _T[now].r) \/ 2;\r\n\t\tif (x > m) return _successor(_T[now].right, x);\r\n\t\telse {\r\n\t\t\tint _Left = _successor(_T[now].left, x);\r\n\t\t\tif (_Left == -1) return _successor(_T[now].right, x);\r\n\t\t\telse return _Left;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n\r\n\r\nbool isVisible(int a, int b){\r\n    if (a > b) swap(a, b);\r\n    return hash.find(a*N+b)!=hash.end();\r\n}\r\n\r\n\r\nvoid addEdge(int a, int b){\r\n    if (a > b) swap(a, b);\r\n    if (hash.find(a*N+b)!=hash.end()) return;\r\n    adj[a].push_back(b), adj[b].push_back(a);\r\n    A[a].key++, A[b].key++;\r\n    hash.insert(a*N+b);\r\n}\r\n\r\n\r\nvoid init1(){\r\n\tmemset(L, 0, sizeof(L));\r\n    cin >> n;\r\n\t\r\n    int l, r, p;\r\n    for (int i=0;i<n;i++){\r\n        scanf(\"%d%d%d\", &#038;l, &#038;r, &#038;p);\r\n        L[2*i].key = l, L[2*i].sign = 1;\r\n        L[2*i+1].key = r, L[2*i+1].sign = -1;\r\n        L[2*i].pos = L[2*i+1].pos = p;\r\n        L[2*i].id = i;\r\n    }\r\n    sort(L, L+2*n);\r\n    memset(adj, 0, sizeof(adj));\r\n    hash.clear();\r\n\t\r\n\tmemset(A, 0, sizeof(A));\r\n\tfor (int i=0;i<n;i++) A[i].id = i;\r\n\ttotal = 0, _build(root, 0, N);\r\n\t\r\n\tint i = 0, ii, cur;\r\n\tint _L, _M, _R;\r\n\t\r\n\twhile (i<2*n){\r\n\t\tcur = L[i].key;\r\n\t\tii = i;\r\n        while (L[ii].sign==1 &#038;&#038; L[ii].key==cur){\r\n            _insert(root, L[ii].pos, L[ii].id);\r\n\t\t\tii++;\r\n        }\r\n\t\t\r\n\t\tfor (int j=i;j<ii;j++){\r\n\t\t\t_M = L[j].id;\r\n\t\t\t_L = L[j].pos!=0 ? _predecessor(root, L[j].pos-1) : -1;\r\n\t\t\tif (_L!=-1) addEdge(_L, _M);\r\n\t\t\t_R = L[j].pos!=N ? _successor(root, L[j].pos+1) : -1;\r\n\t\t\tif (_R!=-1) addEdge(_M, _R);\r\n\t\t\t\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\t\r\n        i = ii;\r\n\t\t\r\n        while (L[ii].sign==-1 &#038;&#038; L[ii].key==cur){\r\n            _insert(root, L[ii].pos, -1);\r\n            ii++;\r\n        }\r\n\t\t\r\n\t\t\r\n\t\tfor (int j=i;j<ii;j++){\r\n\t\t\tif (L[j].pos!=0 &#038;&#038; L[j].pos!=N){\r\n\t\t\t\t_L = _predecessor(root, L[j].pos-1); if (_L == -1) continue;\r\n\t\t\t\t_R = _successor(root, L[j].pos+1); if (_R == -1) continue;\r\n\t\t\t\taddEdge(_L, _R);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\t\r\n        i = ii;\r\n\t}\r\n\t\r\n\t\r\n}\r\n\r\n\r\nvoid init0(){\r\n    memset(L, 0, sizeof(L));\r\n    cin >> n;\r\n\t\r\n    int l, r, p;\r\n    for (int i=0;i<n;i++){\r\n        scanf(\"%d%d%d\", &#038;l, &#038;r, &#038;p);\r\n        L[2*i].key = l, L[2*i].sign = 1;\r\n        L[2*i+1].key = r, L[2*i+1].sign = -1;\r\n        L[2*i].pos = L[2*i+1].pos = p;\r\n        L[2*i].id = i;\r\n    }\r\n    sort(L, L+2*n);\r\n    memset(adj, 0, sizeof(adj));\r\n    hash.clear();\r\n\t\r\n    memset(A, 0, sizeof(A));\r\n    for (int i=0;i<n;i++) A[i].id = i;\r\n\t\r\n    int i = 0, ii, cur;\r\n\tset<Re> T; \/\/ The Binary-Search-Tree recorded the Seg position ...\r\n\tset<Re>::iterator XL, X, XR;\r\n\t\r\n    while (i<2*n){\r\n        cur = L[i].key;\r\n        ii = i;\r\n        while (L[ii].sign==1 &#038;&#038; L[ii].key==cur){\r\n            T.insert(Re(L[ii].pos, L[ii].id));\r\n\t\t\tii++;\r\n        }\r\n\t\t\r\n\t\tif (T.size()>=2){\r\n\t\t\tfor (int j=i;j<ii;j++){\r\n\t\t\t\tX = T.find(Re(L[j].pos, -1));\r\n\t\t\t\t\r\n\t\t\t\tif (X!=T.begin()){\r\n\t\t\t\t\tXL = X, XL--;\r\n\t\t\t\t\taddEdge(XL->id, X->id);\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tXR = X, XR++;\r\n\t\t\t\tif (XR!=T.end())\r\n\t\t\t\t\taddEdge(X->id, XR->id);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t\r\n        i = ii;\r\n\t\t\r\n        while (L[ii].sign==-1 && L[ii].key==cur){\r\n\t\t\tT.erase(Re(L[ii].pos, -1));\r\n            ii++;\r\n        }\r\n\t\t\r\n\t\tif (T.size()>=2){\r\n\t\t\tfor (int j=i;j<ii;j++){\r\n\t\t\t\tT.insert(Re(L[j].pos, -1)), X = T.find(Re(L[j].pos, -1));\r\n\t\t\t\tXR = X, XR++;\r\n\t\t\t\tif (X!=T.begin() &#038;&#038; XR!=T.end()){\r\n\t\t\t\t\tXL = X, XL--;\r\n\t\t\t\t\taddEdge(XL->id, XR->id);\r\n\t\t\t\t}\r\n\t\t\t\tT.erase(X);\r\n\t\t\t}\r\n\t\t}\r\n        i = ii;\r\n\t\t\r\n    }\r\n}\r\n\r\n\r\nvoid stat2(){\r\n    memset(removed, false, sizeof(removed));\r\n    \r\n\tstack<int> S;\r\n\tfor (int i=0;i<n;i++)\r\n\t\tif (A[i].key < 6) S.push(i);\r\n\t\r\n\tans = 0;\r\n\twhile (!S.empty()){\r\n\t\tint u = S.top(); S.pop();\r\n\t\tvector<int> temp;\r\n\t\t\r\n\t\tfor (int j=0;j<adj[u].size();j++){\r\n\t\t\tint v = adj[u][j];\t\t\t\r\n\t\t\tif (!removed[v]) {\r\n\t\t\t\tif (A[v].key--==6) S.push(v);\r\n\t\t\t\ttemp.push_back(v);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tfor (int j1=0;j1<temp.size();j1++)\r\n\t\t\tfor (int j2=j1+1;j2<temp.size();j2++)\r\n\t\t\t\tif (isVisible(temp[j1], temp[j2])) ans++;\r\n\t\tremoved[u] = true;\r\n\t}\r\n}\r\n\r\nvoid stat1(){\r\n\tmemset(removed, false, sizeof(removed));\r\n\t\r\n\tans = 0;\r\n\tfor (int i=0;i<n;i++){\r\n\t\tint u = A[i].id;\r\n\t\tvector<int> temp;\r\n\t\t\r\n\t\tfor (int j=0;j<adj[u].size();j++){\r\n\t\t\tint v = adj[u][j];\r\n\t\t\tif (!removed[v]) {\r\n\t\t\t\ttemp.push_back(v);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tfor (int j1=0;j1<temp.size();j1++)\r\n\t\t\tfor (int j2=j1+1;j2<temp.size();j2++)\r\n\t\t\t\tif (isVisible(temp[j1], temp[j2])) ans++;\r\n\t\tremoved[u] = true;\r\n\t}\r\n}\r\n\r\nvoid stat0(){\r\n\tmemset(removed, false, sizeof(removed));\r\n\tsort(A, A+n);\r\n\t\r\n\tans = 0;\r\n\tfor (int i=0;i<n;i++){\r\n\t\tint u = A[i].id;\r\n\t\tvector<int> temp;\r\n\t\t\r\n\t\tfor (int j=0;j<adj[u].size();j++){\r\n\t\t\tint v = adj[u][j];\r\n\t\t\tif (!removed[v]) {\r\n\t\t\t\ttemp.push_back(v);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tfor (int j1=0;j1<temp.size();j1++)\r\n\t\t\tfor (int j2=j1+1;j2<temp.size();j2++)\r\n\t\t\t\tif (isVisible(temp[j1], temp[j2])) ans++;\r\n\t\tremoved[u] = true;\r\n\t}\r\n}\r\n\r\nvoid patch(){\r\n\tfor (int u=0;u<n;u++){\r\n\t\tcout << u << \":\";\r\n\t\tfor (int j=0;j<adj[u].size();j++){\r\n\t\t\tint v = adj[u][j];\r\n\t\t\tcout << \" \" << v; \r\n\t\t}\r\n\t\tcout << endl;\r\n\t}\r\n}\r\n\r\nint main(){\r\n\t\/\/freopen(\"h.in\", \"r\", stdin);\r\n\t\/\/freopen(\"h.out\", \"w\", stdout);\r\n\t\/\/freopen(\"in.txt\", \"r\", stdin);\r\n\t\r\n\tint d;\r\n\tcin >> d;\r\n\twhile (d--){\r\n\t\tinit1(); \/\/init0(); \/\/init1();\r\n\t\tstat0(); \/\/stat1(); stat2();\r\n\t\/\/\tpatch();\r\n\t\tcout << ans << endl;\r\n\t}\r\n}\r\n<\/pre>\n<pre lang=\"cpp\" file=\"2.cpp\">\r\n#include <iostream>\r\n#include <cstdio>\r\n#include <vector>\r\n#include <algorithm>\r\nusing namespace std;\r\nconst int N = 8000;\r\n\r\nstruct Tnode{\r\n\tint l, r, c;\r\n    int left, right;\r\n} T[4*N+1]; \/\/..?\r\nint root, total, _a, _b, _c, _x;\r\n\r\nstruct Seg{\r\n\tint l, r, key;\r\n\tfriend bool operator <(Seg a, Seg b){\r\n\t\treturn a.key < b.key;\r\n\t}\r\n} S[N];\r\n\r\nint hash[N];\r\nvector<int> adj[N];\r\nint n ,ans;\r\n\r\nvoid addEdge(int x, int y){\r\n\tadj[x].push_back(y);\r\n}\r\n\r\n\r\nvoid build(int& now, int a, int b){\r\n\tnow = total++;\r\n\tT[now].l = a, T[now].r = b, T[now].c = -1;\r\n\tif (a < b){\r\n\t\tint m = (a + b) \/ 2;\r\n\t\tbuild(T[now].left, a, m);\r\n\t\tbuild(T[now].right, m+1, b);\r\n\t}\r\n}\r\n\r\n\r\nvoid query(int now){\r\n\tif (T[now].c!=-1){\r\n\t\tif (hash[T[now].c]!=_c){\r\n\t\t\thash[T[now].c] = _c;\r\n\t\t\taddEdge(T[now].c, _c);\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\tif (T[now].l < T[now].r){\r\n\t\t\tint m = (T[now].l  + T[now].r) \/ 2;\r\n\t\t\tif (_a <= m) query(T[now].left); \t\r\n\t\t\tif (m < _b) query(T[now].right);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n\r\n\r\nvoid insert(int now){\r\n\tif (_a <= T[now].l &#038;&#038; T[now].r <= _b)\r\n\t\tT[now].c = _c;\r\n\telse{\r\n\t\tif (T[now].c != -1){\r\n\t\t\tT[T[now].left].c = T[T[now].right].c = T[now].c;\r\n\t\t\tT[now].c = -1;\r\n\t\t}\r\n\t\tint m = (T[now].l + T[now].r) \/ 2;\r\n\t\tif (_a <= m) insert(T[now].left);\r\n\t\tif (m < _b) insert(T[now].right);\r\n\t}\r\n}\r\n\r\n\r\nvoid init(){\r\n\tscanf(\"%d\", &#038;n);\r\n\tfor (int i=0;i<n;i++)\r\n\t\tscanf(\"%d%d%d\", &#038;S[i].l, &#038;S[i].r, &#038;S[i].key);\r\n\t\r\n\tsort(S, S+n), total = 0, build(root, 0, 2 * N);\r\n\tmemset(hash, -1, sizeof(hash));\r\n\tmemset(adj, 0, sizeof(adj));\r\n\tfor (int i=0;i<n;i++){\r\n\t\t_a = S[i].l * 2, _b = S[i].r * 2, _c = i;\r\n\t\tquery(root); insert(root);\r\n\t}\r\n}\r\n\r\n\r\nvoid stat(){\r\n\tans = 0;\r\n\tfor (int x=0;x<n;x++){\r\n\t\tmemset(hash, 0, sizeof(hash));\r\n\t\tfor (int i=0;i<adj[x].size();i++)\r\n\t\t\thash[adj[x][i]] = 1;\r\n\t\tfor (int i=0;i<adj[x].size();i++){\r\n\t\t\tint y = adj[x][i];\r\n\t\t\tfor (int j=0;j<adj[y].size();j++)\r\n\t\t\t\tif (hash[adj[y][j]]) ans++;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nvoid patch(){\r\n\tfor (int u=0;u<n;u++){\r\n\t\tcout << u << \":\";\r\n\t\tfor (int i=0;i<adj[u].size();i++)\r\n\t\t\tcout << \" \" << adj[u][i];\r\n\t\tcout << endl;\r\n\t}\r\n\t\r\n}\r\n\r\nint main(){\r\n\t\/\/freopen(\"in.txt\", \"r\", stdin);\r\n\tint d;\r\n\tcin >> d;\r\n\twhile (d--){\r\n\t\tinit(); stat(); \r\n\t\t\/\/patch();\r\n\t\tcout << ans << endl;\r\n\t}\r\n}\r\n\r\n<\/pre>\n<p><bk><bk><\/p>\n<h3>Further discussion :<\/h3>\n<p>1. \u65b9\u6cd5\u4e00\u7684\u4ee3\u7801\u5de8\u5927\u4e86\u70b9\uff0c\u4e3b\u8981\u662f\u60f3\u5c1d\u8bd5\u4e0d\u540c\u7684\u5199\u6cd5 ... \u4f46\u662f\u65f6\u95f4\u4f3c\u4e4e\u53d8\u5316\u90fd\u4e0d\u5927\uff0c\u5e73\u5747 0.88 s \u5de6\u53f3\uff0c\u65b9\u6cd5\u4e8c\u65f6\u95f4 0.40 s \u8981\u66f4\u5feb ...<br \/>\n2. \u53e6\u5916\u65b9\u6cd5\u4e8c\u8fd8\u6709\u8bf8\u591a\u597d\u5904\uff0c\u4f8b\u5982\u6784\u56fe\u65f6\u4ea7\u751f\u7684\u8fb9\u662f\u4e25\u683c\u6309\u7167\u4ece\u5750\u81f3\u53f3\u7684\u987a\u5e8f\u7684 ... \u53ef\u4ee5\u4e0d\u9700\u8981\u989d\u5916\u7684\u4e00\u5f20\u6563\u5217\u8868\u5224\u65ad\u4e24\u70b9\u4e4b\u95f4\u662f\u5426\u6709\u8fb9\u5b58\u5728 ...<br \/>\n3. \u5e73\u9762\u56fe (Planer graph) \u81f3\u5c11\u5305\u62ec\u4e00\u4e2a\u5ea6\u6570\u5c0f\u4e8e6\u7684\u70b9\uff1f\uff08\u7591\u4f3c\u662f\u5e93\u65af\u56fe\u65af\u57fa\u5b9a\u7406 (Kuratowski's Theorem) \u7684\u4e00\u4e2a\u63a8\u8bba\uff0c<a href=\"http:\/\/en.wikipedia.org\/wiki\/Planar_graph\">\u53c2\u89c1\u8fd9\u91cc ...<\/a>\uff09 <\/p>\n<h3>Reference : <\/h3>\n<p><a href=\"http:\/\/www.notonlysuccess.com\/?p=59\">\u2014\u2014 \u7ebf\u6bb5\u6811\u4e13\u8f91 notonlysuccess <\/a><br \/>\n<a href=\"http:\/\/hi.baidu.com\/c_loud26\/blog\/item\/d02152ff370eca9a9f514666.html\">poj 1436 Horizontally Visible Segments_\u4e91\u5377\u4e91\u8212_\u767e\u5ea6\u7a7a\u95f4<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description : \u7ed9\u5b9a\u4e00\u7ec4\u5782\u76f4\u7ebf\u6bb5\uff0c\u6c42\u5176\u4e2d\u5e73\u884c\u53ef\u89c1\u4e09\u89d2\u7684\u7ec4\u6570\u3002\u6240\u8c13\u7684\u53ef\u89c1\u4e09\u89d2\uff0c\u6307\u4e09\u7ec4\u7ebf\u6bb5\u4e4b\u95f4\u76f8\u4e92\u53ef\u89c1\u3002 Analyse : \u6b64\u9898\u8f83\u96be\u7f20\uff0c\u901a\u5e38\u53ef\u5206\u4e3a\u4ee5\u4e0b\u4e24\u4e2a\u4e3b\u8981\u6b65\u9aa4\u3002 1. \u6839\u636e\u51e0\u4f55\u53ef\u89c6\u5173\u7cfb\uff0c\u6784\u56fe\u3002 2. \u7edf\u8ba1\u53ef\u89c1\u4e09\u89d2\u7684\u7ec4\u6570\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-83","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-1l","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=83"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/83\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}