Submission #922633

# Submission time Handle Problem Language Result Execution time Memory
922633 2024-02-05T20:50:42 Z vjudge1 Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
82 ms 4336 KB
#include<bits/stdc++.h>
#define int long long
#define ff first
#define ss second
using namespace std;
const int mod = 1'000'000'000 + 7;
struct seg{
    int l,r,h;
    
};
bool operator<(const seg& a, const seg& b){
    return a.l < b.l;
};
bool operator>(const seg& a, const seg& b){
    return a.l < b.l;
};

int sum (int l,int r)
{
    
    return ((r*r+r)/2 - (l*l-l)/2)%mod;
}

const int dva = 500000004LL;

void solve()
{

    int n;
    cin >> n;
    int at = 0;
    vector<seg> v(n);
    for (int i = 0; i<n; i++)
    {
        int aew;
        cin >> aew;
        v[i].h = aew;
    }
    for (int i = 0; i < n; i++)
    {
        int w;
        cin >> w;
        v[i].l = at;
        v[i].r = at+w-1;
        at=v[i].r+1;
    }
    int ans = 0;
    int cur = 0;
    set<pair<int,int>> cat;
    
    
    cat.insert({v[0].l,v[n-1].r});
    

    auto remove = [&](seg x)
    {
        auto it = cat.upper_bound({x.l,x.r}); 
        pair<int,int> st;
        if (it != cat.end());
        st = *it;
        if (it == cat.end() || !(x.l >= st.ff && x.r <= st.ss))
            --it;
        pair<int,int> big = *it;
      
        int biglen = big.ss-big.ff+1;
        int oduz =(int)((((__uint128_t)biglen)*((__uint128_t)biglen)+((__uint128_t)biglen))/((__uint128_t)2)%mod);
        cur-=oduz;
        cur+=7*mod;
        cur%=mod;

        if (x.l-1 >= big.ff)
            cat.insert({big.ff,x.l-1});
        if (x.r+1 <= big.ss)
            cat.insert({x.r+1,big.ss});
        

        int len1 = max(0LL,(x.l-1 - big.ff)+1);
        int len2 = max(0LL,big.ss - x.r);

        int oduz1 =(int)((((__uint128_t)len1)*((__uint128_t)len1)+((__uint128_t)len1))/((__uint128_t)2)%mod);
        int oduz2 =(int)((((__uint128_t)len2)*((__uint128_t)len2)+((__uint128_t)len2))/((__uint128_t)2)%mod);

        cat.erase(big);
        cur+=oduz1+oduz2;
        cur%=mod;
    };
    auto comp = [&](seg& mile, seg& alen){
        return (mile.h < alen.h);
    };
    int globallen = (v[n-1].r - v[0].l + 1);
    sort(v.begin(),v.end(),comp);
    int prev = 0;
    int same = 0;
    
    globallen%=mod;
    cur = globallen*globallen+globallen;
    cur%=mod;
    cur*=dva;
    cur%=mod;

    for (int i = 0; i < n; i++)
    {
       
        
        
        if (i!=0 && v[i].h != v[i-1].h)
        {
            ans+=(cur*(sum(prev+1,v[i-1].h)))%mod;
            ans%=mod;
            for (int j = i-1; j >= same; j--)
                remove(v[j]);
            
            same = i;
            prev = v[i-1].h;
        }
    }

    ans+=(cur*(sum(prev+1,v[n-1].h)))%mod;
    ans%=mod;

    cout << ans << '\n';
    return;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input1.txt", "r", stdin);
    solve();
    
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 13 ms 2152 KB Output is correct
4 Correct 28 ms 3676 KB Output is correct
5 Correct 26 ms 4284 KB Output is correct
6 Correct 17 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 8 ms 1628 KB Output is correct
4 Correct 17 ms 2648 KB Output is correct
5 Correct 17 ms 2652 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 500 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 11 ms 1628 KB Output is correct
5 Correct 17 ms 2648 KB Output is correct
6 Correct 18 ms 2652 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 10 ms 1624 KB Output is correct
10 Correct 22 ms 2648 KB Output is correct
11 Correct 23 ms 2652 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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
6 Correct 1 ms 500 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 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 13 ms 2156 KB Output is correct
12 Correct 28 ms 3668 KB Output is correct
13 Correct 26 ms 4188 KB Output is correct
14 Correct 17 ms 3164 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 11 ms 1628 KB Output is correct
18 Correct 17 ms 2652 KB Output is correct
19 Correct 19 ms 2652 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 4 ms 604 KB Output is correct
22 Correct 10 ms 1628 KB Output is correct
23 Correct 24 ms 2648 KB Output is correct
24 Correct 23 ms 2712 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 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 6 ms 860 KB Output is correct
31 Correct 5 ms 700 KB Output is correct
32 Correct 30 ms 2396 KB Output is correct
33 Correct 30 ms 2148 KB Output is correct
34 Correct 63 ms 4180 KB Output is correct
35 Correct 59 ms 4176 KB Output is correct
36 Correct 65 ms 4336 KB Output is correct
37 Correct 82 ms 4176 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 58 ms 2904 KB Output is correct
40 Correct 37 ms 2652 KB Output is correct
41 Correct 27 ms 2652 KB Output is correct
42 Correct 29 ms 2652 KB Output is correct