Submission #568685

#TimeUsernameProblemLanguageResultExecution timeMemory
568685dantoh000Snowball (JOI21_ho_t2)C++14
100 / 100
118 ms16844 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int n,q; int p[200005]; int D[200005]; int l[200005]; int r[200005]; int pos[200005]; int ans[200005]; main(){ scanf("%lld%lld",&n,&q); for (int i = 1; i <= n; i++){ scanf("%lld",&p[i]); } int cur = 0; l[0] = r[0] = D[0] = 0; for (int i = 1, x; i <= q+1; i++){ if (i == q+1) x = 0; else scanf("%lld",&x); cur += x; l[i] = min(l[i-1], cur); r[i] = max(r[i-1], cur); D[i] = r[i]-l[i]; pos[i] = cur; } ans[1] += -l[q]; ans[n] += r[q]; for (int i = 1; i < n; i++){ int d = p[i+1]-p[i]; int id = lower_bound(D, D+q+1, d) - D; int L = -l[id]; int R = r[id]; L = min(L, d); R = min(R, d); if (pos[id] == l[id]) L = min(L, d - R); else if (pos[id] == r[id]) R = min(R, d - L); ///printf("position %d moves %d left, position %d moves %d right\n",i+1,L,i,R); ans[i] += R; ans[i+1] += L; } for (int i = 1; i <= n; i++){ printf("%lld\n",ans[i]); } }

Compilation message (stderr)

Main.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%lld%lld",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%lld",&p[i]);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:20:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         else scanf("%lld",&x);
      |              ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...