Submission #869497

# Submission time Handle Problem Language Result Execution time Memory
869497 2023-11-04T14:00:10 Z lalig777 Fancy Fence (CEOI20_fancyfence) C++14
55 / 100
68 ms 5716 KB
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;

const int m=1e9+7;

int main(){
    int n;
    cin>>n;
    long long int res=0;
    vector<long long int>horizontales(n+1);
    vector<long long int>alturas(n);
    stack<int>pila1;
    stack<int>pila2;
    stack<int>pila3;
    vector<pair<int,int>>siguiente(n, make_pair(-1, n));
    vector<int>v(n, -1);
    for (int i=0; i<n; i++) cin>>alturas[i];
    horizontales[0]=0;
    int x;
    for (int i=0; i<n; i++){
        cin>>x;
        horizontales[i+1]=(horizontales[i]+x)%m;
    }for (int i=0; i<n; i++){
        while (!pila1.empty()){
            if (alturas[pila1.top()]>=alturas[i]) pila1.pop();
            else{
                siguiente[i].first=pila1.top();
                break;
            }
        }pila1.push(i);
        while (!pila2.empty()){
            if (alturas[pila2.top()]>=alturas[n-i-1]) pila2.pop();
            else{
                siguiente[n-i-1].second=pila2.top();
                break;
            }
        }pila2.push(n-i-1);
        while (!pila3.empty()){
            if (alturas[pila3.top()]<=alturas[i]){
                v[i]=pila3.top();
                break;
            }else pila3.pop();
        }pila3.push(i);
    }
    long long int left=0, right, top, bottom=0;
    long long int h, w;
    for (int i=0; i<n; i++){
        left=horizontales[i]-horizontales[siguiente[i].first+1];
        right=horizontales[siguiente[i].second]-horizontales[siguiente[i].first+1];
        top=alturas[i];
        if (v[i]==-1) bottom=0;
        else bottom=alturas[v[i]];
        w=(right*(right+1)-left*(left+1))/2;
        w%=m;
        h=(top*(top+1)-bottom*(bottom+1))/2;
        h%=m;
        res+=(w*h)%m;
        res%=m;
    }cout<<res<<endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 22 ms 2396 KB Output is correct
4 Correct 48 ms 4520 KB Output is correct
5 Correct 42 ms 4436 KB Output is correct
6 Correct 42 ms 4176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 6 ms 860 KB Output is correct
3 Correct 30 ms 2780 KB Output is correct
4 Correct 57 ms 5456 KB Output is correct
5 Correct 65 ms 5584 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 6 ms 824 KB Output is correct
4 Correct 29 ms 2948 KB Output is correct
5 Correct 66 ms 5336 KB Output is correct
6 Correct 68 ms 5460 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 6 ms 896 KB Output is correct
9 Correct 30 ms 2908 KB Output is correct
10 Correct 56 ms 5712 KB Output is correct
11 Correct 58 ms 5716 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -