Submission #963079

# Submission time Handle Problem Language Result Execution time Memory
963079 2024-04-14T13:27:46 Z anton Fancy Fence (CEOI20_fancyfence) C++17
25 / 100
19 ms 3184 KB
#include<bits/stdc++.h>

using namespace std;
#define int long long
#define pii pair<int,int>

const int MAX_N = 1e5+1;
const int mod =1e9+7;

int h[MAX_N];
int w[MAX_N];

int nbp(int u){
    return (u*(u+1LL)/2LL)%mod;
}
struct stak{
    int s =0;
    vector<pii> st;
    stak(){
        st.push_back({0, 0});
    }

    void insert(pii val){
        while(st.back().second>=val.second){
            auto e= st.back();
            val.first+=e.first;
            s = (s+mod-(nbp(e.second)*e.first)%mod)%mod;
            st.pop_back();
        }
        s =(s+nbp(val.second)*val.first)%mod;
        st.push_back(val);
    }
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; 
    cin>>n;
    int sw = 0;
    vector<pair<int, int>> ev;
    for(int i = 0; i<n; i++){
        cin>>h[i];
    }
    for(int i = 0; i<n; i++){
        cin>>w[i];
    }
    int res= 0;
    auto s = stak();
    for(int i = 0; i<n; i++){
        res = (res+ (nbp(w[i]) * nbp(h[i]))%mod)%mod;
        
        s.insert({0, h[i]});
        res = (res + (w[i]*s.s)%mod)%mod;
        s.insert({w[i], h[i]});
        
    }

    cout<<res<<endl;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:41:9: warning: unused variable 'sw' [-Wunused-variable]
   41 |     int sw = 0;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 Correct 0 ms 432 KB Output is correct
3 Correct 1 ms 344 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 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 8 ms 1628 KB Output is correct
4 Correct 18 ms 3160 KB Output is correct
5 Correct 19 ms 3184 KB Output is correct
6 Correct 15 ms 3160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 2 ms 604 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 Correct 1 ms 348 KB Output is correct
3 Incorrect 2 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -