Submission #930366

# Submission time Handle Problem Language Result Execution time Memory
930366 2024-02-19T13:00:20 Z haxorman Fancy Fence (CEOI20_fancyfence) C++14
30 / 100
22 ms 5948 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int mxN = 1e5 + 7;
const int MOD = 1e9 + 7;

int pref[mxN], nex[mxN], add[mxN];
pair<int,int> arr[mxN];

int nc2(int n) {
    return n * (n - 1) / 2;
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int n;
    cin >> n;

    for (int i = 1; i <= n; ++i) {
        cin >> arr[i].first;
    }

    for (int i = 1; i <= n; ++i) {
        cin >> arr[i].second;
        pref[i] = pref[i - 1] + arr[i].second;
    }
    
    vector<int> st = {n + 1};
    for (int i = n; i >= 1; --i) {
        while (st.size() && arr[i].first <= arr[st.back()].first) {
            st.pop_back();
        }
        assert(st.size());
        nex[i] = st.back();
        st.push_back(i);
    }

    int ans = 0, sub = 0;
    for (int i = 1; i <= n; ++i) {
        sub -= add[i];

        int w = (pref[nex[i] - 1] - pref[i - 1]) % MOD;
        ans += (nc2(arr[i].first + 1) - sub) % MOD * (nc2(w + 1) % MOD) % MOD;
        ans %= MOD;
        
        add[nex[i]] += (nc2(arr[i].first + 1) - sub);
        sub = nc2(arr[i].first + 1);
    }
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 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 2 ms 860 KB Output is correct
3 Correct 12 ms 4204 KB Output is correct
4 Correct 17 ms 5324 KB Output is correct
5 Correct 19 ms 5404 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 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 2 ms 988 KB Output is correct
4 Correct 9 ms 4120 KB Output is correct
5 Correct 18 ms 5460 KB Output is correct
6 Correct 22 ms 5948 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 856 KB Output is correct
9 Correct 10 ms 4396 KB Output is correct
10 Correct 20 ms 5528 KB Output is correct
11 Correct 17 ms 5468 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 0 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 348 KB Output isn't correct
3 Halted 0 ms 0 KB -