Submission #609513

#TimeUsernameProblemLanguageResultExecution timeMemory
609513MohamedAliSaidaneMeetings (IOI18_meetings)C++14
0 / 100
2984 ms506748 KiB
#include <bits/stdc++.h> #include "meetings.h" using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpi; typedef vector<pll> vpl; #define pb push_back #define popb pop_back #define all(x) (x).begin(),(x).end() #define ff first #define ss second const ll INF = 1e18; const int nax = 1e5 + 4; ll sp[nax][20], A[nax]; int LG[nax]; int n, q; void build() { for(int i = 0 ; i < n; i++) sp[i][0] = A[i]; for(int j = 1; j < 20; j ++) for(int i = 0 ; i + (1 << j) <= n; i ++) sp[i][j] = max(sp[i][j - 1], sp[i + (1 << (j-1))][j - 1]); } ll rmq(int l, int r) { if(l > r) swap(l, r); int j = LG[r - l + 1]; return max(sp[l][j], sp[r - (1 << j) + 1][j]); } vll minimum_costs(vi H, vi L, vi R) { n = H.size(); for(int i = 0 ; i < n; i ++) A[i] = H[i]; q = L.size(); LG[1] = 0 ; for(int i= 2; i <= n;i ++) LG[i] = LG[i/2] + 1; build(); ll pref[n][n + 1]; for(int i = 0; i < n;i ++) { pref[i][0] = 0ll; for(int j = 0 ; j < n ;j++) { pref[i][j + 1] = pref[i][j] + rmq(i, j); } } vll ans(q, INF); for(int query = 0; query < q; query ++) { int l = L[query]; int r = R[query]; for(int i = l; i <= r; i ++) { ans[i] = min(ans[i], pref[i][r + 1] - pref[i][l]); } } return ans; }
#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...