Submission #611847

#TimeUsernameProblemLanguageResultExecution timeMemory
611847JomnoiMeetings (IOI18_meetings)C++17
0 / 100
2676 ms21952 KiB
#include <bits/stdc++.h> #include "meetings.h" using namespace std; const int MAX_N = 75e4 + 5; const long long INF = 1e18 + 7; int N, Q; long long H[MAX_N]; pair <int, int> table[MAX_N][20]; vector <int> graph[MAX_N]; pair <int, int> getMax(int l, int r) { int j = log2(r - l + 1); return max(table[l][j], table[r - (1<<j) + 1][j]); } int build_tree(int l, int r) { if(l > r) { return -1; } int u = getMax(l, r).second; int L = build_tree(l, u - 1); int R = build_tree(u + 1, r); if(L != -1) { graph[u].push_back(L); } if(R != -1) { graph[u].push_back(R); } return u; } long long dfs(int u, int l, int r, long long total = 0) { long long now = total + H[u] * max(0, (r - l + 1)); for(auto v : graph[u]) { if(v < u) { now = min(now, dfs(v, l, u - 1, total + H[u] * max(0, (r - u + 1)))); } else { now = min(now, dfs(v, u + 1, r, total + H[u] * max(0, (u - l + 1)))); } } return now; } vector <long long> minimum_costs(vector <int> h, vector <int> L, vector <int> R) { N = h.size(), Q = L.size(); for(int i = 1; i <= N; i++) { H[i] = h[i - 1]; table[i][0] = make_pair(H[i], i); } for(int j = 1; j < 20; j++) { for(int i = 1; i + (1<<j) - 1 <= N; i++) { table[i][j] = max(table[i][j - 1], table[i + (1<<(j - 1))][j - 1]); } } build_tree(1, N); vector <long long> C; for(int i = 0; i < Q; i++) { L[i]++, R[i]++; C.push_back(dfs(getMax(L[i], R[i]).second, L[i], R[i])); } 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...