Submission #935439

#TimeUsernameProblemLanguageResultExecution timeMemory
935439weakweakweakSnowball (JOI21_ho_t2)C++14
100 / 100
71 ms15016 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define fs first #define sc second int n, a[210000], ans[210000] = {0}, q; vector<pii>pp; signed main () { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> q; for (int i = 1; i <= n; i++) { cin >> a[i]; if (i > 1) pp.push_back({a[i] - a[i - 1], i - 1}); } pp.push_back({LLONG_MAX - 2, 0}); pp.push_back({LLONG_MAX - 2, n}); sort(pp.begin(), pp.end()); int now = 0, l = 0, r = 0, x, stkf = 0; while (q -- ) { cin >> x; now += x; int oldl = l, oldr = r; if (now < 0) l = max(l, -now); if (now > 0) r = max(r, now); while (stkf < pp.size() and l + r >= pp[stkf].fs) { ans[pp[stkf].sc] += oldr, ans[pp[stkf].sc + 1] += oldl; pp[stkf].fs -= oldl + oldr; if (now < 0) ans[pp[stkf].sc + 1] += pp[stkf].fs; else ans[pp[stkf].sc] += pp[stkf].fs; stkf++; } } while (stkf < pp.size()) { ans[pp[stkf].sc] += r, ans[pp[stkf].sc + 1] += l; stkf++; } for (int i = 1; i <= n; i++) cout << ans[i] << '\n'; return 0;}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:28:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         while (stkf < pp.size() and l + r >= pp[stkf].fs) {
      |                ~~~~~^~~~~~~~~~~
Main.cpp:36:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     while (stkf < pp.size()) {
      |            ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...