QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#463415#8831. Chemistry ClassMay_27thWA 203ms31344kbC++202.2kb2024-07-04 20:09:402024-07-04 20:09:40

Judging History

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

  • [2024-07-04 20:09:40]
  • 评测
  • 测评结果:WA
  • 用时:203ms
  • 内存:31344kb
  • [2024-07-04 20:09:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define i64 long long
#define i128 __int128
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
struct Tree{
  int n;
  vector<int64_t>lazy;
  vector<int64_t>st;
  Tree(int _n, int64_t _v): n(_n), st(_n * 4, _v), lazy(_n * 4, _v){};
  void push(int id){
    int64_t add = lazy[id];
    lazy[id * 2] += add, st[id * 2] += add;
    lazy[id * 2 + 1] += add, st[id * 2 + 1] += add;
    lazy[id] = 0;
  }
  void update(int id, int l, int r, int u, int v, int64_t val){
    if (v < l || u > r) return;
    if (u <= l && r <= v) {
      st[id] = val;
      // lazy[id] += val;
      return;
    }
    // push(id);
    int mid = (l + r)/2;
    update(id * 2, l, mid, u, v, val);
    update(id * 2 + 1, mid + 1, r, u, v, val);
    st[id] = max(st[id * 2], st[id * 2 + 1]);
  }
  i64 get(int id, int l, int r, int u, int v) {
    if (v < l || u > r) return -1000000000;
    if (u <= l && r <= v) return st[id];
    int mid = (l + r)/2;
    return max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
  }
};
void Solve(void) {
  int N; i64 A, B; cin >> N >> A >> B;
  vector<i64> a(2 * N);
  for (int i = 0; i < 2 * N; i ++) cin >> a[i];
  sort(all(a));
  Tree T(2 * N + 4, -10000000);
  T.update(1, 0, 2 * N, 0, 0, 0);
  for (int i = 1; i <= 2 * N; i ++) {
    int lf = lower_bound(all(a), a[i - 1] - A) - a.begin();
    int rg = i - 2;
    if (lf + 1 == i && a[i - 1] > A) continue;
    if (a[i - 1] <= A) rg = i - 1;
    i64 cur = T.get(1, 0, 2 * N, lf, rg);
    lf = lower_bound(all(a), a[i - 1] - B) - a.begin();
    // cout << i << " " << cur << " ";
    rg = i - 2;
    if (a[i - 1] <= B) rg = i - 1;
    cur = max(cur, T.get(1, 0, 2 * N, lf, rg) + 1);
    T.update(1, 0, 2 * N, i, i, cur);
    // cout << cur << "\n";
    // cout << i << " " << lf << " " << cur << "\n";
  }
  i64 ans = T.get(1, 0, 2 * N, 2 * N, 2 * N);
  if (ans <= 0) {
    cout << -1 << "\n";
    return;
  }
  cout << T.get(1, 0, 2 * N, 2 * N, 2 * N) << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(10);
  int Tests = 1; cin >> Tests;
  while (Tests --) {
    Solve();
  }
}

詳細信息

Test #1:

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

input:

4
1 2 1
42 69
2 3 1
1 2 3 4
2 5 1
6 1 3 4
5 19 1
1 7 8 9 10 11 12 13 14 20

output:

-1
2
1
4

result:

ok 4 number(s): "-1 2 1 4"

Test #2:

score: -100
Wrong Answer
time: 203ms
memory: 31344kb

input:

1
199996 67013419502794 1
403716252634677166 895717933735068492 410002430455111886 844431179242134559 322988383133810700 133475121268220299 481706326769800263 606871141911985391 195911124687409946 959578180866483093 930547702157856949 877914383714875160 994158366044742636 890855755285236186 69498488...

output:

-1

result:

wrong answer 1st numbers differ - expected: '0', found: '-1'