제출 #1306885

#제출 시각아이디문제언어결과실행 시간메모리
1306885vtnoo메기 농장 (IOI22_fish)C++17
100 / 100
200 ms21000 KiB
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,pao=b;i<pao;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
const ll INF=1e18;
int n;
vector<pair<int,int>>s[MAXN];
struct STree{
	ll st[MAXN*4];
	void init(){
		fore(i,0,MAXN*4)st[i]=-INF;
	}
	void upd(int p,ll x,int v=1,int s=0,int e=n+1){
		if(s==e){
			st[v]=max(st[v],x);
			return;
		}
		int m=(s+e)/2;
		if(p<=m)upd(p,x,v*2,s,m);
		else upd(p,x,v*2+1,m+1,e);
		st[v]=max(st[v*2],st[v*2+1]);
	}
	ll que(int ts,int te,int v=1,int s=0,int e=n+1){
		if(e<ts||te<s)return -INF;
		if(ts<=s&&e<=te)return st[v];
		int m=(s+e)/2;
		return max(que(ts,te,v*2,s,m),que(ts,te,v*2+1,m+1,e));
	}
	ll get(){
		return que(0,n+1);
	}
}inc,decs; //uno para los pilares crecientes y decrecientes
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
	n=N;
	fore(i,0,M){
		s[X[i]].pb({Y[i]+1,W[i]});
	}
	fore(i,0,n)sort(ALL(s[i]));
	inc.init(); 
	decs.init();
	inc.upd(0,0);
	fore(i,0,n-1){
		ll ant=decs.get();
		decs.upd(n+1,inc.get());
		for(auto&[p,w]:s[i]){
			inc.upd(p,w+inc.que(0,p-1));
		}
		inc.upd(0,ant);
		reverse(ALL(s[i+1]));
		for(auto&[p,w]:s[i+1]){
			decs.upd(p,w+decs.que(p+1,n+1));
		}
		reverse(ALL(s[i+1]));
	}
	return max(inc.get(),decs.get());
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...