이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <cassert>
#include <vector>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pi;
#define all(x) x.begin(),x.end()
#define rll(x) x.rbegin(), x.rend()
struct segtree{
vector<ll> tree;
segtree(): tree(404040){}
void upd(ll node, ll s, ll e, ll i, ll d){
if(e<i or i<s)return;
if(s==e)tree[node] = max(tree[node], d);
else{
ll mid = s+e>>1;
upd(node<<1,s,mid,i,d); upd(node<<1|1,mid+1,e,i,d);
tree[node] = max(tree[node<<1],tree[node<<1|1]);
}
}
ll query(ll node, ll s, ll e, ll l, ll r){
if(e<l or r<s)return 0;
if(l<=s and e<=r)return tree[node];
ll mid = s+e>>1;
return max(query(node<<1,s,mid,l,r), query(node<<1|1,mid+1,e,l,r));
}
} lseg[3], rseg[3], useg, dseg;
vector<pi> dp1[101010], dp2[101010]; //l,r
vector<pi> v[101010];
map<pi,ll> mp;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
for(int i = 0 ; i < M ; i++){
v[X[i]].push_back({Y[i], W[i]});
mp[{X[i],Y[i]}] = W[i];
}
for(int i = 0 ; i < N ; i++){
sort(all(v[i]));
for(auto [j,_] : v[i])dp1[i].push_back({j,0});
dp2[i] = dp1[i];
}
ll ans = 0;
for(int i = 0 ; i < N ; i++){
for(auto j : {1, 2}){
if(i<j)break;
for(int k = 0 ; k < dp1[i-j].size() ; k++){
lseg[i-j].upd(1,0,N-1,dp1[i-j][k].first,dp1[i-j][k].second);
rseg[i-j].upd(1,0,N-1,dp2[i-j][k].first,dp2[i-j][k].second);
}
}
if(i>0)for(int j = (int)dp1[i].size()-1 ; j >= 0 ; j--){
dp1[i][j].second = max({dp1[i][j].second, useg.query(1,0,N-1,dp1[i][j].first+1,N-1), rseg[1].tree[1]});
dp1[i][j].second += mp[{i,dp1[i][j].first}];
ans = max(ans, dp1[i][j].second);
useg.upd(1,0,N-1,dp1[i][j].first,dp1[i][j].second);
}
if(i<N-1)for(int j = 0 ; j < dp2[i].size() ; j++){
dp2[i][j].second = max({dp2[i][j].second, dseg.query(1,0,N-1,0,dp2[i][j].first-1), lseg[2].tree[1], rseg[2].tree[1]});
dp2[i][j].second += mp[{i,dp2[i][j].first}];
ans = max(ans, dp2[i][j].second);
dseg.upd(1,0,N-1,dp2[i][j].first,dp2[i][j].second);
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
fish.cpp: In member function 'void segtree::upd(ll, ll, ll, ll, ll)':
fish.cpp:17:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
17 | ll mid = s+e>>1;
| ~^~
fish.cpp: In member function 'll segtree::query(ll, ll, ll, ll, ll)':
fish.cpp:25:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
25 | ll mid = s+e>>1;
| ~^~
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:47:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int k = 0 ; k < dp1[i-j].size() ; k++){
| ~~^~~~~~~~~~~~~~~~~
fish.cpp:58:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | if(i<N-1)for(int j = 0 ; j < dp2[i].size() ; j++){
| ~~^~~~~~~~~~~~~~~
# | 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... |