Submission #692550

#TimeUsernameProblemLanguageResultExecution timeMemory
692550guagua0407Snowball (JOI21_ho_t2)C++17
100 / 100
109 ms16952 KiB
/* 燒雞 燒雞 燒雞 好想進選訓 燒雞 燒雞 */ #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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...