Submission #697052

#TimeUsernameProblemLanguageResultExecution timeMemory
697052vjudge1Fancy Fence (CEOI20_fancyfence)C++17
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define fi first #define se second #define pii pair<int, int> #define pll pair<ll, ll> const int mod=1e9+7, maxn=2e5+5; ll n, h[maxn], pf[maxn], w[maxn], ans, ki, ka, mid, res, leb[maxn]; ll deret(ll a, ll b) { return ((b-a+1)*(a+b)/2)%mod; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i=1; i<=n; i++) { cin >> h[i]; pf[i]=pf[i-1]; if(h[i]==2) pf[i]++; } for(int i=1; i<=n; i++) { cin >> w[i]; leb[i]=leb[i-1]+w[i]; } for(int i=1; i<=n; i++) { ki=leb[n]-leb[i-1], ka=leb[n]-leb[i]+1; ans+=deret(ka, ki), ans%=mod; if(h[i]==2) { ki=i, ka=n; while(ki<=ka) { mid=(ki+ka)/2; if(pf[mid]-pf[i-1]==mid-i+1) res=mid, ki=mid+1; else ka=mid-1; } ki=leb[res]-leb[i-1], ka=leb[res]-leb[i]+1; ans+=2*deret(ka, ki); ans%=mod; } } cout << ans << '\n'; }
#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...