QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#309167#6136. AirdropAlex_WeiAC ✓699ms14764kbC++143.1kb2024-01-20 15:18:122024-01-20 15:18:12

Judging History

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

  • [2024-01-20 15:18:12]
  • 评测
  • 测评结果:AC
  • 用时:699ms
  • 内存:14764kb
  • [2024-01-20 15:18:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;
using ull = unsigned long long;
using LL = __int128_t;

#define ppc(x) __builtin_popcount(x)
#define clz(x) __builtin_clz(x)

bool Mbe;

constexpr int mod = 1e9 + 7;
void addt(int &x, int y) {
  x += y, x >= mod && (x -= mod);
}
int add(int x, int y) {
  return x += y, x >= mod && (x -= mod), x;
}

struct FastMod {
  ull b, m;
  FastMod(ull b = 1) : b(b), m(ull((LL(1) << 64) / b)) {}
  ull reduce(ull a) {
    ull q = ull((LL(m) * a) >> 64);
    ull r = a - q * b; // can be proven that 0 <= r < 2 * b
    return r >= b ? r - b : r;
  }
} R;

// ---------- templates above ----------

constexpr int N = 3e5 + 5;
constexpr int V = 1e5 + 1;

int n, y;
int cnt, d[N], res[N];
struct point {
  int x, y;
  bool operator < (const point &z) const {
    return x != z.x ? x < z.x : abs(y - ::y) < abs(z.y - ::y);
  }
} c[N];

int cur, pt, buc[N], tp[N], vis[N], num, ap[N];
void init() {
  for(int i = 1; i <= num; i++) {
    buc[ap[i]] = vis[ap[i]] = tp[ap[i]] = 0;
  }
  cur = pt = num = 0;
}
int calc(int x) {
  while(pt < n && c[pt + 1].x < x) {
    int pos = V;
    if(c[++pt].y >= y) pos += c[pt].x - (c[pt].y - y);
    else pos += c[pt].x + (c[pt].y - y);
    if(!vis[pos]) ap[++num] = pos, vis[pos] = 1;
    if(pt < n && c[pt].x == c[pt + 1].x && c[pt].y + c[pt + 1].y == 2 * y) {
      if(tp[pos]) {
        buc[pos] ? cur-- : cur++;
        buc[pos] ^= 1;
      }
      tp[pos] = 1;
    }
    else tp[pos] ^= 1;
    buc[pos] ? cur-- : cur++;
    buc[pos] ^= 1;
  }
  return cur;
}

void solve() {
  cin >> n >> y, cnt = 0;
  map<int, int> mp;
  for(int i = 1; i <= n; i++) {
    cin >> c[i].x >> c[i].y;
    mp[c[i].x]++;
    d[++cnt] = c[i].x - 1;
    d[++cnt] = c[i].x;
    d[++cnt] = c[i].x + 1;
  }
  sort(d + 1, d + cnt + 1);
  cnt = unique(d + 1, d + cnt + 1) - d - 1;
  sort(c + 1, c + n + 1);
  init();
  for(int i = 1; i <= cnt; i++) {
    auto it = mp.find(d[i]);
    if(it != mp.end()) res[i] = it->second;
    else res[i] = 0;
    res[i] += calc(d[i]);
  }
  init();
  for(int i = 1; i <= n; i++) c[i].x = V - c[i].x;
  for(int i = 1; i <= cnt; i++) d[i] = V - d[i];
  reverse(c + 1, c + n + 1);
  reverse(d + 1, d + cnt + 1);
  reverse(res + 1, res + cnt + 1);
  init();
  for(int i = 1; i <= cnt; i++) res[i] += calc(d[i]);
  int mn = n, mx = 0;
  for(int i = 1; i <= cnt; i++) {
    mn = min(mn, res[i]);
    mx = max(mx, res[i]);
  }
  cout << mn << " " << mx << "\n";
}

bool Med;
signed main() {
  fprintf(stderr, "%.3lf MB\n", (&Mbe - &Med) / 1048576.0);
  // ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  #ifdef ALEX_WEI
    FILE* IN = freopen("1.in", "r", stdin);
    FILE* OUT = freopen("1.out", "w", stdout);
  #endif
  int T = 1;
  cin >> T;
  while(T--) solve();
  fprintf(stderr, "%.3lf ms\n", 1e3 * clock() / CLOCKS_PER_SEC);
  return 0;
}

/*
g++ a.cpp -o a -std=c++14 -O2 -DALEX_WEI
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7948kb

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: 699ms
memory: 14764kb

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