Submission #972137

# Submission time Handle Problem Language Result Execution time Memory
972137 2024-04-30T07:15:58 Z Halym2007 Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
27 ms 6872 KB
#include "bits/stdc++.h"
#define ll long long int
#define pb push_back
#define pii pair<ll,ll>
#define ff first
#define ss second
#define sz size()

const int N = 2e5 + 1;

using namespace std;

ll n, a[N], b[N], mod = 1e9+7, ins = 5e8+4, sum;

vector <pii> v;

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) cin >> b[i];
    v.pb({0,0});
    n++;
    for(int i = 1; i <= n; i++){
        ll w = 0;
        while(a[i] < v.back().ff){
            ll h_yzdaky = max(a[i],v[(int)v.sz-2].ff);
            ll h_aralyk = v.back().ff - h_yzdaky;
            w += v.back().ss;
            w %= mod;
            sum += w*(w+1) % mod * ins % mod * h_aralyk % mod * h_yzdaky % mod;
            sum %= mod;
            sum += w*(w+1) % mod * ins % mod * h_aralyk % mod * (h_aralyk+1) % mod * ins % mod;
            sum %= mod;
            v.pop_back();
        }
        if(v.back().ff == a[i]) v.back() = {a[i],b[i]+w+v.back().ss};
        else v.pb({a[i],b[i]+w});
    }
    cout << sum << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 7 ms 3160 KB Output is correct
4 Correct 13 ms 3928 KB Output is correct
5 Correct 17 ms 4036 KB Output is correct
6 Correct 13 ms 3932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 3 ms 2652 KB Output is correct
3 Correct 9 ms 3672 KB Output is correct
4 Correct 16 ms 4728 KB Output is correct
5 Correct 18 ms 4800 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2520 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 8 ms 3416 KB Output is correct
5 Correct 15 ms 4696 KB Output is correct
6 Correct 17 ms 4700 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 3 ms 3164 KB Output is correct
9 Correct 10 ms 4340 KB Output is correct
10 Correct 23 ms 6604 KB Output is correct
11 Correct 24 ms 6752 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2536 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2524 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2420 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 7 ms 3032 KB Output is correct
12 Correct 13 ms 3944 KB Output is correct
13 Correct 19 ms 4184 KB Output is correct
14 Correct 13 ms 3932 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 2 ms 2628 KB Output is correct
17 Correct 8 ms 3532 KB Output is correct
18 Correct 16 ms 4700 KB Output is correct
19 Correct 16 ms 4856 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 3 ms 3164 KB Output is correct
22 Correct 10 ms 4320 KB Output is correct
23 Correct 23 ms 6608 KB Output is correct
24 Correct 23 ms 6872 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 3 ms 2652 KB Output is correct
31 Correct 3 ms 2564 KB Output is correct
32 Correct 11 ms 3552 KB Output is correct
33 Correct 12 ms 3420 KB Output is correct
34 Correct 22 ms 4432 KB Output is correct
35 Correct 22 ms 4444 KB Output is correct
36 Correct 23 ms 4700 KB Output is correct
37 Correct 24 ms 4708 KB Output is correct
38 Correct 1 ms 2424 KB Output is correct
39 Correct 22 ms 4712 KB Output is correct
40 Correct 22 ms 4712 KB Output is correct
41 Correct 22 ms 4956 KB Output is correct
42 Correct 27 ms 5732 KB Output is correct