Submission #876177

# Submission time Handle Problem Language Result Execution time Memory
876177 2023-11-21T11:01:28 Z asdasdqwer Fancy Fence (CEOI20_fancyfence) C++14
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define pii pair<int, int>

const int MOD = 1e9 + 7;

signed main() {
    int n;cin>>n;
    vector<pii> tog(n);
    for (auto &x:tog)cin>>x.first;
    for (auto &x:tog)cin>>x.second;

    stack<pii> s;
    int cmSum=0;
    int res=0;
    for (int i=0;i<n;i++) {
        int w=tog[i].second, h=tog[i].first;
        while (s.size() && s.top().first >= h) s.pop();
        
        cmSum += w;
        cmSum %= MOD;

        if (s.size()) {
            int leftBound = s.top().second;
            int heightSum = ((((h * (h+1)) % MOD) * 500000004) % MOD);
            int exp = ((cmSum - leftBound) + 2*MOD) % MOD;
            int widthSum = ((((((cmSum * (cmSum+1))) % MOD) * 500000004) % MOD) - ((((exp * (exp + 1)) % MOD) * 500000004) % MOD) + 2 * MOD) % MOD;
            res += (heightSum * widthSum) % MOD;
            // cout << (heightSum * widthSum) % MOD << "\n";
        }

        else {
            int heightSum = ((((h * (h+1)) % MOD) * 500000004) % MOD);
            int widthSum = (((((cmSum * (cmSum+1))) % MOD) * 500000004) % MOD);
            res += (heightSum * widthSum) % MOD;
            // cout << (heightSum * widthSum) % MOD << "\n";
        }

        s.push({h, cmSum});
    }

    cout << res << "\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -