Submission #534834

# Submission time Handle Problem Language Result Execution time Memory
534834 2022-03-09T03:24:33 Z Cookie197 Snowball (JOI21_ho_t2) C++17
100 / 100
143 ms 24680 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>

using namespace std;
#define ll long long
#define pii pair<ll,ll> 
#define mp make_pair
#define endl "\n"
#define out(x) cout<< #x << " = " << x << endl
#define outp(x) cout << #x << " first = " << x.first << " second = " << x.second << endl
#define inf 3e18

int n,q;
ll arr[200005], ans[200005];
pii snow[200005];
ll rem[200005];

ll wind[200005];
pii samplesnow;
vector<pii> sampleadd(200005);
vector<ll> samplepre(200005);
vector<pii> bit(200005);
pii operator+(const pii &a, const pii &b){
    return mp(a.first+b.first, a.second+b.second);
}
void add(int id,pii x){
    for (int i=id;i<=q;i+=(i&-i)) bit[i] = bit[i] + x;
}
pii sum(int id){
    if (id==0) return mp(0ll,0ll);
    if (id>=q) id=q;
    pii ans = mp(0ll,0ll);
    for (int i=id;i>=1;i-=(i&-i)) ans = ans + bit[i];
    return ans;
}


signed main(){
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>q; n+=2;
    arr[1] = -3e18, arr[n] = 3e18;
    for (int i=2;i<n;i++) cin>>arr[i];
    for (int i=1;i<n;i++) {
        snow[i] = mp(0,0), rem[i] = arr[i+1]-arr[i];
    }
    
    for (int z=1;z<=q;z++){
        ll x; cin>>x; wind[z] = x;
        if (x>0){
            samplesnow.first -= x;
            if (samplesnow.first < 0){
                sampleadd[z].first += -samplesnow.first;
                samplesnow.first = 0;
            }
            samplesnow.second += x;
            if (samplesnow.second > inf){
                samplesnow.second = inf;
            }
        }else{
            x = abs(x);
            samplesnow.second -= x;
            if (samplesnow.second < 0){
                sampleadd[z].second += -samplesnow.second;
                samplesnow.second = 0;
            }
            samplesnow.first += x;
            if (samplesnow.first > inf){
                samplesnow.first = inf;
            }
        }
        samplepre[z] = samplepre[z-1] + sampleadd[z].first + sampleadd[z].second;
    }
    

    for (int z=1;z<=q;z++){
        //cout<<sampleadd[z].first<<" "<<sampleadd[z].second<<"  "<<samplepre[z]<<endl;
        add(z,sampleadd[z]);
    }
    for (int z=q+1;z<samplepre.size();z++) samplepre[z] = samplepre[q];

    for (int i=1;i<n;i++){
        ll amount = arr[i+1] - arr[i];
        int pos = lower_bound(samplepre.begin(),samplepre.end(),amount+1) - samplepre.begin();
        pii more = sum(pos);
        //out(pos);
        //outp(sampleadd[pos]);
        //out(amount);
        //outp(more);
        ll toomuch = samplepre[pos] - amount; toomuch = max(0ll, toomuch);
        if (sampleadd[pos].first != 0) more.first -= toomuch;
        else more.second -= toomuch;

        //outp(more);
        ans[i] += more.first, ans[i+1] += more.second;
    }

    for (int i=2;i<n;i++) cout<<ans[i]<<endl;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:81:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for (int z=q+1;z<samplepre.size();z++) samplepre[z] = samplepre[q];
      |                    ~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 5 ms 8140 KB Output is correct
3 Correct 4 ms 8140 KB Output is correct
4 Correct 7 ms 8268 KB Output is correct
5 Correct 6 ms 8268 KB Output is correct
6 Correct 4 ms 8188 KB Output is correct
7 Correct 5 ms 8268 KB Output is correct
8 Correct 5 ms 8268 KB Output is correct
9 Correct 4 ms 8268 KB Output is correct
10 Correct 5 ms 8268 KB Output is correct
11 Correct 4 ms 8268 KB Output is correct
12 Correct 4 ms 8140 KB Output is correct
13 Correct 4 ms 8140 KB Output is correct
14 Correct 4 ms 8140 KB Output is correct
15 Correct 5 ms 8268 KB Output is correct
16 Correct 6 ms 8268 KB Output is correct
17 Correct 5 ms 8248 KB Output is correct
18 Correct 6 ms 8140 KB Output is correct
19 Correct 4 ms 8268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 5 ms 8140 KB Output is correct
3 Correct 4 ms 8140 KB Output is correct
4 Correct 7 ms 8268 KB Output is correct
5 Correct 6 ms 8268 KB Output is correct
6 Correct 4 ms 8188 KB Output is correct
7 Correct 5 ms 8268 KB Output is correct
8 Correct 5 ms 8268 KB Output is correct
9 Correct 4 ms 8268 KB Output is correct
10 Correct 5 ms 8268 KB Output is correct
11 Correct 4 ms 8268 KB Output is correct
12 Correct 4 ms 8140 KB Output is correct
13 Correct 4 ms 8140 KB Output is correct
14 Correct 4 ms 8140 KB Output is correct
15 Correct 5 ms 8268 KB Output is correct
16 Correct 6 ms 8268 KB Output is correct
17 Correct 5 ms 8248 KB Output is correct
18 Correct 6 ms 8140 KB Output is correct
19 Correct 4 ms 8268 KB Output is correct
20 Correct 34 ms 9640 KB Output is correct
21 Correct 36 ms 9720 KB Output is correct
22 Correct 35 ms 9668 KB Output is correct
23 Correct 30 ms 9728 KB Output is correct
24 Correct 41 ms 11624 KB Output is correct
25 Correct 127 ms 22800 KB Output is correct
26 Correct 108 ms 22724 KB Output is correct
27 Correct 118 ms 22432 KB Output is correct
28 Correct 107 ms 22500 KB Output is correct
29 Correct 111 ms 22104 KB Output is correct
30 Correct 104 ms 21484 KB Output is correct
31 Correct 70 ms 20804 KB Output is correct
32 Correct 84 ms 21056 KB Output is correct
33 Correct 14 ms 9592 KB Output is correct
34 Correct 108 ms 23208 KB Output is correct
35 Correct 113 ms 22628 KB Output is correct
36 Correct 115 ms 22812 KB Output is correct
37 Correct 143 ms 22548 KB Output is correct
38 Correct 106 ms 22344 KB Output is correct
39 Correct 110 ms 22572 KB Output is correct
40 Correct 81 ms 22596 KB Output is correct
41 Correct 43 ms 12400 KB Output is correct
42 Correct 66 ms 21036 KB Output is correct
43 Correct 89 ms 24316 KB Output is correct
44 Correct 35 ms 12228 KB Output is correct
45 Correct 76 ms 22704 KB Output is correct
46 Correct 91 ms 24432 KB Output is correct
47 Correct 87 ms 24680 KB Output is correct
48 Correct 104 ms 24668 KB Output is correct