답안 #373469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373469 2021-03-04T18:03:09 Z jenkinsser Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
50 ms 3212 KB
#include <bits/stdc++.h>
#define FOR(ii,aa,bb) for(int ii=aa;ii<bb;ii++)
#define for0(ii,bb) FOR(ii,0,bb)
#define for1(ii,bb) FOR(ii,1,bb+1)
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define pii pair<int,int>
#define piii pair<pii,int>
#define sp " "
#define nl "\n"
#define all(x) x.begin(),x.end()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long

using namespace std;

const long long mod = 1000000007;
const int N = 1e5+5;

ll n,ans,h[N],w[N];
vector<int> sections;
int par[N];
bool d[N];

bool f(int x,int y){
    return h[x]>h[y];
}

ll comb2(ll x){
    x%=mod;
    return x*(x-1)/2%mod;
}

ll rec(ll x,ll y){
    return comb2(x+1)*comb2(y+1)%mod;
}

int findSet(int x){
    if(par[x]<0)return x;
    return par[x]=findSet(par[x]);
}

void onion(int x,int y,ll high){
    x=findSet(x);
    y=findSet(y);
    ll h=(rec(high,w[x])+rec(high,w[y]))%mod;
    h=(rec(high,w[x]+w[y])-h+mod)%mod;
    ans=(ans+h)%mod;
    if(par[x]<par[y]){
        par[y]=x;
        w[x]=(w[x]+w[y])%mod;
    }
    else{
        if(par[x]==par[y])
            par[y]--;
        par[x]=y;
        w[y]=(w[x]+w[y])%mod;
    }
}

int32_t main(){
    fastio()
    cin >> n;
    vector<int> vec;
    for0(i,n)
        cin >> h[i];
    for0(i,n){
        cin >> w[i];
        vec.pb(i);
        par[i]=-1;
    }
    sort(vec.begin(),vec.end(),f);
    for0(i,n)
        ans+=rec(h[i],w[i]);
    for(int i:vec){
        if(i!=0&&d[i-1])onion(i-1,i,h[i]);
        if(i!=n-1&&d[i+1])onion(i,i+1,h[i]);
        d[i]=1;
    }
    cout << ans << nl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 15 ms 1648 KB Output is correct
4 Correct 29 ms 2924 KB Output is correct
5 Correct 30 ms 2924 KB Output is correct
6 Correct 32 ms 2924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 620 KB Output is correct
3 Correct 18 ms 1648 KB Output is correct
4 Correct 33 ms 2924 KB Output is correct
5 Correct 41 ms 2924 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 4 ms 620 KB Output is correct
4 Correct 17 ms 1648 KB Output is correct
5 Correct 33 ms 2924 KB Output is correct
6 Correct 36 ms 2924 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 4 ms 620 KB Output is correct
9 Correct 18 ms 1648 KB Output is correct
10 Correct 33 ms 2924 KB Output is correct
11 Correct 34 ms 2924 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 396 KB Output is correct
11 Correct 15 ms 1648 KB Output is correct
12 Correct 32 ms 3072 KB Output is correct
13 Correct 30 ms 2924 KB Output is correct
14 Correct 29 ms 2924 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 620 KB Output is correct
17 Correct 17 ms 1648 KB Output is correct
18 Correct 33 ms 2924 KB Output is correct
19 Correct 37 ms 3180 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 4 ms 620 KB Output is correct
22 Correct 17 ms 1648 KB Output is correct
23 Correct 33 ms 2924 KB Output is correct
24 Correct 39 ms 3072 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 5 ms 620 KB Output is correct
31 Correct 5 ms 620 KB Output is correct
32 Correct 20 ms 2004 KB Output is correct
33 Correct 22 ms 1648 KB Output is correct
34 Correct 45 ms 3180 KB Output is correct
35 Correct 41 ms 3180 KB Output is correct
36 Correct 46 ms 2924 KB Output is correct
37 Correct 49 ms 3184 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 47 ms 3200 KB Output is correct
40 Correct 50 ms 3212 KB Output is correct
41 Correct 37 ms 3208 KB Output is correct
42 Correct 35 ms 3180 KB Output is correct