Submission #270395

#TimeUsernameProblemLanguageResultExecution timeMemory
270395Haunted_CppLabels (NOI20_labels)C++17
100 / 100
115 ms35064 KiB
/** * author: Haunted_Cpp **/ #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void debug_out() { cerr << endl; } template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__) #else #define debug(...) 47 #endif class SegmentTree { private: struct Node { long long mn, mx; long long lazy; Node () { mn = 1e18; mx = -1e18; lazy = 0; } void merge(Node l, Node r) { mn = min(l.mn, r.mn); mx = max(l.mx, r.mx); } }; const int LO, HI; vector<Node> seg; void build(int l, int r, int node, const vector<long long> &arr) { if (l == r) { seg[node].mn = seg[node].mx = arr[l]; } else { const int mid = l + (r - l) / 2; build(l, mid, 2 * node + 1, arr); build(mid + 1, r, 2 * node + 2, arr); seg[node].merge(seg[2 * node + 1], seg[2 * node + 2]); } } void push(int l, int r, int node) { if (seg[node].lazy == 0) return; seg[node].mx += seg[node].lazy; seg[node].mn += seg[node].lazy; if (l != r) { seg[2 * node + 1].lazy += seg[node].lazy; seg[2 * node + 2].lazy += seg[node].lazy; } seg[node].lazy = 0; } void range_update(int ql, int qr, int delta, int l, int r, int node) { push(l, r, node); if (l > qr || r < ql) return; if (l >= ql && r <= qr) { seg[node].lazy = delta; push(l, r, node); return; } const int mid = l + (r - l) / 2; range_update(ql, qr, delta, l, mid, 2 * node + 1); range_update(ql, qr, delta, mid + 1, r, 2 * node + 2); seg[node].merge(seg[2 * node + 1], seg[2 * node + 2]); } void dfs(int l, int r, int node) { push(l, r, node); if (l == r) { cout << seg[node].mx << ' '; return; } const int mid = l + (r - l) / 2; dfs(l, mid, 2 * node + 1); dfs(mid + 1, r, 2 * node + 2); } public: SegmentTree(const vector<long long> &arr) : LO(0), HI((int) arr.size() - 1) { seg.clear(); seg.resize(4 * (int)arr.size()); build(LO, HI, 0, arr); }; void range_update(int ql, int qr, int delta) { range_update(ql, qr, delta, LO, HI, 0); } void get_ans() { dfs(LO, HI, 0); } long long get_max() { return seg[0].mx; } long long get_min() { return seg[0].mn; } }; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<long long> arr(n - 1); for (int i = 0; i < n - 1; i++) { cin >> arr[i]; if (i) arr[i] += arr[i - 1]; } SegmentTree seg(arr); int work = 0; for (int i = 1; i <= n; i++) { seg.range_update(0, n - 2, +i); const long long mn = seg.get_min(); const long long mx = seg.get_max(); if (mn >= 1 && mx <= n) ++work; seg.range_update(0, n - 2, -i); } if (work != 1) { cout << "-1" << '\n'; return 0; } for (int i = 1; i <= n; i++) { seg.range_update(0, n - 2, +i); const long long mn = seg.get_min(); const long long mx = seg.get_max(); if (mn >= 1 && mx <= n) { cout << i << ' '; seg.get_ans(); cout << '\n'; return 0; } seg.range_update(0, n - 2, -i); } return 0; }
#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...