Submission #532494

# Submission time Handle Problem Language Result Execution time Memory
532494 2022-03-03T03:17:02 Z scottchou Snowball (JOI21_ho_t2) C++17
100 / 100
107 ms 13936 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
int const N = 2e5 + 5;
LL a[N];
vector<LL> line, ans;
LL sum[N];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(i != 0){
            line.push_back(a[i] - a[i - 1]);
        }
    }
    sort(line.begin(), line.end());
    line.resize(unique(line.begin(), line.end()) - line.begin());
    ans.resize(line.size());
    LL nowx = 0, w, left = 0, right = 0, idx = 0;
    for(int i = 0; i < q; i++){
        cin >> w;
        nowx += w;
        if(nowx < 0)
            left = max(left, -nowx);
        else
            right = max(right, nowx);
        while(idx < line.size() && left + right >= line[idx]){
            if(w < 0){
                ans[idx] = right;
            }else{
                ans[idx] = line[idx] - left;
            }
            idx++;
        }
    }
    while(idx < line.size()){
        ans[idx] = -1;
        idx++;
    }
    sum[0] += left;
    sum[n - 1] += right;
    for(int i = 1; i < n; i++){
        LL len = a[i] - a[i - 1];
        LL lef = ans[lower_bound(line.begin(), line.end(), len) - line.begin()];
        if(lef == -1){
            sum[i - 1] += right;
            sum[i] += left;
            continue;
        }
        sum[i - 1] += lef;
        sum[i] += len - lef;
    }
    for(int i = 0; i < n; i++){
        cout << sum[i] << '\n';
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:32:19: warning: comparison of integer expressions of different signedness: 'LL' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         while(idx < line.size() && left + right >= line[idx]){
      |               ~~~~^~~~~~~~~~~~~
Main.cpp:41:15: warning: comparison of integer expressions of different signedness: 'LL' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     while(idx < line.size()){
      |           ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 25 ms 2444 KB Output is correct
21 Correct 25 ms 2228 KB Output is correct
22 Correct 24 ms 1988 KB Output is correct
23 Correct 24 ms 2016 KB Output is correct
24 Correct 28 ms 2796 KB Output is correct
25 Correct 104 ms 11976 KB Output is correct
26 Correct 106 ms 11852 KB Output is correct
27 Correct 102 ms 11412 KB Output is correct
28 Correct 107 ms 11444 KB Output is correct
29 Correct 103 ms 10348 KB Output is correct
30 Correct 73 ms 8988 KB Output is correct
31 Correct 58 ms 8400 KB Output is correct
32 Correct 53 ms 8660 KB Output is correct
33 Correct 10 ms 1608 KB Output is correct
34 Correct 103 ms 12260 KB Output is correct
35 Correct 101 ms 11624 KB Output is correct
36 Correct 102 ms 12000 KB Output is correct
37 Correct 103 ms 11652 KB Output is correct
38 Correct 98 ms 10628 KB Output is correct
39 Correct 81 ms 10228 KB Output is correct
40 Correct 69 ms 10208 KB Output is correct
41 Correct 30 ms 2980 KB Output is correct
42 Correct 100 ms 10176 KB Output is correct
43 Correct 87 ms 13524 KB Output is correct
44 Correct 29 ms 2868 KB Output is correct
45 Correct 99 ms 11640 KB Output is correct
46 Correct 97 ms 13580 KB Output is correct
47 Correct 89 ms 13804 KB Output is correct
48 Correct 89 ms 13936 KB Output is correct