QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#457931 | #8831. Chemistry Class | ucup-team896# | RE | 0ms | 0kb | C++14 | 2.3kb | 2024-06-29 14:51:26 | 2024-06-29 14:51:28 |
answer
#include <bits/stdc++.h>
#ifdef dbg
#define D(...) fprintf(stderr, __VA_ARGS__)
#define DD(...) D("[Debug] "#__VA_ARGS__ " = "), \
debug_helper::debug(__VA_ARGS__), D("\n")
#include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T> void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }
using namespace std;
const int maxn = 400010;
int n, dp[maxn], cnt[maxn], t[maxn << 2];
ll A, B, a[maxn];
#define mid ((l + r) >> 1)
void upd(int c, int l, int r, int x, int v) {
if (l == r) return chkmx(t[c], v), void();
if (x <= mid) upd(c << 1, l, mid, x, v);
else upd(c << 1 | 1, mid + 1, r, x, v);
t[c] = max(t[c << 1], t[c << 1 | 1]);
}
int qry(int c, int l, int r, int x, int y) {
if (l == x && r == y) return t[c];
if (y <= mid) return qry(c << 1, l, mid, x, y);
else if (x > mid) return qry(c << 1 | 1, mid + 1, r, x, y);
else return max(qry(c << 1, l, mid, x, mid), qry(c << 1 | 1, mid + 1, r, mid + 1, y));
}
#undef mid
void work() {
cin >> n >> A >> B;
rep (i, 1, 2 * n) cin >> a[i];
rep (i, 1, (n + 1) << 2) t[i] = -1e9;
sort(a + 1, a + 2 * n + 1);
rep (i, 1, n) cnt[i] = cnt[i - 1] + (a[2 * i + 1] - a[2 * i] <= B);
rep (i, 0, n) dp[i] = -1e9;
dp[0] = 0, upd(1, 0, n, 0, 0);
int lima = 0, limb = 0;
rep (i, 1, n) {
while (a[2 * i] - a[2 * lima + 1] > A) lima++;
while (a[2 * i] - a[2 * limb + 1] > B) limb++;
if (lima <= i - 1) {
int val = qry(1, 0, n, lima, i - 1) + cnt[i - 1];
chkmx(dp[i], val);
}
if (limb <= i - 1) {
int val = qry(1, 0, n, limb, i - 1) + cnt[i - 1] + 1;
chkmx(dp[i], val);
}
upd(1, 0, n, i, dp[i] - cnt[i]);
}
if (dp[n] < 0) cout << "-1\n";
else cout << dp[n] << '\n';
}
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
int t; cin >> t;
while (t--) work();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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