QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#91083#6136. AirdropValera_GrinenkoAC ✓559ms16012kbC++235.9kb2023-03-27 02:59:002023-03-27 02:59:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-27 02:59:02]
  • 评测
  • 测评结果:AC
  • 用时:559ms
  • 内存:16012kb
  • [2023-03-27 02:59:00]
  • 提交

answer

//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")

#ifdef __APPLE__

#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <immintrin.h>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>

#else
#include <bits/stdc++.h>
#endif

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

template<typename T>
bool umin(T &a, T b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool umax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#if __APPLE__
#define D for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl

template<class ...Ts>
auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }

#else
#define D while (false)
#define LOG(...)
#endif

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int testnum = 0;

const int max_n = 4e5 + 42;

int bruhl[max_n], bruhr[max_n];

void solve() {
    testnum++;
    int n, y0;
    cin >> n >> y0;
    vector<pair<int, int> > a(n);
    for(auto& x : a) cin >> x.fi >> x.se;
    vector<pair<int, int> > kek_l, kek_r;
    {
        vector<pair<int, int> > ops_l;
        ops_l.pb({-1e6, 0});
        unordered_map<int, vector<pair<int, int> > > groups;
        for(auto& x : a) {
            groups[abs(x.fi - (-1e6)) + abs(x.se - y0)].pb(x);
        }
        for(auto& x : groups) {
            if(len(x.se) == 1) continue;
            vector<pair<int, int> > cr;
            for(auto& cp : x.se) cr.pb({abs(y0 - cp.se), cp.fi});
            sort(all(cr));
            int cpos = -1;
            while(cpos + 2 < len(cr)) {
                if(cpos + 3 < len(cr) && cr[cpos + 3].fi == cr[cpos + 2].fi) { ops_l.pb({cr[cpos + 2].se, 3}); cpos += 3; }
                else { ops_l.pb({cr[cpos + 2].se, 2}); cpos += 2; }
            }
            ops_l.pb({-1e6, -(cpos + 1)});
        }
        sort(all(ops_l));
        int cur_am = 0;
        for(int i = 0; i < len(ops_l); i++) {
            int j = i;
            while(j + 1 < len(ops_l) && ops_l[j + 1].fi == ops_l[j].fi) j++;
            for(int k = i; k <= j; k++) cur_am += ops_l[k].se;
            i = j;
            kek_l.pb({ops_l[i].fi, cur_am});
        }
    }
    {
        vector<pair<int, int> > ops_r;
        unordered_map<int, vector<pair<int, int> > > groups;
        ops_r.pb({1e6, 0});
        for(auto& x : a) {
            groups[abs(x.fi - (1e6)) + abs(x.se - y0)].pb(x);
        }
        for(auto& x : groups) {
            if(len(x.se) == 1) continue;
            vector<pair<int, int> > cr;
            for(auto& cp : x.se) cr.pb({abs(y0 - cp.se), cp.fi});
            sort(all(cr));
            int cpos = -1;
            while(cpos + 2 < len(cr)) {
                if(cpos + 3 < len(cr) && cr[cpos + 3].fi == cr[cpos + 2].fi) { ops_r.pb({cr[cpos + 2].se, 3}); cpos += 3; }
                else { ops_r.pb({cr[cpos + 2].se, 2}); cpos += 2; }
            }
            ops_r.pb({1e6, -(cpos + 1)});
        }
        sort(all(ops_r)); reverse(all(ops_r));
        int cur_am = 0;
        for(int i = 0; i < len(ops_r); i++) {
            int j = i;
            while(j + 1 < len(ops_r) && ops_r[j].fi == ops_r[j + 1].fi) j++;
            for(int k = i; k <= j; k++) cur_am += ops_r[k].se;
            i = j;
            kek_r.pb({ops_r[i].fi, cur_am});
        }
        reverse(all(kek_r));
    }
    int mn_ans = 1e9, mx_ans = -1e9;
    vector<int> avpos;
    for(auto& x : kek_l) {
        avpos.pb(x.fi);
        avpos.pb(x.fi - 1);
        avpos.pb(x.fi + 1);
    }
    for(auto& x : kek_r) {
        avpos.pb(x.fi);
        avpos.pb(x.fi - 1);
        avpos.pb(x.fi + 1);
    }
    sort(all(avpos)); avpos.resize(unique(all(avpos)) - avpos.begin());
    for(int i = 0; i < len(kek_l); i++) {
        bruhl[std::lower_bound(avpos.begin(), avpos.end(), kek_l[i].fi) - avpos.begin()] += kek_l[i].se;
        if(i != len(kek_l) - 1) {
            bruhl[std::lower_bound(avpos.begin(), avpos.end(), kek_l[i + 1].fi) - avpos.begin()] -= kek_l[i].se;
        }
    }
    for(int i = 0; i < len(kek_r); i++) {
        bruhr[std::lower_bound(avpos.begin(), avpos.end(), kek_r[i].fi) - avpos.begin()] += kek_r[i].se;
        if(i != 0) {
            bruhr[std::lower_bound(avpos.begin(), avpos.end(), kek_r[i - 1].fi) - avpos.begin()] -= kek_r[i].se;
        }
    }
    for(int i = 1; i < len(avpos); i++) bruhl[i] += bruhl[i - 1];
    for(int i = len(avpos) - 2; i >= 0; i--) bruhr[i] += bruhr[i + 1];
    for(int i = 1; i + 1 < len(avpos); i++) {
        umin(mn_ans, n + bruhl[i] + bruhr[i]);
        umax(mx_ans, n + bruhl[i] + bruhr[i]);
        bruhl[i] = bruhr[i] = 0;
    }
    cout << mn_ans << ' ' << mx_ans << '\n';
}

signed main() {
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;

    cin >> t;

//    if(t == 3) {
//        cout << "1 3\n"
//                "0 3\n"
//                "2 2";
//        return 0;
//    }

    while (t--) solve();

}

/*
KIVI
*/

詳細信息

Test #1:

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

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: 559ms
memory: 16012kb

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