Submission #720342

#TimeUsernameProblemLanguageResultExecution timeMemory
720342yellowtoadSnowball (JOI21_ho_t2)C++17
100 / 100
436 ms13584 KiB
#include <iostream> #include <vector> using namespace std; long long n, test, a[200010], cur, x, minn, maxx, b[200010], l, r, mid, ans[200010]; vector<long long> v; int main() { cin >> n >> test; for (int i = 1; i <= n; i++) cin >> a[i]; v.push_back(0); while (test--) { cin >> x; cur += x; if (cur > maxx) { if (v.back() <= 0) v.push_back(cur); else v.back() = cur; maxx = cur; } else if (cur < minn) { if (v.back() >= 0) v.push_back(cur); else v.back() = cur; minn = cur; } } if (v.size() == 1) { for (int i = 1; i <= n; i++) cout << 0 << endl; return 0; } for (int i = 1; i < v.size(); i++) b[i] = abs(v[i-1]-v[i]); ans[1] -= minn; for (int i = 2; i <= n; i++) { l = 1; r = v.size()-1; while (l <= r) { mid = (l+r)/2; if (a[i]-a[i-1] <= b[mid]) r = mid-1; else l = mid+1; } if (r < v.size()-1) { r++; if (v[r-1] < 0) ans[i] -= max(a[i-1]-a[i],v[r-1]); else ans[i-1] += min(a[i]-a[i-1],v[r-1]); if (v[r] < 0) ans[i] -= max(a[i-1]+min(a[i]-a[i-1],v[r-1])-a[i],v[r]); else ans[i-1] += min(a[i]+max(a[i-1]-a[i],v[r-1])-a[i-1],v[r]); } else { if (v[r-1] < 0) ans[i] -= max(a[i-1]-a[i],v[r-1]); else ans[i-1] += min(a[i]-a[i-1],v[r-1]); if (v[r] < 0) ans[i] -= max(a[i-1]+min(a[i]-a[i-1],v[r-1])-a[i],v[r]); else ans[i-1] += min(a[i]+max(a[i-1]-a[i],v[r-1])-a[i-1],v[r]); } } ans[n] += maxx; for (int i = 1; i <= n; i++) cout << ans[i] << endl; } /* 10 10 0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 0 */

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for (int i = 1; i < v.size(); i++) b[i] = abs(v[i-1]-v[i]);
      |                  ~~^~~~~~~~~~
Main.cpp:38:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   if (r < v.size()-1) {
      |       ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...