Submission #682886

# Submission time Handle Problem Language Result Execution time Memory
682886 2023-01-17T07:31:51 Z lucri Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
98 ms 5348 KB
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
//ifstream in("intrare.in");
//ofstream out("iesire.out");
long long n,h[100010],w[100010],ans,addans;
stack<pair<long long,long long>>a;
int main()
{
    cin>>n;
    a.push({0,0});
    for(int i=1;i<=n;++i)
        cin>>h[i];
    for(int i=1;i<=n;++i)
    {
        cin>>w[i];
        w[i]+=w[i-1];
    }
    for(int i=1;i<=n;++i)
    {
        while(a.top().first>=h[i])
        {
            long long ws=a.top().second;
            long long hs=a.top().first;
            a.pop();
            if(hs%2==0)
                addans-=(ws-a.top().second)%MOD*hs/2%MOD*(hs+1)%MOD;
            else
                addans-=(ws-a.top().second)%MOD*hs%MOD*(hs+1)/2%MOD;
            if(addans<0)
                addans+=MOD;
        }
        long long sg;
        if((w[i]-w[i-1])%2==0)
            sg=(w[i]-w[i-1])/2%MOD*((w[i]-a.top().second+w[i-1]+1-a.top().second)%MOD)%MOD;
        else
            sg=(w[i]-w[i-1])%MOD*((w[i]-a.top().second+w[i-1]+1-a.top().second)/2%MOD)%MOD;
        if(h[i]%2==0)
        {
            ans+=(addans*((w[i]-w[i-1])%MOD)+sg*h[i]/2%MOD*(h[i]+1)%MOD)%MOD;
            if(ans>=MOD)
                ans-=MOD;
            addans+=(w[i]-a.top().second)%MOD*h[i]/2%MOD*(h[i]+1)%MOD;
            if(addans>=MOD)
                addans-=MOD;
        }
        else
        {
            ans+=(addans*((w[i]-w[i-1])%MOD)+sg*h[i]%MOD*(h[i]+1)/2%MOD)%MOD;
            if(ans>=MOD)
                ans-=MOD;
            addans+=(w[i]-a.top().second)%MOD*h[i]%MOD*(h[i]+1)/2%MOD;
            if(addans>=MOD)
                addans-=MOD;
        }
        a.push({h[i],w[i]});
        //out<<ans<<'\n';
    }
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 32 ms 1560 KB Output is correct
4 Correct 59 ms 3000 KB Output is correct
5 Correct 52 ms 2940 KB Output is correct
6 Correct 61 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 8 ms 548 KB Output is correct
3 Correct 40 ms 2040 KB Output is correct
4 Correct 82 ms 3772 KB Output is correct
5 Correct 95 ms 3880 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 8 ms 572 KB Output is correct
4 Correct 39 ms 2044 KB Output is correct
5 Correct 75 ms 3784 KB Output is correct
6 Correct 98 ms 3872 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 8 ms 824 KB Output is correct
9 Correct 39 ms 2296 KB Output is correct
10 Correct 72 ms 5224 KB Output is correct
11 Correct 75 ms 5348 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 264 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 316 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 304 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 35 ms 1656 KB Output is correct
12 Correct 55 ms 2904 KB Output is correct
13 Correct 54 ms 2924 KB Output is correct
14 Correct 52 ms 2896 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 8 ms 576 KB Output is correct
17 Correct 42 ms 2000 KB Output is correct
18 Correct 79 ms 3688 KB Output is correct
19 Correct 76 ms 3824 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 9 ms 732 KB Output is correct
22 Correct 40 ms 2412 KB Output is correct
23 Correct 76 ms 5212 KB Output is correct
24 Correct 83 ms 5344 KB Output is correct
25 Correct 1 ms 304 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 448 KB Output is correct
30 Correct 9 ms 656 KB Output is correct
31 Correct 8 ms 552 KB Output is correct
32 Correct 36 ms 1868 KB Output is correct
33 Correct 39 ms 2036 KB Output is correct
34 Correct 77 ms 3596 KB Output is correct
35 Correct 85 ms 3568 KB Output is correct
36 Correct 79 ms 3676 KB Output is correct
37 Correct 77 ms 3776 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 89 ms 3752 KB Output is correct
40 Correct 77 ms 3780 KB Output is correct
41 Correct 80 ms 3916 KB Output is correct
42 Correct 76 ms 4744 KB Output is correct