Submission #1013592

# Submission time Handle Problem Language Result Execution time Memory
1013592 2024-07-03T17:03:47 Z daffuwu Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
27 ms 5456 KB
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

long long n, h[100069], w, dp[100069], ans, ps[100069];
const long long dv = 1e9+7;
stack<long long> stk;

long long calc(long long a, long long b)
{
    if (a%2 == 0) a/=2;
    else b/=2;
    return a%dv*(b%dv)%dv;
}

int main() 
{
    long long i, j;
    scanf("%lld", &n);
    for (i=1; i<=n; i++)
    {
        scanf("%lld", h+i);
    }
    stk.push(0);
    for (i=1; i<=n; i++)
    {
        scanf("%lld", &w);
        ps[i] = ps[i-1]+w;
        for (; h[i]<=h[stk.top()]; stk.pop());
        j = stk.top();
        ans += (calc(ps[i]-ps[j], ps[i]-ps[j]+1)-calc(ps[i-1]-ps[j], ps[i-1]-ps[j]+1))*calc(h[i], h[i]+1)%dv;
        ans += dp[j]*w%dv;
        ans %= dv;
        dp[i] = (dp[j]+calc(h[i], h[i]+1)*((ps[i]-ps[j])%dv)%dv)%dv;
        stk.push(i);
    }
    if (ans<0) ans += dv;
    printf("%lld\n", ans);
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     scanf("%lld", &n);
      |     ~~~~~^~~~~~~~~~~~
fancyfence.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         scanf("%lld", h+i);
      |         ~~~~~^~~~~~~~~~~~~
fancyfence.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%lld", &w);
      |         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 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 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 8 ms 2140 KB Output is correct
4 Correct 17 ms 3520 KB Output is correct
5 Correct 14 ms 3588 KB Output is correct
6 Correct 14 ms 3620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 9 ms 2208 KB Output is correct
4 Correct 21 ms 3920 KB Output is correct
5 Correct 21 ms 3924 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 2 ms 860 KB Output is correct
4 Correct 15 ms 2380 KB Output is correct
5 Correct 19 ms 3932 KB Output is correct
6 Correct 20 ms 3968 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 14 ms 2344 KB Output is correct
10 Correct 20 ms 4688 KB Output is correct
11 Correct 20 ms 4688 KB Output is correct
12 Correct 1 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 0 ms 448 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 1 ms 460 KB Output is correct
11 Correct 1 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 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 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 344 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 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 344 KB Output is correct
10 Correct 1 ms 452 KB Output is correct
11 Correct 8 ms 2140 KB Output is correct
12 Correct 14 ms 3932 KB Output is correct
13 Correct 16 ms 3828 KB Output is correct
14 Correct 20 ms 3928 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 8 ms 2568 KB Output is correct
18 Correct 18 ms 4692 KB Output is correct
19 Correct 17 ms 4604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 832 KB Output is correct
22 Correct 9 ms 2652 KB Output is correct
23 Correct 22 ms 5212 KB Output is correct
24 Correct 27 ms 5456 KB Output is correct
25 Correct 1 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 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 664 KB Output is correct
32 Correct 8 ms 2468 KB Output is correct
33 Correct 9 ms 2392 KB Output is correct
34 Correct 17 ms 4420 KB Output is correct
35 Correct 17 ms 4444 KB Output is correct
36 Correct 23 ms 4496 KB Output is correct
37 Correct 19 ms 4700 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 17 ms 4464 KB Output is correct
40 Correct 19 ms 4636 KB Output is correct
41 Correct 17 ms 4696 KB Output is correct
42 Correct 22 ms 4956 KB Output is correct