답안 #1100724

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100724 2024-10-14T14:03:02 Z vjudge1 Snowball (JOI21_ho_t2) C++17
100 / 100
78 ms 11376 KB
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
using namespace std;

const int N=2e5+5, mod = 1e9+7, inf = 1e18;

int n, q;
int a[N], res[N], dif[N], p[N], mn[N], ma[N];
 
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q;
    for(int i=1; i<=n; i++) {
        cin >> a[i];
        if(i>1) dif[i-1] = a[i]-a[i-1];
    }
    for(int i=1; i<=q; i++) {
        int x; cin >> x;
        p[i] = p[i-1] + x;
        mn[i] = min(mn[i-1], p[i]);
        ma[i] = max(ma[i-1], p[i]);
    }
    for(int i=1; i<n; i++) {
        int l=1, r=q, ans;
        while(l<=r) {
            int mid = (l+r)>>1;
            if(ma[mid]-mn[mid]>=dif[i]) {
                ans = mid;
                r = mid-1;
            } else l = mid+1;
        }
        if(ma[q]-mn[q]<dif[i]) {
            res[i]+=ma[q];
            res[i+1]-=mn[q];
            continue; 
        }
        ans--;
        res[i]+=ma[ans]; res[i+1]-=mn[ans];
        l=a[i]+ma[ans]; r=a[i+1]+mn[ans];
        ans++;
        if(p[ans]>0) res[i]+=r-l;
        else res[i+1]+=r-l;
    }
    res[1]-=mn[q];
    res[n]+=ma[q];
    for(int i=1; i<=n; i++) cout << res[i] << '\n';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:43:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |         ans--;
      |         ~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 4432 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 2 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 2 ms 4440 KB Output is correct
16 Correct 2 ms 4624 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 4432 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 2 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 2 ms 4440 KB Output is correct
16 Correct 2 ms 4624 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 23 ms 8784 KB Output is correct
21 Correct 18 ms 8768 KB Output is correct
22 Correct 17 ms 8784 KB Output is correct
23 Correct 18 ms 8868 KB Output is correct
24 Correct 23 ms 8844 KB Output is correct
25 Correct 72 ms 11336 KB Output is correct
26 Correct 73 ms 11336 KB Output is correct
27 Correct 71 ms 11080 KB Output is correct
28 Correct 78 ms 11124 KB Output is correct
29 Correct 78 ms 10824 KB Output is correct
30 Correct 68 ms 10568 KB Output is correct
31 Correct 43 ms 10128 KB Output is correct
32 Correct 39 ms 10064 KB Output is correct
33 Correct 7 ms 5368 KB Output is correct
34 Correct 73 ms 11316 KB Output is correct
35 Correct 77 ms 11096 KB Output is correct
36 Correct 78 ms 11336 KB Output is correct
37 Correct 74 ms 11080 KB Output is correct
38 Correct 71 ms 11128 KB Output is correct
39 Correct 65 ms 11084 KB Output is correct
40 Correct 51 ms 11220 KB Output is correct
41 Correct 19 ms 8784 KB Output is correct
42 Correct 37 ms 10064 KB Output is correct
43 Correct 48 ms 11336 KB Output is correct
44 Correct 19 ms 8784 KB Output is correct
45 Correct 42 ms 11080 KB Output is correct
46 Correct 48 ms 11336 KB Output is correct
47 Correct 55 ms 11336 KB Output is correct
48 Correct 49 ms 11376 KB Output is correct