This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//by szh
#include<bits/stdc++.h>
#include "fish.h"
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
const int maxn = 300010;
ll tree[2][maxn],add[2][maxn];
int y[maxn];
int xmax,ymax;
vector <pii> fish[maxn];
ll hi0[maxn],hin[maxn];
ll sum[maxn];
void push_down(int id,int c) {
if (add[id][c]==0) return;
tree[id][c<<1] = max(tree[id][c<<1],add[id][c]);
add[id][c<<1] = max(add[id][c<<1],add[id][c]);
tree[id][c<<1|1] = max(tree[id][c<<1|1],add[id][c]);
add[id][c<<1|1] = max(add[id][c<<1|1],add[id][c]);
add[id][c]=0;
}
void update(int id,int c,int cl,int cr,int l,int r,ll val) {
if (l<=cl and cr<=r) {
add[id][c] = max(add[id][c],val);
tree[id][c] = max(tree[id][c],val);
return;
}
push_down(id,c);
int mid=cl+cr>>1;
if (l<=mid) update(id,c<<1,cl,mid,l,r,val);
if (r>mid) update(id,c<<1|1,mid+1,cr,l,r,val);
tree[id][c] = max(tree[id][c<<1],tree[id][c<<1|1]);
return;
}
ll query(int id,int c,int cl,int cr,int pos) {
if (cl==cr) return tree[id][c];
push_down(id,c);
int mid=cl+cr>>1;
if (pos<=mid) return query(id,c<<1,cl,mid,pos);
else return query(id,c<<1|1,mid+1,cr,pos);
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W) {
rep(i,0,M) {
y[i] = Y[i];
y[i]++;
fish[X[i]].pb({y[i],W[i]});
sum[X[i]]+=W[i];
}
rep(i,0,N) sort(ALL(fish[i]));
rep(i,1,N) {
//increasing
for (pair<int,ll> x:fish[i-1]) {
ll tmp = query(0,1,0,N,x.fi-1);
// debug(tmp);debug(x.fi),debug(x.se);
update(0,1,0,N,x.fi,N,tmp+x.se);
}
for (int j = SZ(fish[i])-1;j>=0;j--) {
pair<int,ll> x = fish[i][j];
// if (i==70) debug(x.fi);
ll tmp = query(1,1,0,N,x.fi);
update(1,1,0,N,0,x.fi-1,tmp+x.se);
}
hi0[i] = query(1,1,0,N,0);
hin[i] = query(0,1,0,N,N);
// rep(j,0,N+1) cout<<i<<" "<<j<<" "<<query(0,1,0,N,j)<<" "<<query(1,1,0,N,j)<<endl;
update(0,1,0,N,0,N,hi0[i-1]);
if (i>=2) update(1,1,0,N,0,N,hin[i-2]+sum[i-1]);
ll tmp1 = query(1,1,0,N,N), tmp2 = query(0,1,0,N,N);
update(0,1,0,N,N,N,max(tmp1,tmp2));
update(1,1,0,N,0,N,max(tmp1,tmp2));
// rep(j,0,N+1) cout<<i<<" "<<j<<" "<<query(0,1,0,N,j)<<" "<<query(1,1,0,N,j)<<endl;
}
return max(tree[0][1],tree[1][1]);
}
Compilation message (stderr)
fish.cpp: In function 'void update(int, int, int, int, int, int, long long int)':
fish.cpp:50:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
50 | int mid=cl+cr>>1;
| ~~^~~
fish.cpp: In function 'long long int query(int, int, int, int, int)':
fish.cpp:60:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
60 | int mid=cl+cr>>1;
| ~~^~~
# | 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... |