不得不说是一道比较烦人的题。。细节比较多

由于没给xy范围所以必须先离散化。。之后再开2个BIT,以y值为下标维护点的个数,在枚举x时,一个BIT维护x左边的点个数,另一个维护x右边的点,然后在枚举的时候主要按点对BIT进行维护,对每个点进行差分求方案,对每个x求得最优方案后还要记录方案来求oli的得分。。

然后记得输出oli得分要去重。。




#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define eps 1e-8
#define inf 1000000007
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define ls T[i<<1]
#define rs T[i<<1|1]
#define op T[i]
#define mid (x+y>>1)
#define NM 200005
#define nm 2000005
#define pi 3.141592653
using namespace std;
int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}




int tot,c[NM];
int n,m,tmp[NM],a[NM],b[NM],x[NM],y[NM],ans,_ans;
void add(int x,int t){for(;x<=n;x+=lowbit(x))a[x]+=t;}
int sum(int x,int s=0){for(;x;x-=lowbit(x))s+=a[x];return s;}

void _add(int x,int t){for(;x<=n;x+=lowbit(x))b[x]+=t;}
int _sum(int x,int s=0){for(;x;x-=lowbit(x))s+=b[x];return s;}

bool cmp(int x,int y){return a[x]<a[y];}
bool _cmp(int x,int y){return b[x]<b[y];}

int main(){
freopen("data.in","r",stdin);
while(m=read()){
mem(a);mem(b);mem(x);mem(y);ans=_ans=tot=0;
inc(i,1,m)a[i]=read(),b[i]=read();
inc(i,1,m)tmp[i]=i;
sort(tmp+1,tmp+1+m,_cmp);
a[0]=b[0]=inf;tot=0;
inc(k,1,m){
int i=tmp[k];
if(b[tmp[k-1]]!=b[i])tot++;
y[i]=tot;
}
n=tot;tot=0;
sort(tmp+1,tmp+1+m,cmp);
inc(k,1,m){
int i=tmp[k];
if(a[tmp[k-1]]!=a[i])tot++;
x[i]=tot;
}
mem(a);mem(b);
//inc(i,1,m)printf("%d ",x[i]);putchar('\n');
//inc(i,1,m)printf("%d ",y[i]);putchar('\n');
inc(i,1,m)_add(y[i],1);
inc(k,1,m){
int _x;
for(int j=k;x[tmp[j]]==x[tmp[k]];j++)_add(y[tmp[j]],-1);
int s=inf;
for(int j=k;x[tmp[j]]==x[tmp[k]];j++){
int t=sum(y[tmp[j]]-1)+_sum(n)-_sum(y[tmp[j]]);
if(t<s){_x=y[tmp[j]];s=t;}
}
if(s>ans){ans=s;c[_ans=1]=sum(n)-sum(_x)+_sum(_x-1);}
else if(s==ans)c[++_ans]=sum(n)-sum(_x)+_sum(_x-1);
add(y[tmp[k]],1);
while(x[tmp[k]]==x[tmp[k+1]])add(y[tmp[++k]],1);
}
printf("Stan: %d; Ollie:",ans);
sort(c+1,c+1+_ans);
c[0]=inf;
inc(i,1,_ans)if(c[i]!=c[i-1])printf(" %d",c[i]);puts(";");
}
return 0;
}






Brownie Points II


Time Limit: 5000MS

 

Memory Limit: 65536K

Total Submissions: 2744

 

Accepted: 884


Description


Stan and Ollie play the game of Odd Brownie Points. Some brownie points are located in the plane, at integer coordinates. Stan plays first and places a vertical line in the plane. The line must go through a brownie point and may cross many (with the same x-coordinate). Then Ollie places a horizontal line that must cross a brownie point already crossed by the vertical line.
Those lines divide the plane into four quadrants. The quadrant containing points with arbitrarily large positive coordinates is the top-right quadrant.

The players score according to the number of brownie points in the quadrants. If a brownie point is crossed by a line, it doesn't count. Stan gets a point for each (uncrossed) brownie point in the top-right and bottom-left quadrants. Ollie gets a point for each (uncrossed) brownie point in the top-left and bottom-right quadrants.

Stan and Ollie each try to maximize his own score. When Stan plays, he considers the responses, and chooses a line which maximizes his smallest-possible score.


Input


Input contains a number of test cases. The data of each test case appear on a sequence of input lines. The first line of each test case contains a positive odd integer 1 < n < 200000 which is the number of brownie points. Each of the following n lines contains two integers, the horizontal (x) and vertical (y) coordinates of a brownie point. No two brownie points occupy the same place. The input ends with a line containing 0 (instead of the n of a test).


Output


For each input test, print a line of output in the format shown below. The first number is the largest score which Stan can assure for himself. The remaining numbers are the possible (high) scores of Ollie, in increasing order.


Sample Input


11 3 2 3 3 3 4 3 6 2 -2 1 -3 0 0 -3 -3 -3 -2 -3 -4 3 -7 0


Sample Output


Stan: 7; Ollie: 2 3;


Source


​Waterloo local 2005.06.11​


[​​Submit​​​]   [Go Back]   [​​Status​​​]   [​​Discuss​​]