Submission #598553

# Submission time Handle Problem Language Result Execution time Memory
598553 2022-07-18T13:45:17 Z KarolZ Snowball (JOI21_ho_t2) C++14
100 / 100
166 ms 21912 KB
//Karol Zeleznik
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
pair<ll,ll>t[200010];
//to co odejmuje
vector<ll>v;
//wejscie
priority_queue< pair<ll,ll> >p;
priority_queue< pair<ll,ll> >l;
//kolejki minimalne roznice na prawo i na lewo
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
    ll n,q,v1,akt=0,mnl=0,mnp=0,as;
    // n,q,v1,aktualna pozycja,max na lewo i prawo
    cin>>n>>q;
    for(int i=0;i<n;i++){
        cin>>v1;
        v.push_back(v1);
        t[i].first=1e18;
        t[i].second=1e18;
    }
    for(int i=0;i<v.size();i++){
        if(i!=n-1)p.push({-v[i+1]+v[i],i});
        if(i!=0)l.push({-v[i]+v[i-1],i});
    }
    p.push({-1e18,n-1});
    l.push({-1e18,0});
    while(q--){
        cin>>v1;
        akt+=v1;
        //cout<<akt<<'\n';
        if(akt>mnp){
            while(-p.top().first+mnl<akt){
                t[p.top().second].second=max(mnp,-p.top().first+mnl);
                //cout<<-p.top().first+mnl<<'\n';
                p.pop();
            }
            mnp=akt;
        }
        if(akt<mnl){
            while(-l.top().first-mnp<-akt){
                t[l.top().second].first=max(-mnl,-l.top().first-mnp);
                //cout<<t[l.top().second].first<<'\n';
                l.pop();
            }
            mnl=akt;
        }
    }
    //cout<<"\ndla 3 odp to: "<<t[2].first<<" + "<<t[2].second<<'\n';
    for(int i=0;i<n;i++){
        as=0;
        if(t[i].first==1e18)as-=mnl;
        else as+=t[i].first;
        if(t[i].second==1e18)as+=mnp;
        else as+=t[i].second;
        cout<<as<<'\n';
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 520 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 476 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 476 KB Output is correct
16 Correct 3 ms 472 KB Output is correct
17 Correct 2 ms 472 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 520 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 476 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 476 KB Output is correct
16 Correct 3 ms 472 KB Output is correct
17 Correct 2 ms 472 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 25 ms 2356 KB Output is correct
21 Correct 24 ms 2256 KB Output is correct
22 Correct 23 ms 2008 KB Output is correct
23 Correct 21 ms 2020 KB Output is correct
24 Correct 29 ms 3428 KB Output is correct
25 Correct 131 ms 19960 KB Output is correct
26 Correct 142 ms 19960 KB Output is correct
27 Correct 142 ms 19568 KB Output is correct
28 Correct 152 ms 19768 KB Output is correct
29 Correct 137 ms 19280 KB Output is correct
30 Correct 132 ms 18620 KB Output is correct
31 Correct 102 ms 18192 KB Output is correct
32 Correct 69 ms 18148 KB Output is correct
33 Correct 12 ms 2216 KB Output is correct
34 Correct 128 ms 20340 KB Output is correct
35 Correct 151 ms 19772 KB Output is correct
36 Correct 124 ms 19956 KB Output is correct
37 Correct 126 ms 19772 KB Output is correct
38 Correct 126 ms 19524 KB Output is correct
39 Correct 166 ms 19724 KB Output is correct
40 Correct 130 ms 19748 KB Output is correct
41 Correct 29 ms 3024 KB Output is correct
42 Correct 71 ms 18180 KB Output is correct
43 Correct 120 ms 21536 KB Output is correct
44 Correct 34 ms 2868 KB Output is correct
45 Correct 70 ms 19684 KB Output is correct
46 Correct 134 ms 21624 KB Output is correct
47 Correct 111 ms 21872 KB Output is correct
48 Correct 104 ms 21912 KB Output is correct