Submission #295396

# Submission time Handle Problem Language Result Execution time Memory
295396 2020-09-09T16:20:00 Z PedroBigMan Fancy Fence (CEOI20_fancyfence) C++14
15 / 100
34 ms 7968 KB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 5000000000000000000LL

template<class A=ll> 
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}

template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}} 

ll mod=1000000007LL;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll N; cin>>N; vector<ll> h,w; In(h,N); In(w,N);
    vector<ll> NSL, NSR;
    REP(i,0,N) {NSL.pb(-1LL); NSR.pb(N);}
    vector<ll> chain; 
    REP(i,0,N)
    {
        while(chain.size()>0 && h[i]<=h[chain[chain.size()-1]]) {chain.pop_back();}
        chain.pb(i);
        if(chain.size()>1) {NSL[i]=chain[chain.size()-2];}
    }
    chain.clear();
    for(ll i=N-1;i>=0;i--)
    {
        while(chain.size()>0 && h[i]<h[chain[chain.size()-1]]) {chain.pop_back();}
        chain.pb(i);
        if(chain.size()>1) {NSR[i]=chain[chain.size()-2];}
    }
    vector<ll> ps; ll sum=0LL; ps.pb(sum); REP(i,0,N) {sum+=w[i]; sum%=mod; ps.pb(sum);}
    ll ans = (ps[N]*(ps[N]+1LL))/2LL; ans%=mod; ans*=(((h[0]*(h[0]+1LL))/2LL)%mod); ans%=mod; if(ans<0) {ans+=mod;} cout<<ans<<endl; return 0;
    ll t_ans=0LL;
    REP(s,0,N)
    {
        ll L = NSL[s]+1LL;
        ll R = NSR[s]-1LL;
        ll W1 = ps[s]-ps[L]; W1%=mod; ll W2 = ps[R+1]-ps[s+1]; W2%=mod;
        ll ans = W1*W2 + W1*w[s] + W2*w[s] + (w[s]*(w[s]+1LL))/2LL;
        ans%=mod; ans*=((h[s]*(h[s]+1LL))/2LL);
        ans%=mod; 
        t_ans+=ans; 
        t_ans%=mod;
    }
    cout<<t_ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 3 ms 1280 KB Output is correct
3 Correct 16 ms 4220 KB Output is correct
4 Correct 31 ms 7704 KB Output is correct
5 Correct 34 ms 7968 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -