Submission #878072

#TimeUsernameProblemLanguageResultExecution timeMemory
878072frostray8653Snowball (JOI21_ho_t2)C++17
100 / 100
79 ms11416 KiB
// #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 = 0, 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; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:8:38: warning: unused variable 'I' [-Wunused-variable]
    8 | #define FOR(i, a, b) for (int i = a, I = b; i <= b; i++)
      |                                      ^
Main.cpp:32:5: note: in expansion of macro 'FOR'
   32 |     FOR(i, 1, n) cin >> a[i];
      |     ^~~
Main.cpp:8:38: warning: unused variable 'I' [-Wunused-variable]
    8 | #define FOR(i, a, b) for (int i = a, I = b; i <= b; i++)
      |                                      ^
Main.cpp:33:5: note: in expansion of macro 'FOR'
   33 |     FOR(i, 1, m) cin >> dx[i];
      |     ^~~
Main.cpp:8:38: warning: unused variable 'I' [-Wunused-variable]
    8 | #define FOR(i, a, b) for (int i = a, I = b; i <= b; i++)
      |                                      ^
Main.cpp:37:5: note: in expansion of macro 'FOR'
   37 |     FOR(i, 1, m) {
      |     ^~~
Main.cpp:8:38: warning: unused variable 'I' [-Wunused-variable]
    8 | #define FOR(i, a, b) for (int i = a, I = b; i <= b; i++)
      |                                      ^
Main.cpp:45:5: note: in expansion of macro 'FOR'
   45 |     FOR(i, 1, n) {
      |     ^~~
Main.cpp:8:38: warning: unused variable 'I' [-Wunused-variable]
    8 | #define FOR(i, a, b) for (int i = a, I = b; i <= b; i++)
      |                                      ^
Main.cpp:71:5: note: in expansion of macro 'FOR'
   71 |     FOR(i, 1, n)
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...