제출 #244096

#제출 시각아이디문제언어결과실행 시간메모리
244096crossing0ver모임들 (IOI18_meetings)C++17
0 / 100
58 ms83064 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;
ll DD[5005][5005];
vector<ll> small(vi H,vi L,vi R) {
	vector<ll> T(Q);
	vector<int> e = H,WW(n);
	sort(e.begin(),e.end());
	map<int,int> mp;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (i == 0 || e[i-1] != e[i]) {
			mp[e[i]] = cnt;
			WW[cnt] = e[i];
			cnt++;
		}
	}
	for (int i = 0; i < cnt; i++) {
		int val = WW[cnt];
		ll sum = 0;
		for (int j = 0; j < n; j++) {
			sum += max(H[j],val);
			DD[i][j] = sum;
		}
	}
	for (int i = 0; i < Q; i++) {
		int l = L[i], r = R[i];
		stack<ll> st;
		ll ans = LLONG_MAX;
		for (int x = l ; x <= r; x++) {
			int id = mp[H[x]];
			ll sum = DD[id][r] - (l ? DD[id][l-1] : 0);
			ans = min(ans,sum);
		}
		T[i] = ans;
	}
	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...