QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#120130#6136. Airdrophos_lyricAC ✓324ms6456kbC++143.6kb2023-07-06 14:08:382023-07-06 14:08:41

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 14:08:41]
  • 评测
  • 测评结果:AC
  • 用时:324ms
  • 内存:6456kb
  • [2023-07-06 14:08:38]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


int N, Y0;
vector<int> X, Y;

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d%d", &N, &Y0);
    X.resize(N);
    Y.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d%d", &X[i], &Y[i]);
    }
    
    // (x, t)
    vector<pair<int, int>> ps(N);
    for (int i = 0; i < N; ++i) {
      ps[i] = make_pair(X[i], abs(Y[i] - Y0));
    }
    sort(ps.begin(), ps.end());
// cerr<<"ps = "<<ps<<endl;
    
    vector<int> ls(N + 1, 0), rs(N + 1, 0);
    {
      vector<int> zs(N);
      for (int i = 0; i < N; ++i) {
        zs[i] = ps[i].first - ps[i].second;
      }
      sort(zs.begin(), zs.end());
      zs.erase(unique(zs.begin(), zs.end()), zs.end());
      const int zsLen = zs.size();
      vector<int> freq(zsLen, 0);
      for (int i = 0; i < N; ++i) {
        const int pos = lower_bound(zs.begin(), zs.end(), ps[i].first - ps[i].second) - zs.begin();
        if (i - 1 >= 0 && ps[i - 1] == ps[i]) {
          ls[i + 1] = ls[i] - freq[pos];
          freq[pos] = 0;
        } else {
          ls[i + 1] = ls[i] + (freq[pos] ? -1 : +1);
          freq[pos] ^= 1;
        }
      }
    }
    {
      vector<int> zs(N);
      for (int i = 0; i < N; ++i) {
        zs[i] = ps[i].first + ps[i].second;
      }
      sort(zs.begin(), zs.end());
      zs.erase(unique(zs.begin(), zs.end()), zs.end());
      const int zsLen = zs.size();
      vector<int> freq(zsLen, 0);
      for (int i = N; --i >= 0; ) {
        const int pos = lower_bound(zs.begin(), zs.end(), ps[i].first + ps[i].second) - zs.begin();
        if (i + 1 < N && ps[i] == ps[i + 1]) {
          rs[i] = rs[i + 1] - freq[pos];
          freq[pos] = 0;
        } else {
          rs[i] = rs[i + 1] + (freq[pos] ? -1 : +1);
          freq[pos] ^= 1;
        }
      }
    }
// cerr<<"ls = "<<ls<<", rs = "<<rs<<endl;
    
    int ansMin = N + 1, ansMax = -1;
    
    // exact
    for (int i = 0, j; i < N; i = j) {
      for (j = i; j < N && ps[i].first == ps[j].first; ++j) {}
      chmin(ansMin, ls[i] + (j - i) + rs[j]);
      chmax(ansMax, ls[i] + (j - i) + rs[j]);
    }
    
    // between
    for (int i = 0; i <= N; ++i) if (i == 0 || i == N || ps[i - 1].first + 1 < ps[i].first) {
      chmin(ansMin, ls[i] + rs[i]);
      chmax(ansMax, ls[i] + rs[i]);
    }
    
    printf("%d %d\n", ansMin, ansMax);
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

详细

Test #1:

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

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: 324ms
memory: 6456kb

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