Submission #532486

# Submission time Handle Problem Language Result Execution time Memory
532486 2022-03-03T03:07:51 Z scottchou Snowball (JOI21_ho_t2) C++17
0 / 100
1 ms 460 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++;
        }
    }
    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()];
        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]){
      |               ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 460 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 460 KB Output isn't correct
5 Halted 0 ms 0 KB -