QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#518679#9141. Array Spreaducup-team3215WA 1ms3860kbC++201.8kb2024-08-14 00:34:232024-08-14 00:34:23

Judging History

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

  • [2024-09-18 18:58:44]
  • hack成功,自动添加数据
  • (/hack/840)
  • [2024-09-18 18:53:02]
  • hack成功,自动添加数据
  • (/hack/839)
  • [2024-08-14 00:34:23]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3860kb
  • [2024-08-14 00:34:23]
  • 提交

answer

#include <algorithm>
#include <array>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  for (int tc = (cin >> tc, tc); tc--; ) {
    int n; cin >> n >> n;
    vector<int> pts;
    vector<array<int, 2>> v(n);
    for (auto& [l, r]: v) cin >> l >> r, pts.insert(pts.end(), {--l, r});
    sort(pts.begin(), pts.end());
    pts.erase(unique(pts.begin(), pts.end()), pts.end());
    for (auto& v: v) for (auto& v: v) v = lower_bound(pts.begin(), pts.end(), v) - pts.begin();
    vector<int> mi, ma;
    auto check = [&](int w0, int w1) {
      mi.assign(pts.size() + 1, 0);
      ma.assign(pts.size() + 1, 1 << 30);
      ma[0] = 0;
      for (int _ = mi.size(); _--; ) {
        for (auto [l, r]: v) {
          mi[r] = max(mi[r], mi[l] + w0);
          ma[r] = min(ma[r], ma[l] + w1);
          mi[l] = max(mi[l], mi[r] - w1);
          ma[l] = min(ma[l], ma[r] - w0);
          if (mi[l] > ma[l] || mi[r] > ma[r]) return 0;
        }
        for (int i = 1; i < mi.size(); ++i) mi[i] = max(mi[i], mi[i - 1]);
        for (int i = mi.size() - 1; i--; ) ma[i] = min(ma[i], ma[i + 1]);
        for (int i = mi.size(); i--; ) if (mi[i] > ma[i]) return 0;
      }
      return 1;
    };
    vector<array<int, 2>> u;
    for (int q = 1; q <= n; ++q)
    for (int p = q; p <= n; ++p) if (gcd(p, q) == 1) u.push_back({p, q});
    sort(u.begin(), u.end(), [](auto& a, auto& b) { return a[0] * b[1] < a[1] * b[0]; });
    int l = -1, r = u.size() - 1;
    while (r > l + 1) {
      int m = (l + r) / 2;
      (check(u[m][1], u[m][0])? r: l) = m;
    }
    int64_t p = u[r][0], q = u[r][1];
    while (p % q) p += 998244353;
    cout << p / q << '\n';
  }
}

详细

Test #1:

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

input:

3
3 3
1 3
2 3
1 2
12 6
2 3
5 7
1 9
4 8
1 2
7 11
4 5
3 4
2 3
1 2
4 4
1 1

output:

1
2
499122178

result:

ok 3 number(s): "1 2 499122178"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3800kb

input:

2000
1000000000 1
259923446 367011266
1000000000 1
882434225 971573327
1000000000 1
41585677 470369580
1000000000 1
371902212 947250194
1000000000 1
787209148 924205796
1000000000 1
259074809 960876164
1000000000 1
148079314 188254573
1000000000 1
940091047 948318624
1000000000 1
40636497 743979446
...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 2000 numbers

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3512kb

input:

1000
1000000000 5
575330909 661595447
708422488 913945134
658050911 930246647
786571892 904549453
851755566 969150871
1000000000 2
198072104 844159589
8876188 644559580
1000000000 2
740802634 976972118
783909534 898449184
1000000000 2
871819537 941611957
465883854 640988372
1000000000 1
99458969 462...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

wrong answer 146th numbers differ - expected: '2', found: '1'