Submission #1277670

#TimeUsernameProblemLanguageResultExecution timeMemory
1277670sasdeSnowball (JOI21_ho_t2)C++20
100 / 100
92 ms8260 KiB
#include<bits/stdc++.h> using namespace std; bool M1; #define PI 3.14159265358979323846 #define sz(a) (int)a.size() #define all(x) x.begin(),x.end() #define ii pair<int,int> #define iii pair<int,ii> #define iv pair<ii,ii> #define se second #define fi first #define ffi fi.fi #define sfi se.fi #define sse se.se #define fse fi.se #define lt(i, c, d) for(int i = c; i <= d; ++i) #define fl(i, c, d) for(int i = d; i >= c; --i) #define pb push_back #define emb emplace_back #define emf emplace_front #define em emplace //#define int long long #define look_memory cerr<<'\n'<<abs(&M2-&M1)/1024.0/1024<<'\n' #define look_time cerr << "TIME : " << clock() * 0.001 << "s" <<'\n' const int N=1e6+5,lg=30,mod=1e9+7; mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); int Rand(int u,int v){ return u+rd()%(v-u+1); } int dx[]={1,0,-1,0,1,1,-1,-1}; int dy[]={0,-1,0,1,1,-1,1,-1}; int node,query; long long a[N],pre[N],maxx[N],minn[N]; bool M2; void solve(){ cin >> node >> query; for(int i=1;i<=node;++i)cin >> a[i]; a[0]=-1e18; a[node+1]=1e18; for(int i=1;i<=query;++i){ long long x; cin >> x; pre[i]=pre[i-1]+x; minn[i]=min(minn[i-1],pre[i]); maxx[i]=max(maxx[i-1],pre[i]); // cerr<<pre[i]<<'\n'; } for(int i=1;i<=node;++i){ long long ansl=0,resl=0; long long ansr=0,resr=0; int l=0,r=query; while(l<=r){ int mid=(r+l)>>1; if(a[i]+minn[mid]>a[i-1]+maxx[mid]){ l=mid+1; resl=mid; } else r=mid-1; } if(pre[resl+1]<0)ansl=a[i]-a[i-1]-maxx[resl]; else ansl=-minn[resl]; l=0,r=query; while(l<=r){ int mid=(r+l)>>1; if(a[i]+maxx[mid]<a[i+1]+minn[mid]){ l=mid+1; resr=mid; } else r=mid-1; } if(pre[resr+1]>0)ansr=a[i+1]-a[i]+minn[resr]; else ansr=maxx[resr]; cout << ansl+ansr<<'\n'; // cerr << -minn[resl]<<'\n'; } } main() { srand(time(0)); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define task "a" if(fopen(task".inp","r")){ freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } int t=1; // cin >> t; while(t--){ solve(); // cout<<'\n'; } look_memory; look_time; }

Compilation message (stderr)

Main.cpp:78:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   78 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:86:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |       freopen(task".inp","r",stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:87:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |       freopen(task".out","w",stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...