Submission #692548

# Submission time Handle Problem Language Result Execution time Memory
692548 2023-02-01T22:48:47 Z guagua0407 Snowball (JOI21_ho_t2) C++17
0 / 100
1 ms 504 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;
    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);
    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-1){
            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 336 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 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 336 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Halted 0 ms 0 KB -