Submission #790875

# Submission time Handle Problem Language Result Execution time Memory
790875 2023-07-23T09:10:23 Z 12345678 Fancy Fence (CEOI20_fancyfence) C++17
25 / 100
19 ms 6864 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll nx=1e5+5, mod=1e9+7;
ll n, ans, h, w, sm, H[nx], W[nx];
stack<pair<pair<ll, ll>, ll>> s;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    for (int i=0; i<n; i++) cin>>H[i];
    for (int i=0; i<n; i++) cin>>W[i];
    for (int i=0; i<n; i++)
    {
        ll h=H[i], w=W[i];
        ans=(ans+(((h+1)*h/2)%mod*((w+1)*w/2)%mod)%mod)%mod;
        //cout<<i<<' '<<ans<<' '<<sm<<'\n';
        ll sw=0;
        while (!s.empty()&&s.top().first.first>h)
        {
            sw+=s.top().first.second;
            sm=((sm-s.top().second)%mod+mod)%mod;
            s.pop();
        }
        ll tmp=(((h+1)*h/2)%mod*sw)%mod;
        s.push({{h, sw}, tmp});
        sm=(sm+tmp)%mod;
        ans=(ans+sm*w)%mod;
        //cout<<i<<' '<<ans<<' '<<sm<<'\n';
        tmp=(((h+1)*h/2)%mod*w)%mod;
        s.push({{h, w}, tmp});
        sm+=tmp;
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 12 ms 2636 KB Output is correct
4 Correct 19 ms 6864 KB Output is correct
5 Correct 17 ms 4896 KB Output is correct
6 Correct 16 ms 3536 KB Output is correct
# 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 0 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 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -