Submission #572517

# Submission time Handle Problem Language Result Execution time Memory
572517 2022-06-04T15:24:41 Z teki Fancy Fence (CEOI20_fancyfence) C++11
100 / 100
43 ms 7536 KB
#include <bits/stdc++.h>

typedef long long ll;

#define pb push_back
#define MS(x,y) memset((x),(y),sizeof((x)))
#define MN 1000000007

using namespace std;

ll n, curr = 0, res = 0, x = 0;
ll h[100001],w[100001];

ll calcZbir(ll w) {
    w %= MN;
    return (w*(w-1)/2)%MN;
}

int main()
{
    #if LOCAL_DEBUG
        fstream cin("in.txt");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for (int i = 0; i<n; i++) cin>>h[i];
    for (int i = 0; i<n; i++) cin>>w[i];
    n++;

    stack<pair<ll,ll>> st;
    st.push({0,-1});

    for (int i = 0; i<n; i++) {
        vector<pair<ll,ll>> v2;

        while(st.top().second >= h[i]) {
            v2.pb(st.top());
            st.pop();
            v2.back().first -= st.top().first;
        }

        for (int j = 1; j<v2.size(); j++) v2[j].first += v2[j-1].first;

        v2.pb({MN+1,h[i]});

        for (int j = 0; j<v2.size()-1; j++) {
            ll temp = v2[j].second-v2[j+1].second;

            res += (calcZbir(v2[j].first+1))*(temp*v2[j+1].second%MN+calcZbir(temp+1));
            res %= MN;
        }

        x += w[i];
        st.push({x,h[i]});
    }

    cout<<res<<endl;

    return 0;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:46:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for (int j = 1; j<v2.size(); j++) v2[j].first += v2[j-1].first;
      |                         ~^~~~~~~~~~
fancyfence.cpp:50:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for (int j = 0; j<v2.size()-1; j++) {
      |                         ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 12 ms 1620 KB Output is correct
4 Correct 23 ms 2956 KB Output is correct
5 Correct 25 ms 3012 KB Output is correct
6 Correct 43 ms 2988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 16 ms 2072 KB Output is correct
4 Correct 28 ms 3756 KB Output is correct
5 Correct 41 ms 3832 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 15 ms 1984 KB Output is correct
5 Correct 35 ms 3716 KB Output is correct
6 Correct 29 ms 3860 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 1236 KB Output is correct
9 Correct 14 ms 3088 KB Output is correct
10 Correct 34 ms 7488 KB Output is correct
11 Correct 37 ms 7532 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 12 ms 1620 KB Output is correct
12 Correct 22 ms 3056 KB Output is correct
13 Correct 22 ms 2920 KB Output is correct
14 Correct 23 ms 3004 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 580 KB Output is correct
17 Correct 16 ms 1992 KB Output is correct
18 Correct 26 ms 3740 KB Output is correct
19 Correct 30 ms 3916 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 1260 KB Output is correct
22 Correct 14 ms 3024 KB Output is correct
23 Correct 26 ms 7424 KB Output is correct
24 Correct 28 ms 7536 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 13 ms 1876 KB Output is correct
33 Correct 14 ms 2016 KB Output is correct
34 Correct 30 ms 3544 KB Output is correct
35 Correct 26 ms 3532 KB Output is correct
36 Correct 28 ms 3696 KB Output is correct
37 Correct 29 ms 3740 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 28 ms 3820 KB Output is correct
40 Correct 25 ms 3832 KB Output is correct
41 Correct 26 ms 4424 KB Output is correct
42 Correct 30 ms 5724 KB Output is correct