Submission #1306883

#TimeUsernameProblemLanguageResultExecution timeMemory
1306883vtnoo메기 농장 (IOI22_fish)C++17
58 / 100
1095 ms17508 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];
ll best[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],W[i]});
		sort(ALL(s[X[i]]));
	}
	inc.init(); 
	decs.init();
	inc.upd(0,0);
	fore(i,0,n-1){
		ll ant=decs.get();
		decs.upd(n,inc.get());
		for(auto&[p,w]:s[i]){
			inc.upd(p+1,w+inc.que(0,p));
		}
		inc.upd(0,best[i]);
		reverse(ALL(s[i+1]));
		for(auto&[p,w]:s[i+1]){
			ll val=w+decs.que(p+1,n);
			best[i+1]=max(best[i+1],val);
			decs.upd(p,val);
		}
		inc.upd(0,ant);
		reverse(ALL(s[i+1]));
		//~ cout<<endl;
		//~ fore(j,0,n+1){
			//~ cout<<inc.que(j,j)<<" ";
		//~ }
		//~ cout<<endl;
		//~ fore(j,0,n+1){
			//~ cout<<decs.que(j,j)<<" ";
		//~ }
		//~ cout<<endl;
	}
	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...