Submission #868581

#TimeUsernameProblemLanguageResultExecution timeMemory
868581mariaclaraFancy Fence (CEOI20_fancyfence)C++17
30 / 100
1076 ms5468 KiB
#pragma GCC optimize "O3" #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef tuple<ll,ll,ll> trio; typedef pair<int,int> pii; const int MAXN = 1e5+10; const ll MOD = 1e9+7; #define all(x) x.begin(), x.end() #define mk make_pair #define pb push_back #define f first #define s second ll n, resp, h[MAXN], w[MAXN], ant[MAXN], pos[MAXN], pw[MAXN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1; i <= n; i++) cin >> h[i]; for(int i = 1; i <= n; i++) cin >> w[i], pw[i] = pw[i-1] + w[i]; for(int i = 1; i <= n; i++) ant[i] = i-1, pos[i] = i+1; for(int i = 1; i <= n; i++) { while(h[i] < h[ant[i]]) ant[i] = ant[ant[i]]; while(h[i] <= h[pos[i]]) pos[i] = pos[pos[i]]; } for(int i = 1; i <= n; i++) { ll l = ant[i]+1, r = pos[i]-1; ll tot = (((pw[r]-pw[l-1]+1)%MOD) * ((pw[r]-pw[l-1])%MOD))/2; ll casoA = (((pw[r]-pw[i]+1)%MOD) * ((pw[r]-pw[i])%MOD))/2; ll casoB = (((pw[i-1]-pw[l-1]+1)%MOD) * ((pw[i-1]-pw[l-1])%MOD))/2; resp += ((tot%MOD - casoA%MOD - casoB%MOD)%MOD) * ((h[i] * (h[i]+1) / 2)%MOD); resp %= MOD; } cout << (resp + MOD) % MOD; } // g++ -std=c++17 clara.cpp -o clara
#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...