Submission #1069119

#TimeUsernameProblemLanguageResultExecution timeMemory
1069119AndreyFancy Fence (CEOI20_fancyfence)C++14
100 / 100
62 ms10440 KiB
#include<bits/stdc++.h> using namespace std; const long long MOD = 1e9+7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n,ans = 0; cin >> n; vector<long long> haha(n+1); vector<long long> bruh(n+1); for(long long i = 1; i <= n; i++) { cin >> haha[i]; } for(long long i = 1; i <= n; i++) { cin >> bruh[i]; bruh[i]+=bruh[i-1]; } vector<pair<long long,long long>> wut(0); for(long long i = 1; i <= n; i++) { wut.push_back({haha[i],i}); } sort(wut.begin(),wut.end()); set<long long> idk; idk.insert(0); idk.insert(n+1); for(long long i = 0; i < n; i++) { long long p = wut[i].second,h = wut[i].first; long long r = *idk.lower_bound(p); long long l = *(--idk.upper_bound(p)); idk.insert(p); long long x = (bruh[r-1]-bruh[l])%MOD,y = (bruh[r-1]-bruh[p])%MOD,z = (bruh[p-1]-bruh[l])%MOD; ans+=((x*(x+1)/2-y*(y+1)/2-z*(z+1)/2+MOD*MOD*2)%MOD)*((h*(h+1)/2)%MOD); ans%=MOD; } cout << ans; 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...