Submission #716871

#TimeUsernameProblemLanguageResultExecution timeMemory
716871BaytoroSnowball (JOI21_ho_t2)C++17
100 / 100
539 ms26452 KiB
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define endl '\n' #define ll long long #define int long long void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const ll INF=1e18,mod=1e9+9,N=2e5+5; void solve(){ int n,q;cin>>n>>q; vector<int> a(n+2); a[0]=-INF,a[n+1]=INF; for(int i=1;i<=n;i++) cin>>a[i]; vector<int> querys(q+1),mn(q+1),mx(q+1); set<pair<int,int>> st; for(int i=1;i<=q;i++){ cin>>querys[i]; querys[i]+=querys[i-1]; mx[i]=max(mx[i-1],querys[i]); mn[i]=min(mn[i-1],querys[i]); st.insert({mx[i]-mn[i],i}); } for(int i=1;i<=n;i++){ int A=a[i]-a[i-1]; int B=a[i+1]-a[i]; int ans=0; auto it=st.lower_bound({A,0}); if(it==st.end()) ans-=mn[q]; else{ int j=(*it).sc; ans+=(querys[j]>querys[j-1]? -mn[j] : A-mx[j]); } it=st.lower_bound({B,0}); if(it==st.end()) ans+=mx[q]; else{ int j=(*it).sc; ans+=(querys[j]<querys[j-1]? mx[j] : B+mn[j]); } cout<<ans<<endl; } } main(){ //fopn("team"); //ios; int T=1; //cin>>T; for(int i=1;i<=T;i++){ //cout<<"Case #"<<i<<": "; solve(); } }

Compilation message (stderr)

Main.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   50 | main(){
      | ^~~~
Main.cpp: In function 'void fopn(std::string)':
Main.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...