Submission #464294

#TimeUsernameProblemLanguageResultExecution timeMemory
464294osmanallazovFancy Fence (CEOI20_fancyfence)C++14
100 / 100
117 ms5392 KiB
#include <bits/stdc++.h> #define DIM 100010 #define MOD 1000000007 using namespace std; long long h[DIM],w[DIM]; deque<pair <long long,long long> > d; int n,i; int main (){ cin>>n; for (i=1;i<=n;i++) cin>>h[i]; for (i=1;i<=n;i++) cin>>w[i]; n++; d.push_back(make_pair(0,0)); long long sol = 0; for (i=1;i<=n;i++){ long long latime = 0; while (!d.empty() && h[i] < d.back().first){ long long h_ant = max (h[i],d[d.size()-2].first); long long dif = (d.back().first - h_ant + MOD) % MOD; latime = (latime + d.back().second) % MOD; sol += ( dif * (dif + 1) / 2 % MOD + dif * h_ant % MOD) % MOD * (1LL * latime * (latime+1) / 2 % MOD) % MOD; sol %= MOD; d.pop_back(); } w[i] = (w[i] + latime) % MOD; if (h[i] == d.back().first) d.back().second = (d.back().second + w[i]) % MOD; else d.push_back(make_pair(h[i],w[i])); } cout<<(sol+MOD)%MOD; 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...