Submission #534879

#TimeUsernameProblemLanguageResultExecution timeMemory
534879vectorFancy Fence (CEOI20_fancyfence)C++17
0 / 100
2 ms460 KiB
#include<bits/stdc++.h> #define MOD 1000000007 #define SIZE 100010 using namespace std; typedef long long ll; struct st2 { ll h,w,idx; }; ll N,psum[SIZE],ans; pair<ll,ll>seg[SIZE<<2]; st2 A[SIZE]; vector<st2>v; void init(ll l,ll r,ll node) { if(l==r){ seg[node]={v[l].h,v[l].h}; return; } ll mid=l+r>>1; init(l,mid,node<<1); init(mid+1,r,node<<1|1); seg[node]={max(seg[node<<1].first,seg[node<<1|1].first),min(seg[node<<1].second,seg[node<<1|1].second)}; } pair<ll,ll>query(ll l,ll r,ll node,ll s,ll e) { if(l>e||r<s||s>e)return {0,1e18}; if(l==r)return seg[node]; ll mid=l+r>>1; pair<ll,ll>p=query(l,mid,node<<1,s,e),q=query(mid+1,r,node<<1|1,s,e); return {max(p.first,q.first),min(p.second,q.second)}; } ll S(ll x) { return (x*(x+1)/2)%MOD; } int main() { ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>N; for(int i=1;i<=N;i++)cin>>A[i].h; for(int i=1;i<=N;i++)cin>>A[i].w; bool f=false; st2 temp={0,0,0}; v.push_back(temp); for(int i=1;i<=N;i++){ if(f){ if(temp.h==A[i].h)temp.w+=A[i].w; else{ v.push_back(temp); f=false; } } if(!f){ temp.h=A[i].h; temp.w=A[i].w; f=true; } } v.push_back(temp); N=v.size()-1; assert(N==1); for(int i=1;i<=N;i++){ v[i].idx=i; //printf("[%lld %lld %lld]\n",v[i].h,v[i].w,v[i].idx); psum[i]=psum[i-1]+v[i].w; } init(1,N,1); for(int i=1;i<=N;i++){ ll l=1,r=i,mid,a,b,c,d,mx=0; pair<ll,ll>t; while(l<r){ mid=l+r>>1; t=query(1,N,1,mid,i); if(t.second>=v[i].h)r=mid; else l=mid+1; } a=r; l=i,r=N; while(l<r){ mid=l+r+1>>1; t=query(1,N,1,i,mid); if(t.second>=v[i].h)l=mid; else r=mid-1; } b=l; l=1,r=i; while(l<r){ mid=l+r>>1; t=query(1,N,1,mid,i); if(t.first<=v[i].h)r=mid; else l=mid+1; } c=r; l=i,r=N; while(l<r){ mid=l+r+1>>1; t=query(1,N,1,i,mid); if(t.first<=v[i].h)l=mid; else r=mid-1; } d=l; mx=max(query(1,N,1,c,i-1).first,query(1,N,1,i+1,d).first); ans=(ans+S(psum[b]-psum[a-1])*(S(v[i].h)-S(mx)+MOD))%MOD; } cout<<ans; }

Compilation message (stderr)

fancyfence.cpp: In function 'void init(ll, ll, ll)':
fancyfence.cpp:20:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |     ll mid=l+r>>1;
      |            ~^~
fancyfence.cpp: In function 'std::pair<long long int, long long int> query(ll, ll, ll, ll, ll)':
fancyfence.cpp:29:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |     ll mid=l+r>>1;
      |            ~^~
fancyfence.cpp: In function 'int main()':
fancyfence.cpp:73:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   73 |             mid=l+r>>1;
      |                 ~^~
fancyfence.cpp:81:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   81 |             mid=l+r+1>>1;
      |                 ~~~^~
fancyfence.cpp:89:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   89 |             mid=l+r>>1;
      |                 ~^~
fancyfence.cpp:97:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   97 |             mid=l+r+1>>1;
      |                 ~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...