Submission #1342442

#TimeUsernameProblemLanguageResultExecution timeMemory
1342442hyyhFancy Fence (CEOI20_fancyfence)C++20
0 / 100
1 ms344 KiB
#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <iomanip>
#include <set>
#include <bitset>

#define int long long

using namespace std;
using ll = long long;
using pii = pair<int,int>;
using piii = tuple<int,int,int>;
#define endl '\n'
#define f first
#define s second
#define all(x) begin(x),end(x)

int const md = 1e9+7;

int cal(int n,int m){
    return (((n*(n+1))/2)%md)*(((m*(m+1))/2)%md);
}

signed main(){
    int n;cin >> n;
    vector<pii> vc(n);
    for(int i{};i < n;i++){
        cin >> vc[i].f;
    }
    for(int i{};i < n;i++){
        cin >> vc[i].s;
    }
    vc.emplace_back(0,0);
    stack<piii> mono;//start, end, hight
    int ans = 0;
    mono.emplace(0,0,0);
    for(int i{};i <= n;i++){
        auto [w,h] = vc[i];
        int ed = get<1>(mono.top());
        while(get<2>(mono.top()) > h){
            auto [stt,edt,ht] = mono.top();mono.pop();
            ans = (ans+cal(ed-stt,ht))%md;
            ans = (ans-cal(ed-get<1>(mono.top()),get<2>(mono.top())));
        }
        mono.emplace(get<1>(mono.top()),get<1>(mono.top())+w,h);
    }
    cout << ans;
}
#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...