Submission #1092293

#TimeUsernameProblemLanguageResultExecution timeMemory
1092293PagodePaivaSnowball (JOI21_ho_t2)C++17
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 200010; int p[N], res[N]; int dif[N]; int query[N]; int minquery[N], maxquery[N]; int32_t main(){ int n, q; cin >> n >> q; for(int i = 1;i <= n;i++){ cin >> p[i]; if(i > 1) dif[i-1] = p[i] - p[i-1]; } for(int i = 1;i <= q;i++){ int x; cin >> x; query[i] = query[i-1] + x; minquery[i] = min(minquery[i-1], query[i]); maxquery[i] = max(maxquery[i-1], query[i]); } res[1] -= minquery[q]; //cout << '\n'; for(int i = 1;i < n;i++){ int l = 1, r = q; int resp; while(l <= r){ int mid = (l+r)/2; int ans = maxquery[mid] - minquery[mid]; if(i == 5){ // cout << mid << ' ' << ans << ' ' << dif[i] << '\n'; } if(ans >= dif[i]){ resp = mid; r = mid-1; } else{ l = mid+1; } } if(maxquery[n] - minquery[n] < dif[i]){ res[i] += maxquery[n]; res[i+1] -= minquery[n]; continue; } resp--; res[i] += maxquery[resp]; res[i+1] -= minquery[resp]; l = p[i]+maxquery[resp]; r = p[i+1]+minquery[resp]; resp++; if(query[resp] > 0){ res[i] += r-l; } else{ res[i+1] += r-l; } } res[n] += maxquery[q]; for(int i = 1;i <= n;i++){ cout << res[i] << '\n'; } }

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:50:13: warning: 'resp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   50 |         resp--;
      |         ~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...