Submission #293476

#TimeUsernameProblemLanguageResultExecution timeMemory
293476GurbanMeetings (IOI18_meetings)C++17
0 / 100
18 ms1400 KiB
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll inf = 1e18;
const int mod = 1e9+7; //998244353;
const int maxn = 1e5+5;
const int Xg[4] = {1,0,-1,0}, Yg[4] = {0,1,0,-1};
ll modpw(ll a,ll e) {if(e==0)return 1;ll x=modpw(a*a%mod,e>>1);return e&1?x*a%mod:x;}

int cep[maxn],sag[maxn];
ll p[maxn];
ll jog[maxn];
stack<pii>s;

vll minimum_costs(vi H, vi L,vi R) {
	int Q=sz(L); vll C;
	if(	Q <= 5e3){
		for(int i = 0;i < Q;i++){
			for(int j = L[i];j <= R[i];j++) cep[j]=sag[j]=p[j]=jog[j]=0;
			while(!s.empty()) s.pop();
			for(int j = L[i];j <= R[i];j++){
				while(!s.empty() and s.top().ss <= H[j]) s.pop();
				if(!s.empty()) cep[j]=s.top().ff+1;	
				else cep[j]=L[i];
				s.push({j,H[j]});
			}
			while(!s.empty()) s.pop();
			for(int j = R[i];j >= L[i];j--){
				while(!s.empty() and s.top().ss < H[j]) s.pop();
				if(!s.empty()) sag[j]=s.top().ff-1;
				else sag[j]=R[i];
				s.push({j,H[j]});
			}
			for(int j = L[i];j <= R[i];j++){
				ll num=j-cep[j];
				ll num1= sag[j]-j;
				p[cep[j]] += ((num1+1)*H[j]);
				p[j] -= ((num1+1)*H[j]);
				p[j+1] += ((num+1)*H[j]);
				p[sag[j]+1] -= ((num+1)*H[j]);
				jog[j] = (num+num1+1)*H[j];
			}
			// for(int j = L[i];j <= R[i];j++) cout<<j<<' '<<cep[j]<<' '<<sag[j]<<'\n';
			ll ans = inf;
			for(int j = L[i];j <= R[i];j++){
				if(j) p[j] += p[j-1];
				ans = min(ans,p[j]+jog[j]);
				// cout<<p[j]+jog[j]<<' ';
			}
			// cout<<'\n';
			C.pb(ans);
		}
		return C;
	}
	else {
		return {0};
	}
}

#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...