Submission #538167

# Submission time Handle Problem Language Result Execution time Memory
538167 2022-03-16T07:14:02 Z Tam_theguide Fancy Fence (CEOI20_fancyfence) C++14
0 / 100
2 ms 452 KB
#include <bits/stdc++.h>
using namespace std;
int n;
int h[100005], w[100005];
int pre[100005];
int l[100005], r[100005];
stack<int>st;
int func(int h_, int w_){
    return (h_*(h_+1)*w_*(w_+1))/4;
}
int ans=0;
int main(){
    cin>>n;
    for (int i=1;i <=n; i++){
        cin>>h[i];
    }
    for (int i=1;i <=n; i++){
        cin>>w[i];
        pre[i]=pre[i-1]+w[i];
    }
    for (int i=1;i <=n; i++){
        while (!st.empty() && h[st.top()]>h[i]){
            st.pop();
        }
        if (st.empty()){l[i]=0;}else{l[i]=st.top();};
        st.push(i);
    }
  /*  for (int i=1;i <=n;i ++){
        cout<<l[i]<<" ";
    } */
    while (st.empty()==false){
        st.pop();
    }
   // cout<<st.size();
    for (int i=n;i >=1; i--){
        while (!st.empty() && h[st.top()]>h[i]){
            st.pop();
        }
        if (st.empty()){r[i]=n+1;}else{r[i]=st.top();};
        st.push(i);
    }
  /*  for (int i=1;i <=n; i++){
        cout<<i<<" "<<l[i]<<" "<<r[i]<<'\n';
    } */
    for (int i=1;i <=n;i ++){
        int nearest=max(h[l[i]], h[r[i]]);
        int ww=pre[r[i]-1]-pre[l[i]];
        ans+=(func(h[i], ww)-func(nearest, ww));
    }
    cout<<ans;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 2 ms 452 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 2 ms 452 KB Output isn't correct
3 Halted 0 ms 0 KB -