QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142069 | #4561. Catfish Farm | bashkort# | 0 | 140ms | 19196kb | C++17 | 3.2kb | 2023-08-18 13:40:36 | 2024-07-04 02:39:37 |
Judging History
answer
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll inf = 3e18;
struct SegmentTree {
vector<ll> t, tag;
int sz = 1;
void init(int n) {
sz = 1 << __lg(n) + !!(n & (n - 1));
t.assign(sz << 1, -3e18), tag.assign(sz << 1, -3e18);
}
void apply(int x, ll tg) {
t[x] = max(t[x], tg);
tag[x] = max(tag[x], tg);
}
void push(int x) {
if (tag[x] > 0) {
apply(x << 1, tag[x]);
apply(x << 1 | 1, tag[x]);
tag[x] = -3e18;
}
}
void pull(int x) {
t[x] = max(t[x << 1], t[x << 1 | 1]);
}
ll rangeMax(int l, int r, int x, int lx, int rx) {
if (l >= rx || lx >= r) {
return -3e18;
}
if (l <= lx && rx <= r) {
return t[x];
}
int mid = lx + rx >> 1;
push(x);
return max(rangeMax(l, r, x << 1, lx, mid), rangeMax(l, r, x << 1 | 1, mid, rx));
}
ll rangeMax(int l, int r) {
return rangeMax(l, r, 1, 0, sz);
}
void rangeApply(int l, int r, ll tg, int x, int lx, int rx) {
if (l >= rx || lx >= r) {
return;
}
if (l <= lx && rx <= r) {
return apply(x, tg);
}
int mid = lx + rx >> 1;
push(x);
rangeApply(l, r, tg, x << 1, lx, mid);
rangeApply(l, r, tg, x << 1 | 1, mid, rx);
pull(x);
}
void rangeApply(int l, int r, ll tg) {
rangeApply(l, r, tg, 1, 0, sz);
}
};
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
SegmentTree t[2];
t[0].init(N + 1), t[1].init(N + 1);
t[0].rangeApply(0, 1, 0), t[1].rangeApply(0, 1, 0);
vector<vector<pair<int, int>>> adj(N + 1);
for (int i = 0; i < M; ++i) {
adj[X[i]].push_back({Y[i] + 1, W[i]});
}
for (int x = 0; x <= N; ++x) {
sort(adj[x].begin(), adj[x].end());
t[1].rangeApply(N, N + 1, t[0].rangeMax(N, N + 1));
if (x > 0) {
vector<ll> p{-inf};
for (auto [y, add] : adj[x - 1]) {
p.push_back(add + max(p.back(), t[0].rangeMax(0, y)));
}
int i = 0;
for (auto [y, add] : adj[x - 1]) {
t[0].rangeApply(y, N + 1, p[++i]);
}
}
t[0].rangeApply(0, 1, t[1].rangeMax(0, 1));
reverse(adj[x].begin(), adj[x].end());
vector<ll> p{-inf};
for (auto [y, add] : adj[x]) {
p.push_back(add + max(p.back(), t[1].rangeMax(y, N + 1)));
}
int i = 0;
for (auto [y, add] : adj[x]) {
t[1].rangeApply(0, y, p[++i]);
}
// cout << "dp[0]: ";
// for (int i = 0; i <= N; ++i) {
// cout << t[0].rangeMax(i, i + 1) << " ";
// }
// cout << endl;
// cout << "dp[1]: ";
// for (int i = 0; i <= N; ++i) {
// cout << t[1].rangeMax(i, i + 1) << " ";
// }
// cout << endl;
}
return t[1].rangeMax(0, 1);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 107ms
memory: 17680kb
input:
f785163bfcb92ce6ac387bba5d2f29a0e0f37f19 90000 80699 0 10792 55091480 0 36762 389250726 0 79267 706445371 0 76952 290301137 0 13444 69711795 0 68980 66221400 0 1695 703252611 0 36628 632571604 0 87676 264578012 0 79496 397448339 0 57929 447544332 0 35453 355374818 0 62449 686423696 0 45614 667165709...
output:
938f2698235a9ff1d1d91e23381b68bec7bed102 OK 0
result:
wrong answer 3rd lines differ - expected: '40313272768926', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 0ms
memory: 4036kb
input:
f785163bfcb92ce6ac387bba5d2f29a0e0f37f19 3 2 0 0 1 1 1 1
output:
938f2698235a9ff1d1d91e23381b68bec7bed102 OK 0
result:
wrong answer 3rd lines differ - expected: '2', found: '0'
Subtask #3:
score: 0
Wrong Answer
Test #20:
score: 0
Wrong Answer
time: 43ms
memory: 13620kb
input:
f785163bfcb92ce6ac387bba5d2f29a0e0f37f19 100000 1 0 0 10082010
output:
938f2698235a9ff1d1d91e23381b68bec7bed102 OK 0
result:
wrong answer 3rd lines differ - expected: '10082010', found: '0'
Subtask #4:
score: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 0ms
memory: 3784kb
input:
f785163bfcb92ce6ac387bba5d2f29a0e0f37f19 4 3 2 2 1 0 0 1 1 1 1
output:
938f2698235a9ff1d1d91e23381b68bec7bed102 OK 2
result:
wrong answer 3rd lines differ - expected: '3', found: '2'
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Wrong Answer
Test #60:
score: 0
Wrong Answer
time: 140ms
memory: 19196kb
input:
f785163bfcb92ce6ac387bba5d2f29a0e0f37f19 100000 99999 31026 31026 1 42940 42940 1 69303 69303 1 90350 90350 1 77507 77507 1 87126 87126 1 17988 17988 1 5146 5146 1 63023 63023 1 27776 27776 1 6136 6136 1 82557 82557 1 24904 24904 1 21667 21667 1 67271 67271 1 80294 80294 1 81145 81145 1 47144 47144 ...
output:
938f2698235a9ff1d1d91e23381b68bec7bed102 OK 99998
result:
wrong answer 3rd lines differ - expected: '99999', found: '99998'
Subtask #8:
score: 0
Skipped
Dependency #1:
0%