제출 #244088

#제출 시각아이디문제언어결과실행 시간메모리
244088crossing0ver모임들 (IOI18_meetings)C++17
0 / 100
27 ms1664 KiB
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define vi vector<int>
#define fi first
#define se second
#define local

#ifndef local
#include "meetings.h"
#endif
using namespace std;
int Q,n;
vector<ll> small(vi H,vi L,vi R) {
	vector<ll> T(Q);
	for (int i = 0; i < Q; i++) {
		int l = L[i], r = R[i];
		stack<ll> st;
		ll sum = 0;
		vector<ll> ans(n),bans(n);
		for (int x = l ; x <= r; x++) {
			int e = 1;
			if (st.size() && st.top() < H[x]) {
				sum -= st.top();
				st.pop();
				e++;
			}
			while (e--) st.push(H[x]), sum += H[x];
			ans[x] = sum;
		}
		while(!st.empty()) st.pop();
		 sum = 0;
		for (int x = r; x >= l; x--) {
			int e = 1;
			if (st.size() && st.top() < H[x]) {
				sum -= st.top();
				st.pop();
				e++;
			}
			while(e--) st.push(H[x]), sum += H[x];
			sum -= H[x];
			ans[i] += sum;
		}
		ll mn = LLONG_MAX;
		for (int i = l; i <= r; i++) mn = min(mn,ans[i]);
		T[i] = mn;
	}
	return T;
}
vector<ll> minimum_costs(vi H, vi L,vi R) {
  n = H.size(); Q = L.size();
  if (n <= 5000 && Q <= 5000) return small(H,L,R);
  std::vector<long long> C(Q);
  for (int j = 0; j < Q; ++j) {
    C[j] = H[L[j]];
  }
  return C;
}
#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...