답안 #866716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866716 2023-10-26T21:02:52 Z Lalic Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
57 ms 6252 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 1e5+10;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9+7;
const ll inv2 = 500000004;

ll gauss(ll a){ return (((a*(a+1))%MOD)*inv2)%MOD; }

void solve(){
    int n; cin >> n;

    vector<pair<ll, pll>> arr(n);
    ll id=0;
    for(int i=0;i<n;i++)
        cin >> arr[i].fi;
    for(int i=0;i<n;i++){
        arr[i].se.fi=id;

        ll x; cin >> x;
        id+=x;

        arr[i].se.se=id;
    }

    set<pair<pll, ll>> st;
    st.insert({{0, arr[n-1].se.se}, 0});

    sort(all(arr));

    ll ans=0;
    for(int i=0;i<n;i++){
        auto aux=st.upper_bound({{arr[i].se.fi+1, -1}, -1});
        aux--;

        pair<pll, ll> curr=*aux;
        st.erase(aux);

        ans+=(((gauss((arr[i].fi)%MOD)-gauss((curr.se)%MOD)+MOD)%MOD)*gauss((curr.fi.se-curr.fi.fi)%MOD))%MOD;
        ans%=MOD;

        if(arr[i].se.fi!=curr.fi.fi)
            st.insert({{curr.fi.fi, arr[i].se.fi}, arr[i].fi});
        if(arr[i].se.se!=curr.fi.se)
            st.insert({{arr[i].se.se, curr.fi.se}, arr[i].fi});
    }

    cout << ans << "\n";
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    // freopen("fetiera.in", "r", stdin);

    int tt=1;
    // cin >> tt;
    while(tt--)
        solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 16 ms 2908 KB Output is correct
4 Correct 32 ms 4732 KB Output is correct
5 Correct 33 ms 5296 KB Output is correct
6 Correct 26 ms 4436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 11 ms 1628 KB Output is correct
4 Correct 22 ms 2648 KB Output is correct
5 Correct 22 ms 2648 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 12 ms 1628 KB Output is correct
5 Correct 25 ms 2652 KB Output is correct
6 Correct 22 ms 2652 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 11 ms 1628 KB Output is correct
10 Correct 21 ms 2652 KB Output is correct
11 Correct 20 ms 2652 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 480 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 500 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 17 ms 2908 KB Output is correct
12 Correct 33 ms 4756 KB Output is correct
13 Correct 32 ms 5204 KB Output is correct
14 Correct 25 ms 4444 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 752 KB Output is correct
17 Correct 11 ms 2396 KB Output is correct
18 Correct 23 ms 4700 KB Output is correct
19 Correct 24 ms 4840 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 11 ms 2396 KB Output is correct
23 Correct 20 ms 4444 KB Output is correct
24 Correct 22 ms 4700 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 5 ms 860 KB Output is correct
31 Correct 6 ms 1116 KB Output is correct
32 Correct 23 ms 3164 KB Output is correct
33 Correct 25 ms 3152 KB Output is correct
34 Correct 53 ms 6096 KB Output is correct
35 Correct 48 ms 5992 KB Output is correct
36 Correct 57 ms 6252 KB Output is correct
37 Correct 56 ms 6224 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 48 ms 4976 KB Output is correct
40 Correct 35 ms 4700 KB Output is correct
41 Correct 26 ms 4720 KB Output is correct
42 Correct 21 ms 4688 KB Output is correct