Submission #998831

# Submission time Handle Problem Language Result Execution time Memory
998831 2024-06-14T17:23:32 Z Trustfulcomic Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
77 ms 6088 KB
#include<bits/stdc++.h>
using namespace std;

#define mod 1000000007
typedef long long ll;
typedef pair<ll,ll> pii;

ll count_rect(pii a){
    return ((a.first+1)*(a.first)/2%mod)*((a.second+1)*(a.second)/2%mod)%mod;
}

pii merge(ll& result, pii& a, pii b){
    if (a.first >= b.first){
        result += count_rect(a) - count_rect({b.first, a.second});
        result %= mod;
        return {b.first, (a.second+b.second)%mod};
    } else {
        result += count_rect(b) - count_rect({a.first, b.second});
        result %= mod;
        return {a.first, (a.second+b.second)%mod};
    }
}

int main(){
    int n; cin >> n;
    vector<ll> vysky(n+1, 0);
    vector<ll> sirky(n+1, 0);
    for (int i = 0 ;i<n; i++) cin >> vysky[i];
    for (int i = 0; i<n; i++) cin >> sirky[i];

    vector<pii> stc;
    stc.push_back({-1,-1}); 
    stc.push_back({vysky[0], sirky[0]});

    ll result = 0;

    for (int i = 1; i<n+1; i++){
        if (vysky[i] > stc.back().first){
            stc.push_back({vysky[i],sirky[i]});
        } else {
            while (stc[stc.size()-2].first >= vysky[i]){
                pii novy = merge(result, stc[stc.size()-2], stc[stc.size()-1]);
                stc.pop_back(); stc.pop_back();
                stc.push_back(novy);
            }
            if (vysky[i] > stc.back().first){
                stc.push_back({vysky[i], sirky[i]});
            } else {
                pii novy = merge(result, stc.back(), {vysky[i], sirky[i]});
                stc.pop_back();
                stc.push_back(novy);
            }
        }
    }

    cout << (result+mod)%mod << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 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 16 ms 1808 KB Output is correct
4 Correct 61 ms 3016 KB Output is correct
5 Correct 37 ms 3152 KB Output is correct
6 Correct 32 ms 3144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 456 KB Output is correct
2 Correct 5 ms 604 KB Output is correct
3 Correct 23 ms 2136 KB Output is correct
4 Correct 77 ms 3780 KB Output is correct
5 Correct 49 ms 3920 KB Output is correct
6 Correct 0 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 5 ms 792 KB Output is correct
4 Correct 23 ms 1980 KB Output is correct
5 Correct 52 ms 3924 KB Output is correct
6 Correct 49 ms 3924 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 5 ms 1072 KB Output is correct
9 Correct 24 ms 2768 KB Output is correct
10 Correct 56 ms 5804 KB Output is correct
11 Correct 48 ms 6084 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 428 KB Output is correct
6 Correct 1 ms 348 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 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 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 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 0 ms 348 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 432 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 1596 KB Output is correct
12 Correct 34 ms 3016 KB Output is correct
13 Correct 34 ms 3164 KB Output is correct
14 Correct 33 ms 3156 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 604 KB Output is correct
17 Correct 24 ms 2200 KB Output is correct
18 Correct 49 ms 3924 KB Output is correct
19 Correct 52 ms 3924 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 5 ms 1116 KB Output is correct
22 Correct 24 ms 2864 KB Output is correct
23 Correct 48 ms 5832 KB Output is correct
24 Correct 51 ms 6088 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 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 604 KB Output is correct
30 Correct 6 ms 604 KB Output is correct
31 Correct 5 ms 604 KB Output is correct
32 Correct 22 ms 2112 KB Output is correct
33 Correct 24 ms 2140 KB Output is correct
34 Correct 43 ms 3656 KB Output is correct
35 Correct 49 ms 3676 KB Output is correct
36 Correct 48 ms 3904 KB Output is correct
37 Correct 48 ms 3920 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 51 ms 3908 KB Output is correct
40 Correct 47 ms 3912 KB Output is correct
41 Correct 47 ms 4176 KB Output is correct
42 Correct 49 ms 5068 KB Output is correct