4548: Kit's candy time limit:10 Sec Memory limit:256 MB
submit:103 solved:47
[Submit] [Status] [Discuss] Description
There are N colored candies on the plane. The little whim takes a horizontal line in the plane and picks up all the candies above or below it. To find the most
How many candies are made, so that the obtained candies do not contain all the colors. Input
Contains multiple sets of test data, and the first line enters a positive integer T to indicate the number of test data groups.
Next T group test data, for each group of test data, the first line input two positive integers N, K, respectively, the number of points and colors. Next N lines, each line describes a point, the first two digits x, y (|x|, |y|≤2^30-1) describe the position of the point, and the last number Z (1≤z≤k) describes the color of the point. For 100% of data, N≤100000,k≤100000,t≤3output
Outputs a non-negative integer ans for each set of data in a row, indicating the answer
Sample Input1
10 3
1 2 3
2 1 1
2 4 2
3 5 3
4 4 2
5 1 2
6 3 1
6 7 1
7 2 3
9 4 2
Sample Output5Hintsource
by Hzwer
3658:jabberwocky time limit:20 Sec Memory limit:1024 MB
submit:178 solved:73
[Submit] [Status] [Discuss] Description
There are n points on the plane, one of the K colors for each point.
You can select a horizontal segment to get all the points above or below it:
Ask for the maximum number of points you can get so that the points you get don't contain all the colors.
Input
Contains multiple sets of test data, and the first line enters a number T to indicate the number of test data groups.
Next T Group test data, for each group of test data, the first line entered two number n,k, respectively, the number of points and the number of colors.
The next n lines describe a point, the first two numbers z,y (lxl,lyl≤2^32-1) describe the position of the point, and the last number Z (1≤z≤k) describes the color of the point.
Output
For each set of data output one line, each line is a number of ans, which represents the answer.
Sample Input1
10 3
1 2 3
2 1 1
2 4 2
3 5 3
4 4 2
5 1 2
6 3 1
6 7 1
7 2 3
9 4 2
Sample Output5HINT
N<=100000,k<=100000,t<=3
Source
Solution
The idea of a better problem, originally thought can be converted into some kind of scanning line, but no fruit
First, by the y-coordinate, we assume that this line is infinitely low, when the answer corresponds to the maximum number of points in the middle of the next two same color
And then this line up, one-time Delete row
Maintain the position of the previous and the latter of the same color with a doubly linked list
Delete, delete this point from the tree array and the linked list, delete each one, and count the adjacent and adjacent answers before the point.
And then you have to assign Y all to the opposite number, and then do it again to get the lower case.
Code
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;intRead () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9') {if(ch=='-') f=-1; Ch=GetChar ();} while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;} #defineMAXN 1000010intT,n,k,ans;structpointnode{intX,y,c,id;} P[MAXN]; intLs[maxn],tp,top;structlklist{intLast,nxt,now;} LK[MAXN]; intC[MAXN];structBIT {intTREE[MAXN]; voidInit () {memset (tree,0,sizeof(tree)); intLowbit (intx) {returnx& (-x);} voidADD (intPosintD) { for(intI=pos; i<=top+1; i+=lowbit (i)) Tree[i]+=D; } intQuery (intPOS) { intRe=0; for(intI=pos; I i-=lowbit (i)) Re+=Tree[i]; returnre; } intQuery (intLintR) {if(r<l)return 0;Else returnQuery (R)-query (l1);} }bit; BOOLCmpy (Pointnode A,pointnode B) {returna.y<B.y;} BOOLCMPX (Pointnode A,pointnode B) {returna.x<b.x;} voidSolve () {bit. Init (); memset (C,0,sizeof(C)); Sort (P+1, p+n+1, cmpx); lk[n+1].now=top+1; for(intI=1; i<=n; i++) bit. ADD (p[i].x,1); for(intI=1; i<=n; i++) {p[i].id=i; Lk[i].last=c[P[I].C]; lk[i].nxt=n+1; lk[i].now=p[i].x; if(c[p[i].c]) lk[c[p[i].c]].nxt=i; c[P[I].C]=i; Ans=max (ans,bit. Query (p[lk[i].last].x+1, p[i].x-1)); } //printf ("ans1=%d\n", ans);Sort (p+1, p+n+1, Cmpy); for(intI=1; i<=k; i++) ans=max (ans,bit. Query (lk[c[i]].now+1, top+1)); //printf ("ans2=%d\n", ans); for(intt=1, i=1; i<=n; i++) { intnow=p[i].id; while(T<=n && p[t].y==p[i].y) bit. ADD (p[t].x,-1), t++; if(LK[NOW].NXT) lk[lk[now].nxt].last=Lk[now].last; if(lk[now].last) lk[lk[now].last].nxt=lk[now].nxt; Ans=max (ans,bit. Query (lk[lk[now].last].now+1, lk[lk[now].nxt].now-1)); LK[NOW].NXT=lk[now].last=0; } //printf ("ans3=%d\n", ans);} intMain () {T=read (); while(t--) {N=read (), k=read (); Ans=0; for(intI=1; i<=n; i++) ls[++tp]=p[i].x=read (), P[i].y=read (), P[i].c=read (), p[i].id=i; Sort (LS+1, ls+tp+1); Top=unique (ls+1, ls+tp+1)-ls-1; for(intI=1; i<=n; i++) P[i].x=lower_bound (ls+1, ls+top+1, p[i].x)-ls; //for (int i=1; i<=n; i++) printf ("x=%d\n", p[i].x);Solve (); for(intI=1; i<=n; i++) p[i].y=-p[i].y; Solve (); printf ("%d\n", ans); } return 0; }
"bzoj-4548&3658" Kit candy &jabberwocky doubly linked list + tree array