Submission #1033334

#TimeUsernameProblemLanguageResultExecution timeMemory
1033334vjudge1Snowball (JOI21_ho_t2)C++17
100 / 100
124 ms15496 KiB
#include "bits/stdc++.h" #define MAXN 200009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<ll,ll> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} ll arr[MAXN],w[MAXN],par[MAXN],mx[MAXN],mn[MAXN]; PII rng[3]; const ll I=1e18; bool intersect(PII a, PII b){ if(a.ff>b.ff)swap(a,b); return (b.ff<=a.ss and a.ss<=b.ss); } PII get(int pos,int ind){ return {arr[pos]+mn[ind],arr[pos]+mx[ind]}; } int main(){ //freopen("file.in", "r", stdin); int n,q; scanf("%d%d",&n,&q); for(int i=1;i<=n;i++) scanf("%lld",arr+i); arr[0]=-I; arr[n+1]=I; for(int i=1;i<=q;i++){ scanf("%lld",w+i); par[i]=par[i-1]+w[i]; mn[i]=min(mn[i-1],par[i]); mx[i]=max(mx[i-1],par[i]); } for(int i=1;i<=n;i++){ ll A=get(i,q).ff,B=get(i,q).ss; if(intersect(get(i-1,q), get(i,q))){ int st=1,en=q; while(st+1<en){ int mid=(st+en)>>1; if(intersect(get(i-1,mid), get(i,mid)))en=mid; else st=mid; } if(intersect(get(i-1,st), get(i,st)))en=st; if(w[en]<0)A=get(i-1,en).ss; else A=get(i,en).ff; } if(intersect(get(i+1,q),get(i,q))){ int st=1,en=q; while(st+1<en){ int mid=(st+en)>>1; if(intersect(get(i+1,mid),get(i,mid)))en=mid; else st=mid; } if(intersect(get(i+1,st),get(i,st)))en=st; if(w[en]<0)B=get(i,en).ss; else B=get(i+1,en).ff; } printf("%lld\n",B-A); } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d%d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~
Main.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   scanf("%lld",arr+i);
      |   ~~~~~^~~~~~~~~~~~~~
Main.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   scanf("%lld",w+i);
      |   ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...