Submission #644264

#TimeUsernameProblemLanguageResultExecution timeMemory
644264ItamarFancy Fence (CEOI20_fancyfence)C++14
25 / 100
19 ms4564 KiB
// CEOI.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <iostream> using namespace std; #define ll long long #include <vector> #define vll vector<ll> const int m = 1e9 + 7; ll c(ll x) { return ((x * (x - 1)) / 2) % m; } int main() { int n; cin >> n; ios_base::sync_with_stdio(false); cin.tie(NULL); vll resh(n + 2); vll h(n+2); for (int i = 0; i < n; i++) { int hi; cin >> hi; h[i + 1] = hi; } for (int i = 0; i < n; i++) { int w; cin >> w; resh[i + 1] = (resh[i] + w)%m; } vll v; vll l(n+2); vll r(n+2); for (int i = 0; i < n+2; i++) { while (!v.empty() && h[v.back()] > h[i]) { r[v.back()] = i; v.pop_back(); } v.push_back(i); } for (int i = n+1; i >=0; i--) { while (!v.empty() && h[v.back()] >= h[i]) { l[v.back()] = i; v.pop_back(); } v.push_back(i); } ll ans=0; for (int i = 1; i <= n; i++) { ans = (ans + c(h[i]+1)*((resh[i] - resh[l[i]]) * (resh[r[i] - 1] - resh[i - 1]))%m) % m; ans = (ans - c(resh[i] - resh[i - 1] ) * c(h[i] + 1)) % m; } if (ans < 0) ans += m; cout << ans; } // Run program: Ctrl + F5 or Debug > Start Without Debugging menu // Debug program: F5 or Debug > Start Debugging menu // Tips for Getting Started: // 1. Use the Solution Explorer window to add/manage files // 2. Use the Team Explorer window to connect to source control // 3. Use the Output window to see build output and other messages // 4. Use the Error List window to view errors // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
#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...