Submission #1110293

# Submission time Handle Problem Language Result Execution time Memory
1110293 2024-11-09T06:05:33 Z koukirocks Fancy Fence (CEOI20_fancyfence) C++17
12 / 100
20 ms 3920 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++) {
        int 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+val)%P});
        ll nw = (w[i]-w[i-1]+P)%P;
        ans+=((w[i]-w[i-1]+P)%P*val%P+(2*ttlw-nw+1)%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 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 592 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 508 KB Output is correct
2 Incorrect 2 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 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 10 ms 2128 KB Output is correct
4 Incorrect 18 ms 3920 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 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 9 ms 2004 KB Output is correct
5 Incorrect 20 ms 3920 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -