Submission #930723

# Submission time Handle Problem Language Result Execution time Memory
930723 2024-02-20T10:21:28 Z LucaIlie Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
82 ms 2180 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e5;
const int MOD = 1e9 + 7;
int h[MAX_N], w[MAX_N], p[MAX_N];
vector <int> s;

int lgPut( int x, int n ) {
    if ( n == 0 )
        return 1;

    int p = lgPut( x, n / 2 );
    p = (long long)p * p % MOD;
    if ( n % 2 == 1 )
        p = (long long)p * x % MOD;

    return p;
}

const int inv2 = (MOD + 1) / 2;
int nchoose2( int n ) {
    return (long long)n * (n + 1) % MOD * inv2 % MOD;
}

int main() {
    int n;

    cin >> n;
    for ( int i = 0; i < n; i++ )
        cin >> h[i];
    for ( int i = 0; i < n; i++ )
        cin >> w[i];


    int ans = 0, sum = 0;
    for ( int i = 0; i < n; i++ ) {
        while ( !s.empty() && h[i] < h[s.back()] ) {
            sum = (sum - (long long)nchoose2( h[s.back()] ) * p[s.back()] % MOD + MOD) % MOD;
            p[i] = (p[i] + p[s.back()]) % MOD;
            s.pop_back();
        }
        s.push_back( i );

        sum = (sum + (long long)nchoose2( h[i] ) * p[i]) % MOD;
        ans = (ans + (long long)nchoose2( h[i] ) * nchoose2( w[i] )) % MOD;
        ans = (ans + (long long)sum * w[i]) % MOD;
        sum = (sum + (long long)nchoose2( h[i] ) * w[i]) % MOD;

        p[i] = (p[i] + w[i]) % MOD;
    }

    cout << ans << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 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 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 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 1 ms 348 KB Output is correct
3 Correct 23 ms 1032 KB Output is correct
4 Correct 51 ms 2012 KB Output is correct
5 Correct 46 ms 1904 KB Output is correct
6 Correct 46 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 7 ms 604 KB Output is correct
3 Correct 34 ms 1340 KB Output is correct
4 Correct 67 ms 1996 KB Output is correct
5 Correct 76 ms 2180 KB Output is correct
6 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 1 ms 348 KB Output is correct
3 Correct 7 ms 500 KB Output is correct
4 Correct 34 ms 1240 KB Output is correct
5 Correct 82 ms 1996 KB Output is correct
6 Correct 70 ms 2044 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 8 ms 856 KB Output is correct
9 Correct 34 ms 1240 KB Output is correct
10 Correct 64 ms 2000 KB Output is correct
11 Correct 66 ms 1912 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 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 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 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 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 600 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 348 KB Output is correct
10 Correct 1 ms 448 KB Output is correct
11 Correct 23 ms 1056 KB Output is correct
12 Correct 52 ms 2144 KB Output is correct
13 Correct 45 ms 1884 KB Output is correct
14 Correct 45 ms 1652 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 7 ms 604 KB Output is correct
17 Correct 42 ms 1296 KB Output is correct
18 Correct 67 ms 1996 KB Output is correct
19 Correct 69 ms 2000 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 7 ms 744 KB Output is correct
22 Correct 35 ms 1232 KB Output is correct
23 Correct 64 ms 2096 KB Output is correct
24 Correct 66 ms 2000 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 7 ms 348 KB Output is correct
31 Correct 7 ms 348 KB Output is correct
32 Correct 32 ms 912 KB Output is correct
33 Correct 40 ms 856 KB Output is correct
34 Correct 64 ms 1476 KB Output is correct
35 Correct 64 ms 1360 KB Output is correct
36 Correct 68 ms 1568 KB Output is correct
37 Correct 68 ms 1364 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 67 ms 1468 KB Output is correct
40 Correct 69 ms 1568 KB Output is correct
41 Correct 68 ms 1552 KB Output is correct
42 Correct 67 ms 1796 KB Output is correct