Submission #543676

#TimeUsernameProblemLanguageResultExecution timeMemory
543676AsymmetrySnowball (JOI21_ho_t2)C++17
100 / 100
174 ms16932 KiB
//Autor: Bartłomiej Czarkowski #include <bits/stdc++.h> using namespace std; #ifdef DEBUG template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';} template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';} #define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n' #else #define debug(...) {} #endif const int N = 201000; int n, q; long long odp[N]; long long t[N]; long long w[N]; long long pw[N]; long long pref_min[N]; long long pref_max[N]; int main() { scanf("%d%d", &n, &q); for (int i = 1; i <= n; ++i) { scanf("%lld", &t[i]); } for (int i = 1; i <= q; ++i) { scanf("%lld", &w[i]); pw[i] = pw[i - 1] + w[i]; pref_min[i] = min(pref_min[i - 1], pw[i]); pref_max[i] = max(pref_max[i - 1], pw[i]); } odp[1] -= pref_min[q]; odp[n] += pref_max[q]; for (int i = 1; i < n; ++i) { long long dif = t[i + 1] - t[i]; int bp = 0, bk = q + 1, bs; while (bk - bp > 1) { bs = (bp + bk) / 2; if (pref_max[bs] - pref_min[bs] < dif) { bp = bs; } else { bk = bs; } } debug(t[i], t[i + 1], bk, pref_min[bk], pref_max[bk]); if (bk == q + 1) { odp[i] += pref_max[q]; odp[i + 1] -= pref_min[q]; } else if (w[bk] < 0) { odp[i] += pref_max[bk]; odp[i + 1] += dif - pref_max[bk]; } else { debug("c", -pref_min[bk], dif + pref_min[bk]); odp[i + 1] -= pref_min[bk]; odp[i] += dif + pref_min[bk]; } } for (int i = 1; i <= n; ++i) { printf("%lld\n", odp[i]); } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   scanf("%lld", &t[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
Main.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   scanf("%lld", &w[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...