Submission #944973

#TimeUsernameProblemLanguageResultExecution timeMemory
944973gelastropodMeetings (IOI18_meetings)C++14
0 / 100
13 ms2004 KiB
#include "meetings.h" #include <bits/stdc++.h> using namespace std; #define int long long /* struct node { int s, e, m, v; node *l, *r; node (int _s, int _e) : s(_s), e(_e), m((_s + _e) / 2), v(-1) { if (s != e) l = new node(s, m), r = new node(m + 1, e); } void upd(int n, int x) { if (s == e) { v = x; return; } if (n <= m) l->upd(n, x); else r->upd(n, x); v = max(l->v, r->v); } int qry(int a, int b) { if (b < s || a > e) return -1; if (a <= s && b >= e) return v; return max(l->qry(a, b), r->qry(a, b)); } } *root;*/ vector<long long> minimum_costs(vector<signed> H, vector<signed> L, vector<signed> R) { int N = H.size(), Q = L.size(); stack<int> stk; vector<int> f2s(N, 0), b2s(N, 0); for (int i = 0; i < N; i++) { if (H[i] == 2) { f2s[i] = i; while (!stk.empty()) { f2s[stk.top()] = i; stk.pop(); } } else { stk.push(i); } } while (!stk.empty()) { f2s[stk.top()] = -1; stk.pop(); } for (int i = N - 1; i >= 0; i--) { if (H[i] == 2) { b2s[i] = i; while (!stk.empty()) { b2s[stk.top()] = i; stk.pop(); } } else { stk.push(i); } } while (!stk.empty()) { b2s[stk.top()] = -1; stk.pop(); } vector<int> ans; for (int i = 0; i < Q; i++) { if (f2s[L[i]] == -1) ans.push_back(R[i] + 1 - L[i]); else ans.push_back((R[i] + 1 - L[i]) * 2 - max(f2s[L[i]] - L[i], R[i] - b2s[R[i]])); } 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...