QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#458056 | #8831. Chemistry Class | ucup-team045# | WA | 115ms | 17196kb | C++20 | 3.2kb | 2024-06-29 15:32:21 | 2024-06-29 15:32:22 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<numeric>
#include<functional>
#include<algorithm>
using namespace std;
using LL = long long;
const int INF = 1e9;
struct Info {
int mx = -INF;
};
Info operator+(const Info &a, const Info &b){
return {max(a.mx, b.mx)};
}
template<class Info>
struct SegmentTree{
int n;
vector<Info> info;
SegmentTree() {}
SegmentTree(int n, Info _init = Info()){
init(vector<Info>(n, _init));
}
SegmentTree(const vector<Info> &_init){
init(_init);
}
void init(const vector<Info> &_init){
n = (int)_init.size();
info.assign((n << 2) + 1, Info());
function<void(int, int, int)> build = [&](int p, int l, int r){
if (l == r){
info[p] = _init[l];
return;
}
int m = (l + r) / 2;
build(2 * p, l, m);
build(2 * p + 1, m + 1, r);
pull(p);
};
build(1, 0, n - 1);
}
void pull(int p){
info[p] = info[2 * p] + info[2 * p + 1];
}
void modify(int p, int l, int r, int x, const Info &v){
if (l == r){
info[p] = v;
return;
}
int m = (l + r) / 2;
if (x <= m){
modify(2 * p, l, m, x, v);
}
else{
modify(2 * p + 1, m + 1, r, x, v);
}
pull(p);
}
void modify(int p, const Info &v){
modify(1, 0, n - 1, p, v);
}
Info query(int p, int l, int r, int x, int y){
if (l > y || r < x){
return Info();
}
if (l >= x && r <= y){
return info[p];
}
int m = (l + r) / 2;
return query(2 * p, l, m, x, y) + query(2 * p + 1, m + 1, r, x, y);
}
Info query(int l, int r){
return query(1, 0, n - 1, l, r);
}
};
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int T;
cin >> T;
while(T--){
int n; LL A, B;
cin >> n >> A >> B;
n *= 2;
vector<LL> a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a.begin() + 1, a.end());
vector<int> b(n + 2);
for(int i = n - 2; i >= 1; i -= 2){
if (a[i + 1] - a[i] <= B){
b[i] = 1;
}
}
for(int i = 1; i <= n + 1; i++){
b[i] += b[i - 1];
}
vector<int> pre(n + 1);
for(int i = n, j = n; i >= 1; i--){
while(j >= 1 and a[i] - a[j] <= A) j--;
pre[i] = j;
}
SegmentTree<Info> seg(n + 1);
seg.modify(0, {0});
vector<int> dp(n + 1, -1);
dp[0] = 0;
for(int i = 2; i <= n; i += 2){
if (a[i] - a[i - 1] <= B){
dp[i] = max(dp[i], dp[i - 2] + 1);
}
dp[i] = max(dp[i], seg.query(pre[i], i).mx + b[i - 1]);
seg.modify(i, {dp[i] - b[i + 1]});
}
cout << dp[n] << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3412kb
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: 0
Accepted
time: 111ms
memory: 17132kb
input:
1 199996 67013419502794 1 403716252634677166 895717933735068492 410002430455111886 844431179242134559 322988383133810700 133475121268220299 481706326769800263 606871141911985391 195911124687409946 959578180866483093 930547702157856949 877914383714875160 994158366044742636 890855755285236186 69498488...
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 115ms
memory: 17084kb
input:
1 199998 38987266278826 1 974183459404323858 517476981059568123 730207399881008603 532509909948600146 89227878552241675 16653300445469756 791674368913652595 92177901403222015 980536748304824579 581564387828767376 471919726893404451 759601909683722004 632340812998214017 818440789777778368 18845836031...
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 113ms
memory: 17032kb
input:
1 199996 54170919220045 1 968843690955781467 596307347951820347 406785475849275444 383666938223357986 725160735782817082 132577412512120631 891899794864087098 779434145671998619 932681297277907326 208765550447928461 385078857912267975 669360937040314510 917331948890514855 505938744714587815 47145437...
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 102ms
memory: 17020kb
input:
1 199998 35667463938291 8255384928693 770468016026697053 519790816750772730 110085058423772871 85144239858008037 782003096084947976 938498644167289660 693768718229582367 242186248813489674 155335549252315364 428982852761422230 890445026369869037 86401573937739054 9122788624365829 63351367715811463 1...
output:
193326
result:
ok 1 number(s): "193326"
Test #6:
score: -100
Wrong Answer
time: 100ms
memory: 17196kb
input:
1 199998 30382921668955 14233448082254 963132297376532181 199422464083525159 322744997549904069 484222268324755182 911994852231141516 486452603601138945 442934186247306449 697067018736912231 391585717434570522 682442472054944522 79264788486972294 313368204441969076 399649435615099454 810055146752799...
output:
143431
result:
wrong answer 1st numbers differ - expected: '-1', found: '143431'