Submission #1249353

#TimeUsernameProblemLanguageResultExecution timeMemory
1249353CrabCNHSnowball (JOI21_ho_t2)C++20
100 / 100
63 ms11452 KiB
#include <bits/stdc++.h> #define task "BriantheCrab" #define int long long #define pii pair <int, int> #define fi first #define se second #define szf sizeof #define sz(s) (int)((s).size()) #define all(v) (v).begin(), (v).end() typedef long long ll; typedef unsigned long long ull; typedef long double ld; using namespace std; template <class T> void minimize (T &t, T f) {if (t > f) t = f;} template <class T> void maximize (T &t, T f) {if (t < f) t = f;} const int maxN = 2e5 + 5; const int inf = 1e18 + 7; const int mod = 1e9 + 7; // khong tu code thi khong kha len duoc dau int a[maxN]; int l[maxN], r[maxN]; int turn[maxN]; int res[maxN]; void solve () { int n, q; cin >> n >> q; for (int i = 1; i <= n; i ++) { cin >> a[i]; } int cur = 0; vector <int> pos; for (int i = 1; i <= q; i ++) { int w; cin >> w; cur += w; r[i] = r[i - 1]; l[i] = l[i - 1]; if (cur > 0) { turn[i] = 1; maximize (r[i], cur); } else { turn[i] = 0; maximize (l[i], -cur); } pos.push_back (l[i] + r[i]); } // cout << "gay "; // for (int i = 1; i <= q; i ++) { // cout << l[i] << ' '; // } // cout << '\n'; // cout << "gay "; // for (int i = 1; i <= q; i ++) { // cout << r[i] << ' '; // } // cout << '\n'; // cout << "gay "; // for (auto it : pos) { // cout << it << ' '; // } // cout << '\n'; pos.push_back (inf); res[1] += l[q]; res[n] += r[q]; for (int i = 2; i <= n; i ++) { // dis <= l[i] + r[i] auto id = upper_bound (all (pos), abs (a[i] - a[i - 1]) - 1) - pos.begin (); if (id >= q) { res[i - 1] += r[q]; res[i] += l[q]; continue; } //cout << "bruh " << i << ' ' << i - 1 << ' ' << id + 1 << '\n'; if (turn[id + 1] == 1) { // if (i == 2) { // cout << "gay"; // } res[i - 1] += abs (a[i] - a[i - 1]) - l[id + 1]; res[i] += l[id + 1]; } else { res[i - 1] += r[id + 1]; res[i] += abs (a[i] - a[i - 1]) - r[id + 1]; } } for (int i = 1; i <= n; i ++) { cout << res[i] << '\n'; } return; } signed main () { cin.tie (nullptr) -> sync_with_stdio (false); if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int t = 1; //cin >> t; while (t --) { solve (); } return 0; } // thfv

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:105:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:106:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...