Submission #998835

# Submission time Handle Problem Language Result Execution time Memory
998835 2024-06-14T17:27:37 Z Trustfulcomic Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
17 ms 4212 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){
        pii tmp = {b.first, a.second};
        result += count_rect(a) - count_rect(tmp);
        result %= mod;
        return {b.first, (a.second+b.second)%mod};
    } else {
        pii tmp = {a.first, b.second};
        result += count_rect(b) - count_rect(tmp);
        result %= mod;
        return {a.first, (a.second+b.second)%mod};
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    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 tmp = {vysky[i], sirky[i]};
                pii novy = merge(result, stc.back(), tmp);
                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 0 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 0 ms 348 KB Output is correct
3 Correct 6 ms 1116 KB Output is correct
4 Correct 11 ms 2036 KB Output is correct
5 Correct 12 ms 2036 KB Output is correct
6 Correct 11 ms 1880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 356 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 9 ms 1116 KB Output is correct
4 Correct 17 ms 2036 KB Output is correct
5 Correct 17 ms 2040 KB Output is correct
6 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 0 ms 344 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 7 ms 1248 KB Output is correct
5 Correct 14 ms 1880 KB Output is correct
6 Correct 15 ms 2044 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 8 ms 1892 KB Output is correct
10 Correct 16 ms 4052 KB Output is correct
11 Correct 17 ms 4056 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 460 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 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 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
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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 6 ms 1116 KB Output is correct
12 Correct 11 ms 1880 KB Output is correct
13 Correct 12 ms 1884 KB Output is correct
14 Correct 12 ms 1884 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 7 ms 1116 KB Output is correct
18 Correct 14 ms 2040 KB Output is correct
19 Correct 16 ms 1884 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 856 KB Output is correct
22 Correct 8 ms 1840 KB Output is correct
23 Correct 16 ms 4212 KB Output is correct
24 Correct 17 ms 4212 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 7 ms 1116 KB Output is correct
33 Correct 8 ms 1116 KB Output is correct
34 Correct 15 ms 1884 KB Output is correct
35 Correct 17 ms 2036 KB Output is correct
36 Correct 16 ms 1884 KB Output is correct
37 Correct 16 ms 2040 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 15 ms 1884 KB Output is correct
40 Correct 15 ms 1884 KB Output is correct
41 Correct 15 ms 2396 KB Output is correct
42 Correct 15 ms 3036 KB Output is correct