Submission #692550

# Submission time Handle Problem Language Result Execution time Memory
692550 2023-02-01T22:54:54 Z guagua0407 Snowball (JOI21_ho_t2) C++17
100 / 100
109 ms 16952 KB
/*
燒雞
 燒雞
  燒雞    好想進選訓
 燒雞
燒雞
*/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end() 
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

const int mxn=2e5+5;
ll num[mxn];
ll gap[mxn];
ll ans[mxn];

int main() {_
    //setIO("wayne");
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n;i++){
        cin>>num[i];
    }
    for(int i=0;i<n-1;i++){
        gap[i]=num[i+1]-num[i];
    }
    pair<ll,ll> cur={0ll,0ll};
    ll pos=0;
    vector<pair<ll,ll>> vec;
    vec.push_back(cur);
    for(int i=0;i<q;i++){
        ll x;
        cin>>x;
        pos+=x;
        cur.f=max(cur.f,pos*-1);
        cur.s=max(cur.s,pos);
        vec.push_back(cur);
    }
    vector<ll> sum(q+1);
    for(int i=0;i<=q;i++){
        sum[i]=vec[i].f+vec[i].s;
    }
    for(int i=0;i<n-1;i++){
        ll gp=gap[i];
        int pos=upper_bound(all(sum),gp)-sum.begin()-1;
        if(pos==q){
            ans[i]+=vec[pos].s;
            ans[i+1]+=vec[pos].f;
        }
        else{
            if(vec[pos+1].f>vec[pos].f){
                ans[i]+=vec[pos].s;
                ans[i+1]+=gp-vec[pos].s;
            }
            else{
                ans[i]+=gp-vec[pos].f;
                ans[i+1]+=vec[pos].f;
            }
        }
    }
    ans[0]+=cur.f;
    ans[n-1]+=cur.s;
    for(int i=0;i<n;i++){
        cout<<ans[i]<<'\n';
    }
    return 0;
}
//maybe its multiset not set

Compilation message

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 472 KB Output is correct
16 Correct 1 ms 516 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory 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 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 472 KB Output is correct
16 Correct 1 ms 516 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 29 ms 7072 KB Output is correct
21 Correct 27 ms 6868 KB Output is correct
22 Correct 25 ms 6796 KB Output is correct
23 Correct 25 ms 6572 KB Output is correct
24 Correct 28 ms 7204 KB Output is correct
25 Correct 88 ms 15016 KB Output is correct
26 Correct 98 ms 14880 KB Output is correct
27 Correct 109 ms 14584 KB Output is correct
28 Correct 87 ms 14780 KB Output is correct
29 Correct 88 ms 14312 KB Output is correct
30 Correct 81 ms 13652 KB Output is correct
31 Correct 61 ms 12988 KB Output is correct
32 Correct 54 ms 13184 KB Output is correct
33 Correct 8 ms 1876 KB Output is correct
34 Correct 94 ms 15292 KB Output is correct
35 Correct 88 ms 14692 KB Output is correct
36 Correct 89 ms 14980 KB Output is correct
37 Correct 87 ms 14744 KB Output is correct
38 Correct 86 ms 14568 KB Output is correct
39 Correct 85 ms 14708 KB Output is correct
40 Correct 66 ms 14728 KB Output is correct
41 Correct 30 ms 7680 KB Output is correct
42 Correct 53 ms 13180 KB Output is correct
43 Correct 73 ms 16448 KB Output is correct
44 Correct 30 ms 7624 KB Output is correct
45 Correct 61 ms 14772 KB Output is correct
46 Correct 94 ms 16776 KB Output is correct
47 Correct 76 ms 16860 KB Output is correct
48 Correct 75 ms 16952 KB Output is correct