# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
878070 | 2023-11-24T04:12:20 Z | frostray8653 | Snowball (JOI21_ho_t2) | C++17 | 2 ms | 8792 KB |
// #pragma GCC optimize("Ofast,unroll-loops,O3") #include <bits/stdc++.h> #define int long long // #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define IO ios::sync_with_stdio(0), cin.tie(0) #define FOR(i, a, b) for (int i = a, I = b; i <= b; i++) using namespace std; void dbg() {;} template<class T, class ...U> void dbg(T a, U ...b) {cout << a << " "; dbg(b...);} void ent() {cout << "\n";} const int mod = 998244353; // const int mod = 1e9 + 7; // const int INF = 2e9; const int INF = 9e17; /// ------- Initialization End ------- const int N = 200005; int a[N]; int dx[N]; int bestl[N], bestr[N]; int ansl[N], ansr[N]; signed main() { IO; int n, m; cin >> n >> m; FOR(i, 1, n) cin >> a[i]; FOR(i, 1, m) cin >> dx[i]; int now = 0; int lft = 0, rgt = 0; FOR(i, 1, m) { now += dx[i]; lft = min(lft, now); rgt = max(rgt, now); bestl[i] = lft; bestr[i] = rgt; } ansl[1] = a[1] + bestl[m]; FOR(i, 1, n) { if (i == n) { ansr[i] = a[i] + bestr[m]; } else { int dif = a[i + 1] - a[i]; int l = 1, r = m + 1; while (l + 1 < r) { int mid = (l + r) >> 1; if (bestr[mid] - bestl[mid] >= dif) r = mid; else l = mid; } int id = l; int len = bestr[id] - bestl[id]; ansr[i + 0] = a[i + 0] + bestr[id]; ansl[i + 1] = a[i + 1] + bestl[id]; if (id < m) { if (bestr[id + 1] > bestr[id]) { ansr[i + 0] += dif - len; } else { ansl[i + 1] -= dif - len; } } } } FOR(i, 1, n) cout << ansr[i] - ansl[i] << "\n"; return 0; } /* 4 3 -2 3 5 8 2 -4 7 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8540 KB | Output is correct |
2 | Correct | 1 ms | 8664 KB | Output is correct |
3 | Correct | 2 ms | 8540 KB | Output is correct |
4 | Correct | 2 ms | 8792 KB | Output is correct |
5 | Correct | 2 ms | 8540 KB | Output is correct |
6 | Correct | 2 ms | 8540 KB | Output is correct |
7 | Correct | 2 ms | 8540 KB | Output is correct |
8 | Correct | 2 ms | 8540 KB | Output is correct |
9 | Correct | 2 ms | 8540 KB | Output is correct |
10 | Correct | 1 ms | 8540 KB | Output is correct |
11 | Correct | 2 ms | 8692 KB | Output is correct |
12 | Correct | 1 ms | 8540 KB | Output is correct |
13 | Correct | 1 ms | 8540 KB | Output is correct |
14 | Incorrect | 1 ms | 8540 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8540 KB | Output is correct |
2 | Correct | 1 ms | 8664 KB | Output is correct |
3 | Correct | 2 ms | 8540 KB | Output is correct |
4 | Correct | 2 ms | 8792 KB | Output is correct |
5 | Correct | 2 ms | 8540 KB | Output is correct |
6 | Correct | 2 ms | 8540 KB | Output is correct |
7 | Correct | 2 ms | 8540 KB | Output is correct |
8 | Correct | 2 ms | 8540 KB | Output is correct |
9 | Correct | 2 ms | 8540 KB | Output is correct |
10 | Correct | 1 ms | 8540 KB | Output is correct |
11 | Correct | 2 ms | 8692 KB | Output is correct |
12 | Correct | 1 ms | 8540 KB | Output is correct |
13 | Correct | 1 ms | 8540 KB | Output is correct |
14 | Incorrect | 1 ms | 8540 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |