Submission #60589991
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--) #define SZ(a) int(a.size()) #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair #define F first #define S second typedef long long LL; typedef vector<int> VI; typedef vector<LL> VL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef double db; const int LOG = 19; const int N = 1 << LOG; /** * Description: Sparse table for minimum on the range $[l, r), l < r$. * You can push back an element in $O(\text{LOG})$ and query anytime. */ struct SparseTable { vector<PII> t[LOG]; void push_back(PII v) { int i = SZ(t[0]); t[0].PB(v); FOR (j, 0, LOG - 1) t[j + 1].PB(max(t[j][i], t[j][max(0, i - (1 << j))])); } // [l, r) PII query(int l, int r) { assert(l < r && r <= SZ(t[0])); int i = 31 - __builtin_clz(r - l); return max(t[i][r - 1], t[i][l + (1 << i) - 1]); } } st; int n; int a[N]; LL pref[N]; LL ans[N]; void solve(int l, int r) { if (l > r) return; auto [mx, lastPos] = st.query(l, r + 1); VI poses = {lastPos}; while (poses.back() > l) { auto [val, pos] = st.query(l, poses.back()); assert(val <= mx); if (val < mx) break; poses.PB(pos); } reverse(ALL(poses)); LL s = pref[r + 1] - pref[l]; int prv = l - 1; for (int i : poses) { if ((i > 0 && a[i - 1] < a[i]) || (i + 1 < n && a[i + 1] < a[i])) { if (l > 0 && a[l - 1] < s) ans[i] = ans[l - 1]; else if (r + 1 < n && a[r + 1] < s) ans[i] = ans[r + 1]; else ans[i] = s; } else { ans[i] = a[i]; } solve(prv + 1, i - 1); prv = i; } solve(prv + 1, r); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; FOR(i, 0, n) { cin >> a[i]; st.PB({a[i], i}); } FOR(i, 0, n) pref[i + 1] = pref[i] + a[i]; solve(0, n - 1); FOR(i, 0, n) cout << ans[i] << " "; cout << "\n"; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Takahashi is Slime |
User | mshcherba |
Language | C++ 20 (gcc 12.2) |
Score | 700 |
Code Size | 2057 Byte |
Status | AC |
Exec Time | 190 ms |
Memory | 92408 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, example0.txt, example1.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 1 ms | 3412 KiB |
001.txt | AC | 1 ms | 3472 KiB |
002.txt | AC | 1 ms | 3476 KiB |
003.txt | AC | 139 ms | 91248 KiB |
004.txt | AC | 156 ms | 91156 KiB |
005.txt | AC | 156 ms | 91120 KiB |
006.txt | AC | 141 ms | 88992 KiB |
007.txt | AC | 140 ms | 89000 KiB |
008.txt | AC | 140 ms | 89032 KiB |
009.txt | AC | 140 ms | 88976 KiB |
010.txt | AC | 148 ms | 87688 KiB |
011.txt | AC | 166 ms | 92408 KiB |
012.txt | AC | 170 ms | 88544 KiB |
013.txt | AC | 170 ms | 88528 KiB |
014.txt | AC | 171 ms | 88552 KiB |
015.txt | AC | 170 ms | 88552 KiB |
016.txt | AC | 170 ms | 88524 KiB |
017.txt | AC | 171 ms | 88600 KiB |
018.txt | AC | 171 ms | 88656 KiB |
019.txt | AC | 170 ms | 88616 KiB |
020.txt | AC | 172 ms | 88556 KiB |
021.txt | AC | 171 ms | 88548 KiB |
022.txt | AC | 41 ms | 23980 KiB |
023.txt | AC | 75 ms | 38920 KiB |
024.txt | AC | 76 ms | 38240 KiB |
025.txt | AC | 84 ms | 43000 KiB |
026.txt | AC | 20 ms | 12940 KiB |
027.txt | AC | 144 ms | 70400 KiB |
028.txt | AC | 11 ms | 8600 KiB |
029.txt | AC | 140 ms | 69324 KiB |
030.txt | AC | 2 ms | 3928 KiB |
031.txt | AC | 153 ms | 76944 KiB |
032.txt | AC | 180 ms | 91900 KiB |
033.txt | AC | 185 ms | 91992 KiB |
034.txt | AC | 181 ms | 91912 KiB |
035.txt | AC | 181 ms | 91988 KiB |
036.txt | AC | 181 ms | 91908 KiB |
037.txt | AC | 181 ms | 91968 KiB |
038.txt | AC | 184 ms | 91948 KiB |
039.txt | AC | 181 ms | 91956 KiB |
040.txt | AC | 181 ms | 91972 KiB |
041.txt | AC | 181 ms | 91928 KiB |
042.txt | AC | 183 ms | 91948 KiB |
043.txt | AC | 190 ms | 91952 KiB |
044.txt | AC | 183 ms | 91996 KiB |
045.txt | AC | 181 ms | 91940 KiB |
046.txt | AC | 181 ms | 91920 KiB |
047.txt | AC | 182 ms | 92004 KiB |
048.txt | AC | 184 ms | 91952 KiB |
049.txt | AC | 180 ms | 91948 KiB |
050.txt | AC | 179 ms | 91908 KiB |
051.txt | AC | 180 ms | 91940 KiB |
example0.txt | AC | 2 ms | 3480 KiB |
example1.txt | AC | 1 ms | 3488 KiB |