Submission #985075

# Submission time Handle Problem Language Result Execution time Memory
985075 2024-05-17T10:25:08 Z alexdd Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
70 ms 5588 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9+7;
int n;
int h[100005];
int w[100005];
int nrp(int x)
{
    return (x*(x+1)/2LL)%MOD;
}
signed main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    deque<pair<int,int>> dq;///{h, cnt}
    int sumdq=0,rez=0;
    for(int i=1;i<=n;i++)
    {
        cin>>w[i];
        int cnt = w[i];
        while(!dq.empty() && h[i] <= dq.back().first)
        {
            cnt += dq.back().second;
            cnt %= MOD;
            sumdq = (sumdq + MOD - nrp(dq.back().first) * dq.back().second)%MOD;
            dq.pop_back();
        }
        dq.push_back({h[i],cnt});
        rez += (sumdq*w[i])%MOD + nrp(h[i]) * (((cnt - w[i] + MOD)*w[i] + nrp(w[i]))%MOD);
        rez %= MOD;
        sumdq += (nrp(h[i]) * cnt)%MOD;
        sumdq %= MOD;
    }
    cout<<rez;
    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 0 ms 444 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 Correct 1 ms 456 KB Output is correct
3 Correct 20 ms 1624 KB Output is correct
4 Correct 39 ms 2900 KB Output is correct
5 Correct 39 ms 3164 KB Output is correct
6 Correct 39 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 8 ms 604 KB Output is correct
3 Correct 28 ms 2136 KB Output is correct
4 Correct 57 ms 3796 KB Output is correct
5 Correct 59 ms 3920 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 1 ms 348 KB Output is correct
3 Correct 6 ms 604 KB Output is correct
4 Correct 28 ms 2136 KB Output is correct
5 Correct 56 ms 3856 KB Output is correct
6 Correct 59 ms 3924 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 6 ms 828 KB Output is correct
9 Correct 30 ms 2384 KB Output is correct
10 Correct 55 ms 5588 KB Output is correct
11 Correct 57 ms 5460 KB Output is correct
12 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 1 ms 348 KB Output is correct
4 Correct 1 ms 600 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 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 476 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 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 444 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 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 1 ms 348 KB Output is correct
11 Correct 20 ms 1624 KB Output is correct
12 Correct 50 ms 3076 KB Output is correct
13 Correct 41 ms 2908 KB Output is correct
14 Correct 39 ms 3160 KB Output is correct
15 Correct 1 ms 448 KB Output is correct
16 Correct 6 ms 604 KB Output is correct
17 Correct 28 ms 2152 KB Output is correct
18 Correct 57 ms 3924 KB Output is correct
19 Correct 58 ms 4012 KB Output is correct
20 Correct 2 ms 344 KB Output is correct
21 Correct 6 ms 968 KB Output is correct
22 Correct 29 ms 2392 KB Output is correct
23 Correct 60 ms 5492 KB Output is correct
24 Correct 65 ms 5456 KB Output is correct
25 Correct 1 ms 344 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 6 ms 600 KB Output is correct
31 Correct 9 ms 844 KB Output is correct
32 Correct 26 ms 2056 KB Output is correct
33 Correct 29 ms 2140 KB Output is correct
34 Correct 54 ms 3620 KB Output is correct
35 Correct 67 ms 3532 KB Output is correct
36 Correct 59 ms 3664 KB Output is correct
37 Correct 70 ms 3920 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 56 ms 3712 KB Output is correct
40 Correct 58 ms 3852 KB Output is correct
41 Correct 59 ms 3920 KB Output is correct
42 Correct 57 ms 4672 KB Output is correct