QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#269881#6136. AirdropzlxFTHAC ✓706ms10960kbC++171.8kb2023-11-30 10:04:572023-11-30 10:04:57

Judging History

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

  • [2023-11-30 10:04:57]
  • 评测
  • 测评结果:AC
  • 用时:706ms
  • 内存:10960kb
  • [2023-11-30 10:04:57]
  • 提交

answer

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

#define debug(...) fprintf(stderr, __VA_ARGS__)

const int N = 1e5 + 5;
const int Inf = 1e9;

int n, m, Y, MN, MX;
int cnt[N], pos[3 * N], ans[3 * N];
struct Node {
  int x, y;
  bool operator<(const Node &b) const {
    return x < b.x;
  }
} a[N];

void solve() {
  MN = Inf, MX = -Inf, m = 0;
  cin >> n >> Y;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i].x >> a[i].y;
    cnt[a[i].x]++;
    pos[++m] = a[i].x - 1;
    pos[++m] = a[i].x;
    pos[++m] = a[i].x + 1;
  }
  sort(a + 1, a + n + 1);
  sort(pos + 1, pos + m + 1);
  m = unique(pos + 1, pos + m + 1) - pos - 1;
  int cur = 1;
  map<int, int> mp;
  for (int i = 1; i <= m; ++i) {
    int X = pos[i];
    ans[i] = cnt[X];
    vector<int> p;
    while (cur <= n && a[cur].x < X) {
      int d = -a[cur].x + abs(a[cur].y - Y);
      mp[d]++;
      p.push_back(d);
      cur++;
    }
    for (auto d : p) {
      if (mp.find(d) != mp.end() && mp[d] > 1) {
        mp.erase(mp.find(d));
      }
    }
    ans[i] += mp.size();
  }
  mp.clear();
  cur = n;
  for (int i = m; i; --i) {
    int X = pos[i];
    vector<int> p;
    while (cur >= 1 && a[cur].x > X) {
      int d = a[cur].x + abs(a[cur].y - Y);
      mp[d]++;
      p.push_back(d);
      cur--;
    }
    for (auto d : p) {
      if (mp.find(d) != mp.end() && mp[d] > 1) {
        mp.erase(mp.find(d));
      }
    }
    ans[i] += mp.size();
  }
  for (int i = 1; i <= m; ++i) {
    MN = min(MN, ans[i]);
    MX = max(MX, ans[i]);
    ans[i] = 0;
  }
  for (int i = 1; i <= n; ++i) {
    cnt[a[i].x]--;
  }
  cout << MN << " " << MX << "\n";
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}

詳細信息

Test #1:

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

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: 706ms
memory: 10960kb

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