QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#105388#6136. AirdropSorting#AC ✓883ms25888kbC++233.3kb2023-05-13 23:48:532023-05-13 23:48:55

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-13 23:48:55]
  • 评测
  • 测评结果:AC
  • 用时:883ms
  • 内存:25888kb
  • [2023-05-13 23:48:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=4e5+1;
#define fi first
#define se second

#define all(x) (x).begin(), (x).end()

int n;
ll x[N],y[N];
vector<int> mp2[N];
map<ll,int>dx;
void add(ll l,ll r,ll v){
    //cout << "add " << l << ' ' << r << ' ' << v << endl;
    if(v==0) return;
    dx[l]+=v;
    dx[r+1]-=v;
}
void solve(){
    ll y0;
    cin >> n >> y0;
    dx.clear();
    {//
        ll sex=-2e18;sex+=1;
        dx[sex]=0;
    }

    vector<ll> coords;
    for(int i=1; i<=n ;i++){
        cin >> x[i] >> y[i];
        y[i]-=y0;
    }

    for(int i = 1; i <= n; ++i){
        coords.push_back(-x[i] + abs(y[i]));
    }

    sort(all(coords));
    coords.resize(unique(all(coords)) - coords.begin());

    for(int i = 1; i <= n; ++i){
        int idx = lower_bound(all(coords), -x[i] + abs(y[i])) - coords.begin();
        mp2[idx].push_back(i);
    }

    for(int j = 0; j < coords.size(); ++j){
        auto &c = mp2[j];
        if(c.empty()) continue;
        //cout << "doingL " << e.fi << endl;
        vector<pair<int,int> >v;
        for(auto d:c) v.push_back({x[d],d});
        sort(v.begin(),v.end());
        int chp=0;
        for(int i=0; i<v.size() ;i++){
            if(i!=v.size()-1 && v[i+1].fi==v[i].fi) continue;
            ll cur=v[i].fi;
            ll nxt=2e18;
            if(i+1!=v.size()) nxt=v[i+1].fi;
            if(i>0 && v[i-1].fi==v[i].fi){
                add(cur,cur,2+chp);
                chp=0;
            }
            else{
                add(cur,cur,chp+1);
                chp^=1;
                add(cur+1,nxt-1,chp);
            }
        }
    }

    
    for(int i = 0; i < coords.size(); ++i)
        mp2[i].clear();
    coords.clear();

    for(int i = 1; i <= n; ++i){
        coords.push_back(x[i] + abs(y[i]));
    }

    sort(all(coords));
    coords.resize(unique(all(coords)) - coords.begin());

    for(int i = 1; i <= n; ++i){
        int idx = lower_bound(all(coords), x[i] + abs(y[i])) - coords.begin();
        mp2[idx].push_back(i);
    }

    for(int j = 0; j < coords.size(); ++j){
        auto &c = mp2[j];
        if(c.empty()) continue;

        //cout << "doingR " << e.fi << endl;
        vector<pair<int,int> >v;
        for(auto d:c) v.push_back({x[d],d});
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        int chp=0;
        for(int i=0; i<v.size() ;i++){
            if(i!=v.size()-1 && v[i+1].fi==v[i].fi) continue;
            ll cur=v[i].fi;
            ll nxt=-2e18;
            if(i+1!=v.size()) nxt=v[i+1].fi;
            if(i>0 && v[i-1].fi==v[i].fi){
                add(cur,cur,chp);
                chp=0;
            }
            else{
                add(cur,cur,chp);
                chp^=1;
                add(nxt+1,cur-1,chp);
            }
        }
    }
    ll cur=0;
    ll mn=2e18;
    ll mx=-2e18;
    for(auto d:dx){
        if(d.fi>1.5e18) break;
        cur+=d.se;
        mn=min(mn,cur);
        mx=max(mx,cur);
    }
    cout << mn << ' ' << mx << '\n';

    for(int i = 0; i < coords.size(); ++i)
        mp2[i].clear();
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int t;cin >> t;
    while(t--) solve();
}

詳細信息

Test #1:

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

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: 883ms
memory: 25888kb

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