# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
501138 | 2022-01-02T12:52:35 Z | shahriarkhan | Snowball (JOI21_ho_t2) | C++14 | 12 ms | 460 KB |
#include<bits/stdc++.h> using namespace std ; const int MX = 2e5 + 5 ; const long long INF = 1e18 + 5 ; long long pref_mx[MX] , pref_mn[MX] ; int n , q ; int smaller_equal(long long val) { if(pref_mn[q]>val) return (q+1) ; int low = 0 , high = q ; while(low<high) { int mid = (low+high)>>1 ; if(pref_mn[mid]<=val) high = mid ; else low = mid + 1 ; } return low ; } int bigger_equal(long long val) { if(pref_mx[q]<val) return (q+1) ; int low = 0 , high = q ; while(low<high) { int mid = (low+high)>>1 ; if(pref_mx[mid]>=val) high = mid ; else low = mid + 1 ; } return low ; } int main() { scanf("%d%d",&n,&q) ; long long x[n+2] , sum = 0 , ans[n+1] = {0} ; for(int i = 1 ; i <= n ; ++i) { scanf("%lld",&x[i]) ; } pref_mx[0] = 0 , pref_mn[0] = INF ; for(int i = 1 ; i <= q ; ++i) { long long cur ; scanf("%lld",&cur) ; sum += cur ; pref_mx[i] = max(pref_mx[i-1],sum) ; pref_mn[i] = min(pref_mn[i-1],sum) ; } for(int i = 1 ; i <= n ; ++i) { long long low = 0 , high = INF , left = 0 , right = 0 ; while(low<high) { long long mid = (low+high+1)>>1 ; if(i==n) { int pos = bigger_equal(mid) ; if(pos>q) high = mid - 1 ; else low = mid ; } else { if(bigger_equal(mid)<smaller_equal(x[i]-x[i+1]+mid-1)) low = mid ; else high = mid - 1 ; } } left = low ; low = 0 , high = INF ; while(low<high) { long long mid = (low+high+1)>>1 ; if(i==1) { int pos = smaller_equal(-mid) ; if(pos>q) high = mid - 1 ; else low = mid ; } else { if(smaller_equal(-mid)<bigger_equal(x[i]-x[i-1]-mid+1)) low = mid ; else high = mid - 1 ; } } right = low ; ans[i] = left+right ; } for(int i = 1 ; i <= n ; ++i) { printf("%lld\n",ans[i]) ; } return 0 ; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 308 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 2 ms | 312 KB | Output is correct |
4 | Correct | 12 ms | 408 KB | Output is correct |
5 | Correct | 11 ms | 404 KB | Output is correct |
6 | Correct | 10 ms | 332 KB | Output is correct |
7 | Correct | 9 ms | 312 KB | Output is correct |
8 | Correct | 9 ms | 332 KB | Output is correct |
9 | Correct | 8 ms | 460 KB | Output is correct |
10 | Correct | 4 ms | 312 KB | Output is correct |
11 | Correct | 3 ms | 332 KB | Output is correct |
12 | Incorrect | 0 ms | 204 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 308 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 2 ms | 312 KB | Output is correct |
4 | Correct | 12 ms | 408 KB | Output is correct |
5 | Correct | 11 ms | 404 KB | Output is correct |
6 | Correct | 10 ms | 332 KB | Output is correct |
7 | Correct | 9 ms | 312 KB | Output is correct |
8 | Correct | 9 ms | 332 KB | Output is correct |
9 | Correct | 8 ms | 460 KB | Output is correct |
10 | Correct | 4 ms | 312 KB | Output is correct |
11 | Correct | 3 ms | 332 KB | Output is correct |
12 | Incorrect | 0 ms | 204 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |