QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#825238#9776. Best Friend, Worst Enemyucup-team3161#TL 474ms17620kbC++173.2kb2024-12-21 17:50:092024-12-21 17:50:24

Judging History

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

  • [2024-12-21 17:50:24]
  • 评测
  • 测评结果:TL
  • 用时:474ms
  • 内存:17620kb
  • [2024-12-21 17:50:09]
  • 提交

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,bool fl=0){
    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;
        if(!fl) vis[u]=1;
    }
}

void rebuild(int qwq){
    R=max(qwq,1);
    mp.clear();
    For(i,1,nn) add(i,1);
    for(auto [x,y]:mp) if(y!=-1) vis[y]=1;
}

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);
    int cnt=0;
    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;
        int R1=max(mx/4-1,1);
        if(i==2 || R1>R*2){
            ++cnt;
            assert(cnt<=30);
            rebuild(R1);
        }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()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T=1;
    while(T--)work();
    return 0;
}
/*

*/


详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 13880kb

input:

2
1 5
1 10

output:

0
2

result:

ok 2 number(s): "0 2"

Test #2:

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

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: 2ms
memory: 13884kb

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: 0ms
memory: 15928kb

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: 0
Accepted
time: 474ms
memory: 17504kb

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:

0
2
4
7
12
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 384010 numbers

Test #6:

score: 0
Accepted
time: 374ms
memory: 16456kb

input:

400000
4991900 4984622
5004814 4985991
5008541 4983572
4988786 4997631
4995878 5010759
5026284 4998073
5034229 5000047
4983273 5019232
5007885 4993982
5010953 5021220
5026656 5007819
4976562 5013785
4978425 4988215
5000231 4977049
4987937 5023473
5024616 5009522
5002045 4977502
4988899 5014905
49866...

output:

0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 400000 numbers

Test #7:

score: 0
Accepted
time: 195ms
memory: 17600kb

input:

399999
420000 500000
420001 500001
420002 500002
420003 500003
420004 500004
420005 500005
420006 500006
420007 500007
420008 500008
420009 500009
420010 500010
420011 500011
420012 500012
420013 500013
420014 500014
420015 500015
420016 500016
420017 500017
420018 500018
420019 500019
420020 500020...

output:

0
2
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 399999 numbers

Test #8:

score: 0
Accepted
time: 83ms
memory: 17600kb

input:

400000
5000000 5000000
4637207 1362793
6296942 2296942
6971218 2971218
6214485 2214485
8086725 4086725
8414337 5585663
5685949 1685949
1702684 5702684
6472899 7527101
5941033 1941033
7192827 3192827
6379191 2379191
2347274 6347274
7180991 6819009
8685943 5314057
7160303 3160303
6928903 7071097
44215...

output:

0
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 400000 numbers

Test #9:

score: 0
Accepted
time: 80ms
memory: 17552kb

input:

399913
5000000 7000000
5000000 6000000
3000000 5000000
4000000 5000000
5000000 5000000
6000000 5000000
7000000 5000000
5000000 4000000
5000000 3000000
5357589 6392898
4901211 6444181
5188225 6102824
4788614 6242360
4802804 6288663
4734311 6103748
5031314 6227375
5100725 6211516
5247076 6358750
48076...

output:

0
2
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 399913 numbers

Test #10:

score: 0
Accepted
time: 88ms
memory: 15560kb

input:

400000
3000000 8000000
3012636 7948165
6021732 4424572
3110512 7383392
2224678 6167889
6730174 3825314
2667414 7371648
3292265 6926643
2241546 6521035
6270139 1705913
4006880 6643854
4088241 6232389
3768770 6333837
3755946 6344466
6239447 3896690
7067142 2259147
2791441 7083567
2045838 6505125
72353...

output:

0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 400000 numbers

Test #11:

score: 0
Accepted
time: 73ms
memory: 16452kb

input:

400000
4000000 1000000
2000000 4000000
3971122 1730490
4198723 1332093
1891848 4399763
3883748 1754618
1318432 3775511
3824641 1583152
1718804 3837530
1992199 4221010
1863470 4175370
1634863 4587694
4261069 1328631
1796332 3690458
1611836 4116653
1635254 4407379
1317068 4297964
4046238 1937867
14548...

output:

0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 400000 numbers

Test #12:

score: 0
Accepted
time: 81ms
memory: 16100kb

input:

400000
4000003 1000001
2000003 4000001
1681540 4618492
1721680 4192318
1986524 4256472
1682732 4538323
1731436 4480115
1471609 3827694
1879802 4357249
1140557 4064455
1809962 4461028
4628899 1636633
1535641 3964206
1953510 3671812
1904251 3298566
4092976 1434705
1481816 4156505
1609477 4445491
36394...

output:

0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 400000 numbers

Test #13:

score: 0
Accepted
time: 87ms
memory: 17620kb

input:

400000
4999997 8000001
3999997 5000001
5999997 5000001
5217659 2801801
5912267 2981691
4977175 2078224
4984213 2609315
5732901 2796477
4700507 2763210
4857500 7076015
5146689 7537378
4975916 2227084
5335767 2678476
5297317 2382545
4938482 2612155
5002716 7491341
4254058 7030846
4488940 2584804
48196...

output:

0
2
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 400000 numbers

Test #14:

score: 0
Accepted
time: 87ms
memory: 17600kb

input:

400000
4999998 7999993
3999998 4999993
5999998 4999993
4911385 2736908
5207358 7506133
5316688 2415833
4377390 7356539
5572531 2832663
5714897 7236169
4979803 2143629
4162191 2938526
4670816 7342922
4673690 7616930
5257771 2409424
5363441 7609733
5096353 7467363
5288304 7395497
4847351 2920398
49314...

output:

0
2
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 400000 numbers

Test #15:

score: -100
Time Limit Exceeded

input:

381785
5000000 5000000
4999998 5000000
5000001 5000001
5000002 5000000
5000001 4999999
5000000 4999998
4999999 5000001
4999999 4999999
5000000 5000002
5000003 5000001
5000003 4999999
5000001 5000003
4999996 5000000
4999998 4999998
4999998 5000002
5000001 4999997
4999999 5000003
4999999 4999997
50000...

output:

0
2
1
1
2
3
3
4
4
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result: