Submission #856063

# Submission time Handle Problem Language Result Execution time Memory
856063 2023-10-02T16:11:49 Z sofijavelkovska Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
59 ms 7796 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5, MOD=1e9+7;

long long h[MAXN], w[MAXN];

bool compare(int x, int y)
{
    //if (h[x]==h[y])
      //  return x<y;

    return h[x]<h[y];
}

long long outer(int i, long long leftsum, long long rightsum)
{
    long long rectangles=0;
    rectangles=(rectangles+h[i]*w[i]%MOD*leftsum%MOD)%MOD;
    rectangles=(rectangles+h[i]*(h[i]-1)/2%MOD*w[i]%MOD*leftsum%MOD)%MOD;
    rectangles=(rectangles+h[i]*w[i]%MOD*rightsum%MOD)%MOD;
    rectangles=(rectangles+h[i]*(h[i]-1)/2%MOD*w[i]%MOD*rightsum%MOD)%MOD;
    rectangles=(rectangles+h[i]*leftsum%MOD*rightsum%MOD)%MOD;
    rectangles=(rectangles+h[i]*(h[i]-1)/2%MOD*leftsum%MOD*rightsum%MOD)%MOD;

    return rectangles;
}

long long inner(int i)
{
    long long rectangles=0;
    rectangles=(rectangles+h[i]*w[i]%MOD)%MOD;
    rectangles=(rectangles+w[i]*(w[i]-1)/2%MOD*h[i]%MOD)%MOD;
    rectangles=(rectangles+h[i]*(h[i]-1)/2%MOD*w[i]%MOD)%MOD;
    rectangles=(rectangles+h[i]*(h[i]-1)/2%MOD*(w[i]*(w[i]-1)/2%MOD)%MOD)%MOD;

    return rectangles;
}

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

    int n, x, left, right, i;
    long long leftsum, rightsum, total=0;
    set<int> processed;
    cin >> n;
    int index[n];
    long long prefixsum[n];
    for (i=0; i<n; i++)
        cin >> h[i];
    for (i=0; i<n; i++)
        cin >> w[i];
    for (i=0; i<n; i++)
        index[i]=i;
    sort(index, index+n, compare);
    prefixsum[0]=w[0];
    for (i=1; i<n; i++)
        prefixsum[i]=prefixsum[i-1]+w[i];
    processed.insert(-1);
    processed.insert(n);
    for (i=0; i<n; i++)
    {
        x=index[i];
        auto it=processed.lower_bound(x);
        right=*it;
        it--;
        left=*it;
        rightsum=(prefixsum[right-1]-prefixsum[x])%MOD;
        leftsum=(prefixsum[x]-w[x]-(prefixsum[left+1]-w[left+1]))%MOD;
        total=(total+outer(x, leftsum, rightsum)+inner(x))%MOD;
        processed.insert(x);
    }
    cout << total;

    return 0;
}
# 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 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
# 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 18 ms 4012 KB Output is correct
4 Correct 36 ms 7772 KB Output is correct
5 Correct 37 ms 7688 KB Output is correct
6 Correct 36 ms 7676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 4 ms 1116 KB Output is correct
3 Correct 19 ms 4188 KB Output is correct
4 Correct 39 ms 7760 KB Output is correct
5 Correct 38 ms 7764 KB Output is correct
6 Correct 0 ms 348 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 4 ms 1116 KB Output is correct
4 Correct 18 ms 3968 KB Output is correct
5 Correct 38 ms 7636 KB Output is correct
6 Correct 38 ms 7760 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 4 ms 1116 KB Output is correct
9 Correct 20 ms 4016 KB Output is correct
10 Correct 42 ms 7680 KB Output is correct
11 Correct 45 ms 7708 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 0 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 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 360 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 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 1 ms 348 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 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 18 ms 4188 KB Output is correct
12 Correct 40 ms 7764 KB Output is correct
13 Correct 37 ms 7652 KB Output is correct
14 Correct 35 ms 7764 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1116 KB Output is correct
17 Correct 19 ms 4188 KB Output is correct
18 Correct 38 ms 7772 KB Output is correct
19 Correct 38 ms 7760 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 4 ms 1088 KB Output is correct
22 Correct 20 ms 4188 KB Output is correct
23 Correct 45 ms 7736 KB Output is correct
24 Correct 45 ms 7644 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 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 1112 KB Output is correct
31 Correct 5 ms 1208 KB Output is correct
32 Correct 25 ms 4188 KB Output is correct
33 Correct 28 ms 4184 KB Output is correct
34 Correct 58 ms 7764 KB Output is correct
35 Correct 51 ms 7764 KB Output is correct
36 Correct 59 ms 7760 KB Output is correct
37 Correct 59 ms 7784 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 56 ms 7796 KB Output is correct
40 Correct 53 ms 7764 KB Output is correct
41 Correct 50 ms 7732 KB Output is correct
42 Correct 44 ms 7764 KB Output is correct