Submission #999346

# Submission time Handle Problem Language Result Execution time Memory
999346 2024-06-15T10:33:54 Z yoav_s Fancy Fence (CEOI20_fancyfence) C++17
12 / 100
1 ms 512 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<vv> vvv;
typedef pair<ll,ll> p;
typedef vector<p> vp;
typedef vector<vp> vvp;
typedef vector<vvp> vvvp;
typedef pair<ll, p> tri;
typedef vector<tri> vtri;
typedef vector<vtri> vvtri;
typedef vector<vvtri> vvvtri;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;

#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()

const ll INF = 1e18;
const ll mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll N;
    cin >> N;
    vp ranges(N);
    for (ll i= 0; i < N; i++) cin >> ranges[i].f;
    for (ll i = 0; i < N; i++) cin >> ranges[i].s;
    v leftGeq(N, -1), rightG(N, N);
    stack<p> s;
    for (ll i = 0; i < N; i++)
    {
        while (!s.empty() && s.top().f > ranges[i].f) s.pop();
        if (!s.empty()) leftGeq[i] = s.top().s;
        s.emplace(ranges[i].f, i);
    }
    s = stack<p>();
    for (ll i = N - 1; i >= 0; i--)
    {
        while (!s.empty() && s.top().f >= ranges[i].f) s.pop();
        if (!s.empty()) rightG[i] = s.top().s;
        s.emplace(ranges[i].f, i);
    }
    v widthPref(N + 1, 0);
    for (ll i = 1; i <= N; i++) widthPref[i] = widthPref[i -  1] + ranges[i - 1].s;
    ll res = 0;
    for (ll i = 0; i < N; i++)
    {
        ll leftCnt = widthPref[i] - widthPref[leftGeq[i] + 1];
        ll rightCnt = widthPref[rightG[i]] - widthPref[i + 1];
        ll meCnt = ranges[i].s;
        ll intervalCnt = leftCnt * rightCnt + (meCnt * (meCnt + 1)) / 2 + (leftCnt + rightCnt) * meCnt;
        intervalCnt %= mod;
        ll heightCnt = ranges[i].f * (ranges[i].f + 1) / 2; heightCnt %= mod;
        res += (intervalCnt * heightCnt) % mod;
    }
    cout << res % mod << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 460 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 0 ms 348 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 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 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 464 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 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 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -