Topic Link: Click to open the link
The main topic: there is a horizontal axis, there is n this operation, 0 represents a new edge on the horizontal axis, 1 for the deletion of 1 edges, where 0 x represents the beginning of the X position to add an edge, when the second edge, when the edge length of i,1 x represents the deletion of the X-plus edge. When a new edge is added, the side can contain a few sides intact.
Why did not do this problem,,, has been tears Ben,,,
The question is how many edges can be covered by the new side, and the count of the left end of the added edge is greater than or equal to the number of the left end of the new Edge X, the right endpoint of the added edge is greater than the number Y of the new Edge's right endpoint. Then the newly-covered edges are X-y,,,,
The number of left endpoints and the number of right endpoints are maintained with a tree-like array respectively. And then calculate. Because the endpoint location is relatively large, the first discretization of all the endpoints, and then the direct statistics.
#include <cstdio> #include <cstring> #include <algorithm>using namespace std; #define MAXN 200010struct node{int k, S, E;} P[MAXN], QUE[MAXN]; int n, M, cnt; int c[maxn<<1][2]; int a[maxn<<1]; int search1 (int x) {int low = 1, Mid, High = m; while (low <= high) {mid = (low + high)/2; if (a[mid] = = x) return mid; if (A[mid] < x) Low = mid + 1; else high = mid-1; }}int lowbit (int x) {return x & x;} void Add (int i,int j,int k) {while (i) {c[i][j] + = k; I-= lowbit (i); }}int sum (int i,int j) {int ans = 0; while (I <= m) {ans + = c[i][j]; i + = Lowbit (i); } return ans; int main () {int step = 0; int I, J; while (scanf ("%d", &n)! = EOF) {cnt = m = 1; for (i = 1; I <= n; i++) {scanf ("%d%d", &P[I].K, &P[I].S); if (!P[I].K) {a[m++] = P[I].S; a[m++] = P[I].E = p[i].s+cnt; cnt++; }} sort (a+1,a+m); m = Unique (a+1,a+m)-A; for (i = 1; I <= n; i++) {if (P[I].K) continue; P[i].s = Search1 (P[I].S); P[I].E = Search1 (P[I].E); } memset (C,0,sizeof (c)); CNT = 1; printf ("Case #%d:\n", ++step); for (i = 1; I <= n; i++) {if (P[I].K) {Add (que[p[i].s].s,0,-1); Add (que[p[i].s].e,1,-1); } else{que[cnt++] = p[i]; printf ("%d\n", SUM (p[i].s,0)-sum (p[i].e+1,1)); Add (p[i].s,0,1); Add (p[i].e,1,1); }}} return 0;}
Copyright NOTICE: Reprint Please specify source: Http://blog.csdn.net/winddreams
HDU5372 (more than 2015 schools 7)--segment Game (tree-like array)