This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "fish.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= l; --x)
typedef long long ll;
using namespace std;
const int N = 100'032;
struct fish {
int pos = 0;
int weight = 0;
ll dpu = 0;
ll dpd = 0;
fish() {}
fish(int x) : pos(x) {}
fish(int x, int w) : pos(x), weight(w) {}
bool operator<(const fish &f) const { return pos < f.pos; }
};
vector<fish> a[N];
fish &nxt_up(vector<fish> &vec, fish &cur) { return *upper_bound(vec.begin(), vec.end(), cur); }
fish &nxt_do(vector<fish> &vec, fish &cur) { return *--lower_bound(vec.begin(), vec.end(), cur); }
long long max_weights(int n, int m, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
Loop (i,0,m)
a[X[i]].push_back(fish(Y[i], W[i]));
Loop (i,0,n) {
a[i].push_back(fish(-1));
a[i].push_back(fish(n));
sort(a[i].begin(), a[i].end());
}
LoopR (i,0,n) {
a[i].front().dpd = (i+1 < n? a[i+1].front().dpu: 0);
if (i+2 < n)
a[i].front().dpd = max(a[i].front().dpd, a[i+2].back().dpd);
Loop (j,1,a[i].size()) {
a[i][j].dpd = nxt_do(a[i], a[i][j]).dpd;
if (i+1 < n)
a[i][j].dpd = max(a[i][j].dpd, nxt_do(a[i+1], a[i][j]).dpd);
a[i][j].dpd += a[i][j].weight;
}
if (i == n-1)
continue;
a[i].back().dpu = (i+2 < n? a[i+2].back().dpd: 0);
LoopR (j,0,a[i].size()-1) {
a[i][j].dpu = nxt_up(a[i], a[i][j]).dpu;
if (i+1 < n)
a[i][j].dpu = max(a[i][j].dpu, nxt_up(a[i+1], a[i][j]).dpu);
a[i][j].dpu += a[i][j].weight;
}
}
return max(a[0].front().dpu, a[1].back().dpd);
}
Compilation message (stderr)
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:3:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<fish>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
| ^
fish.cpp:40:3: note: in expansion of macro 'Loop'
40 | Loop (j,1,a[i].size()) {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |