/**
_ _ __ _ _ _ _ _ _
|a ||t ||o d | |o |
| __ _| | _ | __| _ |
| __ |/_ | __ /__\ / _\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 100000;
const int M_MAX = 300000;
const ll INF = LLONG_MAX / 3;
int N, M;
int X[M_MAX + 2], Y[M_MAX + 2], W[M_MAX + 2];
vector <int> onX[N_MAX + 2];
ll Fen[N_MAX + 2];
vector <int> updi;
void init () {
while (updi.empty() == false) {
Fen[updi.back()] = -INF;
updi.pop_back();
}
}
void update (int pos, ll val) {
for (int i = pos; i <= N; i += i & -i) {
updi.push_back(i);
Fen[i] = max(Fen[i], val);
}
}
ll query (int pos) {
ll val = -INF;
for (int i = pos; i >= 1; i -= i & -i) {
val = max(val, Fen[i]);
}
return val;
}
ll dpUp[M_MAX + 2];
ll dpDown[M_MAX + 2];
ll fullUp[M_MAX + 2];
ll fullDown[M_MAX + 2];
ll max_weights (int _N, int _M, vector <int> _X, vector <int> _Y, vector <int> _W) {
N = _N; M = _M;
for (int i = 1; i <= M; i++) {
X[i] = _X[i - 1] + 1;
Y[i] = _Y[i - 1] + 1;
W[i] = _W[i - 1];
onX[X[i]].push_back(i);
}
fill(Fen + 1, Fen + N + 1, -INF);
fullUp[0] = -INF;
for (int x = 1; x <= N; x++) {
sort(onX[x].begin(), onX[x].end(), [&] (const int &i, const int &j) {
return Y[i] < Y[j];
});
init();
update(1, fullDown[x]);
for (int i : onX[x - 1]) {
update(Y[i], dpUp[i]);
}
for (int i : onX[x]) {
dpUp[i] = query(Y[i] - 1) + W[i];
update(Y[i], dpUp[i]);
}
fullUp[x + 1] = query(N);
reverse(onX[x].begin(), onX[x].end());
init();
update(1, fullUp[x - 1]);
for (int i : onX[x - 1]) {
update((N - Y[i] + 1), dpDown[i]);
}
for (int i : onX[x]) {
dpDown[i] = query((N - Y[i] + 1) - 1) + W[i];
update((N - Y[i] + 1), dpDown[i]);
}
fullDown[x + 1] = query(N);
reverse(onX[x].begin(), onX[x].end());
}
return max(fullDown[N + 1], fullUp[N]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
89 ms |
11964 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '40313049006569' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
5040 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
5040 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
89 ms |
11964 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '40313049006569' |
2 |
Halted |
0 ms |
0 KB |
- |