Submission #999349

# Submission time Handle Problem Language Result Execution time Memory
999349 2024-06-15T10:37:58 Z yoav_s Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
22 ms 7260 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) % mod;
    ll res = 0;
    for (ll i = 0; i < N; i++)
    {
        ll leftCnt = (widthPref[i] - widthPref[leftGeq[i] + 1] + mod) % mod;
        ll rightCnt = (widthPref[rightG[i]] - widthPref[i + 1] + mod) % mod;
        ll meCnt = ranges[i].s;
        ll intervalCnt = ((leftCnt * rightCnt) % mod) + (((meCnt * (meCnt + 1)) / 2) % mod) + (((leftCnt + rightCnt) * meCnt) % mod);
        intervalCnt %= mod;
        ll heightCnt = ranges[i].f * (ranges[i].f + 1) / 2; heightCnt %= mod;
        res += (intervalCnt * heightCnt) % mod;
        res %= mod;
    }
    cout << res << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 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 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 7 ms 3164 KB Output is correct
4 Correct 15 ms 6012 KB Output is correct
5 Correct 16 ms 6112 KB Output is correct
6 Correct 14 ms 5720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 10 ms 3676 KB Output is correct
4 Correct 19 ms 7124 KB Output is correct
5 Correct 19 ms 7260 KB Output is correct
6 Correct 0 ms 344 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 1116 KB Output is correct
4 Correct 9 ms 3672 KB Output is correct
5 Correct 19 ms 7012 KB Output is correct
6 Correct 20 ms 7172 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 2 ms 1120 KB Output is correct
9 Correct 11 ms 3676 KB Output is correct
10 Correct 19 ms 7004 KB Output is correct
11 Correct 18 ms 7060 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 Correct 0 ms 348 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 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 8 ms 3164 KB Output is correct
12 Correct 15 ms 6096 KB Output is correct
13 Correct 17 ms 5992 KB Output is correct
14 Correct 15 ms 5724 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 1116 KB Output is correct
17 Correct 9 ms 3716 KB Output is correct
18 Correct 18 ms 7004 KB Output is correct
19 Correct 20 ms 7260 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 1116 KB Output is correct
22 Correct 10 ms 3676 KB Output is correct
23 Correct 18 ms 6884 KB Output is correct
24 Correct 19 ms 7000 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 472 KB Output is correct
30 Correct 3 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 9 ms 3148 KB Output is correct
33 Correct 15 ms 3164 KB Output is correct
34 Correct 22 ms 5976 KB Output is correct
35 Correct 18 ms 5980 KB Output is correct
36 Correct 20 ms 6108 KB Output is correct
37 Correct 19 ms 6116 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 19 ms 6236 KB Output is correct
40 Correct 18 ms 6236 KB Output is correct
41 Correct 18 ms 6368 KB Output is correct
42 Correct 18 ms 7136 KB Output is correct