Submission #1110297

# Submission time Handle Problem Language Result Execution time Memory
1110297 2024-11-09T06:54:09 Z koukirocks Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
24 ms 7868 KB
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("popcnt")
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MAX=2e5+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
const ldb eps=1e-6;
const ldb PI=acos(-1.0);
const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
template<typename T>
using vvector = vector<vector<T>>;

int main() {
    speed;
    int n;
    cin>>n;
    vector<ll> h(n+1);
    vector<ll> w(n+1);
    for (int i=1;i<=n;i++) {
        cin>>h[i];
    }
    for (int i=1;i<=n;i++) {
        ll x;
        cin>>x;
        w[i]=w[i-1]+x;
        w[i]%=P;
    }
    vector<pair<pll,ll>> stk;
    stk.push_back({{0,0},0});
    ll ans=0;
    for (int i=1;i<=n;i++) {
        while (stk.back().F.F>=h[i]) {
            stk.pop_back();
        }
        auto [p,val] = stk.back();
        auto [hh,id] = p;
        ll inv = (P+1)/2;
        ll hc = (h[i]+1)%P*h[i]%P*inv%P;
        ll ttlw = (w[i]-w[id]+P)%P;
        stk.push_back({{h[i],i},(ttlw*hc%P+val)%P});
        ll nw = (w[i]-w[i-1]+P)%P;
        ans+=((w[i]-w[i-1]+P)%P*val%P+(2*ttlw%P-nw+1+P)%P*nw%P*inv%P*hc%P)%P;
        ans%=P;
        // cout<<ans<<" ans\n";
    }
    cout<<ans<<"\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 9 ms 1744 KB Output is correct
4 Correct 22 ms 3416 KB Output is correct
5 Correct 16 ms 3156 KB Output is correct
6 Correct 16 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
3 Correct 9 ms 1104 KB Output is correct
4 Correct 19 ms 2048 KB Output is correct
5 Correct 22 ms 3920 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 11 ms 1104 KB Output is correct
5 Correct 20 ms 1872 KB Output is correct
6 Correct 21 ms 3920 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 4 ms 1296 KB Output is correct
9 Correct 11 ms 2892 KB Output is correct
10 Correct 22 ms 7380 KB Output is correct
11 Correct 24 ms 7868 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 656 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 472 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 508 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 11 ms 1616 KB Output is correct
12 Correct 17 ms 3152 KB Output is correct
13 Correct 17 ms 3152 KB Output is correct
14 Correct 16 ms 3152 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 10 ms 2128 KB Output is correct
18 Correct 19 ms 3920 KB Output is correct
19 Correct 19 ms 3920 KB Output is correct
20 Correct 1 ms 504 KB Output is correct
21 Correct 3 ms 1296 KB Output is correct
22 Correct 11 ms 3016 KB Output is correct
23 Correct 21 ms 7364 KB Output is correct
24 Correct 22 ms 7620 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 3 ms 592 KB Output is correct
31 Correct 3 ms 592 KB Output is correct
32 Correct 11 ms 1872 KB Output is correct
33 Correct 10 ms 2128 KB Output is correct
34 Correct 19 ms 3664 KB Output is correct
35 Correct 19 ms 3664 KB Output is correct
36 Correct 21 ms 3920 KB Output is correct
37 Correct 21 ms 3912 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 24 ms 3980 KB Output is correct
40 Correct 19 ms 3784 KB Output is correct
41 Correct 21 ms 4368 KB Output is correct
42 Correct 23 ms 5568 KB Output is correct