제출 #1342449

#제출 시각아이디문제언어결과실행 시간메모리
1342449hyyhFancy Fence (CEOI20_fancyfence)C++20
30 / 100
68 ms4252 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){
    //cout << n << " " << m << endl;
    int n2;
    int m2;
    if(n%2) n2 = (((n)%md)*(((n+1)/2)%md))%md;
    else n2 = (((n/2)%md)*((n+1)%md))%md;
    if(m%2) m2 = (((m)%md)*(((m+1)/2)%md))%md;
    else m2 = (((m/2)%md)*((m+1)%md))%md;
    return (n2*m2)%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 [h,w] = 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;
            //cout << ans << endl;
            ans = (ans-cal(ed-get<1>(mono.top()),get<2>(mono.top()))+md)%md;
            //cout << ans << endl;
        }
        mono.emplace(get<1>(mono.top()),get<1>(mono.top())+w,h);
    }
    cout << ans%md;
}
#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...