Submission #1110297

#TimeUsernameProblemLanguageResultExecution timeMemory
1110297koukirocksFancy Fence (CEOI20_fancyfence)C++17
100 / 100
24 ms7868 KiB
#include <bits/stdc++.h> #define speed ios_base::sync_with_stdio(0); cin.tie(0) #define all(x) (x).begin(),(x).end() #define F first #define S second //#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx,avx2") //#pragma GCC target("popcnt") using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll MAX=2e5+10,P=1e9+7; const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f; const ldb eps=1e-6; const ldb PI=acos(-1.0); const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; template<typename T> using vvector = vector<vector<T>>; int main() { speed; int n; cin>>n; vector<ll> h(n+1); vector<ll> w(n+1); for (int i=1;i<=n;i++) { cin>>h[i]; } for (int i=1;i<=n;i++) { ll x; cin>>x; w[i]=w[i-1]+x; w[i]%=P; } vector<pair<pll,ll>> stk; stk.push_back({{0,0},0}); ll ans=0; for (int i=1;i<=n;i++) { while (stk.back().F.F>=h[i]) { stk.pop_back(); } auto [p,val] = stk.back(); auto [hh,id] = p; ll inv = (P+1)/2; ll hc = (h[i]+1)%P*h[i]%P*inv%P; ll ttlw = (w[i]-w[id]+P)%P; stk.push_back({{h[i],i},(ttlw*hc%P+val)%P}); ll nw = (w[i]-w[i-1]+P)%P; ans+=((w[i]-w[i-1]+P)%P*val%P+(2*ttlw%P-nw+1+P)%P*nw%P*inv%P*hc%P)%P; ans%=P; // cout<<ans<<" ans\n"; } cout<<ans<<"\n"; return 0; }
#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...