QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#825108#9776. Best Friend, Worst Enemyucup-team3161#TL 3ms15980kbC++173.0kb2024-12-21 17:23:032024-12-21 17:23:13

Judging History

你现在查看的是最新测评结果

  • [2024-12-21 17:23:13]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:15980kb
  • [2024-12-21 17:23:03]
  • 提交

answer



// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define ull unsigned long long
//#define int long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	return f?-x:x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 400005
#define inf 0x3f3f3f3f

int n,x[maxn],y[maxn];
int mxx[23],mx;

bool vis[maxn];

int nn;

int R;
int rx,ry;
int tx[maxn],ty[maxn];

map<pii,int>mp;
void add(int u){
    int xx=x[u]/R,yy=y[u]/R;
    if(mp.count(mkp(xx,yy))){
        mp[mkp(xx,yy)]=-1;
    }else{
        mp[mkp(xx,yy)]=u;
        vis[u]=1;
    }
}

void rebuild(int qwq){
    R=max(qwq,1);
    mp.clear();
    For(i,1,nn) add(i);
}

int getmx(int x,int y){
    int mx=0;
    For(s,0,3){
        int sum=((s&1)?(-x):(x))+((s&2)?(-y):y);
        mx=max(mx,sum+mxx[s^3]);
    }
    return mx;
}

int d1[maxn],d2[maxn],res[maxn];
int mxs[maxn],mns[maxn];
int nxt[maxn];
void solve(int u){
    //cout<<"solve "<<u<<"\n";
    int mn=inf,mx=0;
    For(i,1,n){
        if(i!=u){
            mx=max(mx,abs(x[i]-x[u])+abs(y[i]-y[u]));
            mn=min(mn,max(abs(x[i]-x[u]),abs(y[i]-y[u])));
        }
        mxs[i]=mx;
        mns[i]=mn;
    }
    nxt[n]=n+1;
    Rep(i,n-1,1){
        nxt[i]=nxt[i+1];
        if(mns[i+1]!=mns[i] || mxs[i+1]!=mxs[i]) nxt[i]=i+1;
    }
    For(i,1,n){
        if(i!=u){
            int d1=abs(x[i]-x[u])+abs(y[i]-y[u]);
            int d2=max(abs(x[i]-x[u]),abs(y[i]-y[u]));
            
            int t=max(i,u);
            if(d1==mxs[t] && d2==mns[t]) {
                int t2=nxt[t];
                res[t]++;
                res[t2]--;
            }
        }
    }
}

void work()
{
    cin>>n;
    For(i,1,n)cin>>x[i]>>y[i];
    memset(mxx,-63,sizeof mxx);
    For(i,1,n){
        nn=i;
        int lstmx=mx;
        For(s,0,3){
            int sum=((s&1)?(-x[i]):(x[i]))+((s&2)?(-y[i]):y[i]);
            mx=max(mx,sum+mxx[s^3]);
        }
        For(s,0,3){
            int sum=((s&1)?(-x[i]):(x[i]))+((s&2)?(-y[i]):y[i]);
            mxx[s]=max(mxx[s],sum);
        }
        if(i==1) continue;
        if(i==2 || lstmx*2<mx){
            rebuild(mx/8);
        }else{
            add(i);
        }
    }
    For(i,1,n) if(vis[i]) {
        solve(i);
    }
    For(i,1,n){
        res[i]+=res[i-1];
        cout<<res[i]<<"\n";
    }
}

signed main()
{
    int T=1;
    while(T--)work();
    return 0;
}
/*

*/


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 15980kb

input:

2
1 5
1 10

output:

0
2

result:

ok 2 number(s): "0 2"

Test #2:

score: 0
Accepted
time: 3ms
memory: 15912kb

input:

4
2 5
5 3
5 7
8 5

output:

0
2
4
4

result:

ok 4 number(s): "0 2 4 4"

Test #3:

score: 0
Accepted
time: 0ms
memory: 15912kb

input:

9
3 4
3 6
4 3
4 7
5 5
6 3
6 7
7 4
7 6

output:

0
2
1
0
4
5
6
7
8

result:

ok 9 numbers

Test #4:

score: 0
Accepted
time: 2ms
memory: 13856kb

input:

13
3 5
4 4
4 5
4 6
5 3
5 4
5 5
5 6
5 7
6 4
6 5
6 6
7 5

output:

0
2
4
7
2
2
5
2
2
3
3
4
4

result:

ok 13 numbers

Test #5:

score: -100
Time Limit Exceeded

input:

384010
200000 1000000
200000 1000001
199999 1000000
200001 1000000
200000 999999
200000 1000002
200002 1000000
200000 999998
199998 1000000
199997 1000000
200003 1000000
200000 999997
200000 1000003
199996 1000000
200004 1000000
200000 1000004
200000 999996
199995 1000000
200000 1000005
200000 99999...

output:


result: