답안 #773070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773070 2023-07-04T14:42:13 Z Sami_Massah Snowball (JOI21_ho_t2) C++17
100 / 100
93 ms 15312 KB
#include <bits/stdc++.h>
using namespace std;


const long long maxn = 2e5 + 12, mod = 1e9 + 7;
long long n, a[maxn], qer[maxn], ans[maxn], sum[maxn][2];
int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    int q;
    cin >> n >> q;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    long long d = 0;
    for(int i = 1; i <= q; i++){
        long long b;
        cin >> b;
        qer[i] = b;
        d += b;
        sum[i][1] = max(-d, sum[i - 1][1]);
        sum[i][0] = max(d, sum[i - 1][0]);
    }
//    for(int i = 1; i <= q; i++)
  //      cout << sum[i][0] << ' ' << sum[i][1] << endl;
    for(int i = 0; i < n - 1; i++){
        long long f = a[i];
        long long s = a[i + 1];
        long long l = 0, r = q + 1, mid;
        while(r - l != 1){
            mid = (l + r) / 2;
            if(sum[mid][0] + sum[mid][1] <= s - f)
                l = mid;
            else
                r = mid;
        }
   //     cout << l  << ' ' << sum[l][0] << ' ' << sum[l][1] << endl;
        ans[i] += sum[l][0];
        ans[i + 1] += sum[l][1];
 //       cout << qer[l + 1] << endl;
        if(l + 1 == q + 1)
            continue;
        if(qer[l + 1] >= 0)
            ans[i] += s - f - sum[l][0] - sum[l][1];
        else
            ans[i + 1] += s - f - sum[l][0] - sum[l][1];
    }
    ans[0] += sum[q][1];
    ans[n - 1] += sum[q][0];
    for(int i = 0; i < n; i++)
        cout << ans[i] << ' ';
    cout << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 380 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 388 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 380 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 388 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 476 KB Output is correct
20 Correct 21 ms 7096 KB Output is correct
21 Correct 23 ms 6860 KB Output is correct
22 Correct 22 ms 6696 KB Output is correct
23 Correct 18 ms 6532 KB Output is correct
24 Correct 22 ms 7112 KB Output is correct
25 Correct 79 ms 13372 KB Output is correct
26 Correct 83 ms 13396 KB Output is correct
27 Correct 93 ms 13012 KB Output is correct
28 Correct 80 ms 13180 KB Output is correct
29 Correct 75 ms 12712 KB Output is correct
30 Correct 88 ms 12000 KB Output is correct
31 Correct 61 ms 11428 KB Output is correct
32 Correct 54 ms 11656 KB Output is correct
33 Correct 7 ms 1660 KB Output is correct
34 Correct 87 ms 13812 KB Output is correct
35 Correct 77 ms 13188 KB Output is correct
36 Correct 78 ms 13412 KB Output is correct
37 Correct 87 ms 13132 KB Output is correct
38 Correct 77 ms 13004 KB Output is correct
39 Correct 73 ms 13244 KB Output is correct
40 Correct 63 ms 13240 KB Output is correct
41 Correct 21 ms 7656 KB Output is correct
42 Correct 53 ms 11592 KB Output is correct
43 Correct 64 ms 14968 KB Output is correct
44 Correct 20 ms 7560 KB Output is correct
45 Correct 59 ms 13176 KB Output is correct
46 Correct 71 ms 15116 KB Output is correct
47 Correct 67 ms 15312 KB Output is correct
48 Correct 67 ms 15308 KB Output is correct