QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#94996#6136. AirdropGeorge_Plover#AC ✓458ms15412kbC++232.1kb2023-04-08 16:22:112023-04-08 16:22:15

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-08 16:22:15]
  • 评测
  • 测评结果:AC
  • 用时:458ms
  • 内存:15412kb
  • [2023-04-08 16:22:11]
  • 提交

answer

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rof(i,a,b) for(int i=(a);i>=(b);i--)
template<class T> void chkmin(T &x,T y){if(y<x)x=y;}
template<class T> void chkmax(T &x,T y){if(y>x)x=y;}
typedef long long ll;
typedef pair<int,int> pii;
const int N=100005,INF=1000000007,M=100001;
int n,yy0;
int b[N*2],ans[N*2];
int ax[N*2],lenax;
pii p[N];
map<int,int> ma[N];
void lsh(int a[],int &len)
{
    sort(a+1,a+len+1);
    int l=1;
    For(i,2,len)
        if(a[i]!=a[l])a[++l]=a[i];
    len=l;
}
void Main()
{
    scanf("%d%d",&n,&yy0);
    For(i,1,n)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        p[i]={x,abs(y-yy0)};
        ma[x][p[i].second]++;
        ax[++lenax]=x;
        ans[x]++;
    }
    lsh(ax,lenax);
    For(i,1,lenax)ax[lenax+i]=ax[i]+1;
    lenax*=2; ax[++lenax]=ax[1]-1;
    lsh(ax,lenax);
    int cnt=0;
    For(i,1,lenax)
    {
        int x=ax[i];
        ans[x]+=cnt;
        //printf("1:x=%d,cnt=%d\n",x,cnt);
        for(auto [y,z]:ma[x])
            if(z==1)
            {
                b[M-x+y]^=1;
                if(b[M-x+y])cnt++;
                else cnt--;
            }
            else
            {
                if(b[M-x+y])cnt--;
                b[M-x+y]=0;
            }
    }
    For(i,1,n)b[M-p[i].first+p[i].second]=0;
    cnt=0;
    Rof(i,lenax,1)
    {
        int x=ax[i];
        ans[x]+=cnt;
        //printf("2:x=%d,cnt=%d\n",x,cnt);
        for(auto [y,z]:ma[x])
            if(z==1)
            {
                b[x+y]^=1;
                if(b[x+y])cnt++;
                else cnt--;
            }
            else
            {
                if(b[x+y])cnt--;
                b[x+y]=0;
            }
    }
    For(i,1,n)b[p[i].first+p[i].second]=0;
    int ans1=INF,ans2=0;
    For(i,1,lenax)chkmin(ans1,ans[ax[i]]),chkmax(ans2,ans[ax[i]]),ans[ax[i]]=0;
    For(i,1,n)ma[p[i].first].clear();
    lenax=0;
    printf("%d %d\n",ans1,ans2);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)Main();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3 2
1 2
2 1
3 5
3 3
2 1
2 5
4 3
2 3
1 3
4 3

output:

1 3
0 3
2 2

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 458ms
memory: 15412kb

input:

3508
6 1
7 1
1 1
9 1
10 1
3 1
4 1
3 8
8 9
8 7
1 8
9 5
10 1
10 8
10 2
5 1
9 9
5 9
10 9
6 4
4 7
6 7
10 5
3 8
9 5
9 9
7 5
4 7
10 5
6 9
9 5
6 6
9 3
3 2
5 1
3 8
6 4
5 9
10 2
2 9
10 10
10 8
4 1
7 1
6 1
3 1
5 1
2 4
9 3
3 3
4 5
3 8
9 6
9 9
6 3
9 5
9 3
2 9
9 1
9 2
4 1
5 4
5 6
6 5
9 8
4 1
2 1
5 1
7 1
3 1
9 10...

output:

6 6
1 3
1 5
2 6
2 6
0 2
4 4
2 2
4 4
4 7
4 4
9 9
4 6
0 3
2 6
2 2
2 6
10 10
9 9
1 3
2 4
0 2
2 4
4 7
6 6
9 9
2 2
2 2
3 5
1 4
2 2
1 1
3 5
4 7
3 6
1 1
5 7
5 5
1 3
2 2
1 7
1 1
4 6
2 4
2 6
2 4
1 7
2 4
9 9
0 3
1 1
3 8
2 2
2 2
9 9
3 7
4 4
4 6
2 5
0 2
2 5
3 3
0 4
4 4
2 4
2 2
4 6
6 6
6 6
0 2
2 6
2 4
2 6
2 5
1 ...

result:

ok 7016 numbers