답안 #868583

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868583 2023-10-31T22:26:39 Z mariaclara Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
24 ms 6836 KB
#pragma GCC optimize "Ofast"
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef tuple<ll,ll,ll> trio;
typedef pair<int,int> pii;
const int MAXN = 1e5+10;
const ll MOD = 1e9+7;
#define all(x) x.begin(), x.end()
#define mk make_pair
#define pb push_back
#define f first
#define s second

ll n, resp, h[MAXN], w[MAXN], ant[MAXN], pos[MAXN], pw[MAXN];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n;

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

    for(int i = 1; i <= n; i++)
        cin >> w[i], pw[i] = pw[i-1] + w[i];

    stack<int> val;
    val.push(0);
    for(int i = 1; i <= n; i++) {
        while(h[val.top()] > h[i]) val.pop();
        ant[i] = val.top();
        val.push(i);
    }
    while(!val.empty()) val.pop();
    val.push(n+1);

    for(int i = n; i >= 1; i--) {
        while(h[val.top()] >= h[i]) val.pop();
        pos[i] = val.top();
        val.push(i);
    }

    for(int i = 1; i <= n; i++) {
        ll l = ant[i]+1, r = pos[i]-1;
        ll tot = (((pw[r]-pw[l-1]+1)%MOD) * ((pw[r]-pw[l-1])%MOD))/2;
        ll casoA = (((pw[r]-pw[i]+1)%MOD) * ((pw[r]-pw[i])%MOD))/2;
        ll casoB = (((pw[i-1]-pw[l-1]+1)%MOD) * ((pw[i-1]-pw[l-1])%MOD))/2;
        resp +=  ((tot%MOD - casoA%MOD - casoB%MOD)%MOD) * ((h[i] * (h[i]+1) / 2)%MOD);
        resp %= MOD;
    }

    cout << (resp + MOD) % MOD;
}
// g++ -std=c++17 clara.cpp -o clara
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2440 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 7 ms 3452 KB Output is correct
4 Correct 15 ms 4652 KB Output is correct
5 Correct 19 ms 5468 KB Output is correct
6 Correct 15 ms 5464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 10 ms 3676 KB Output is correct
4 Correct 18 ms 6488 KB Output is correct
5 Correct 19 ms 6748 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 2 ms 2904 KB Output is correct
4 Correct 10 ms 3676 KB Output is correct
5 Correct 18 ms 6576 KB Output is correct
6 Correct 24 ms 6740 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 3 ms 2904 KB Output is correct
9 Correct 9 ms 4444 KB Output is correct
10 Correct 18 ms 6392 KB Output is correct
11 Correct 18 ms 6836 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2592 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2548 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 8 ms 3508 KB Output is correct
12 Correct 14 ms 4520 KB Output is correct
13 Correct 16 ms 5728 KB Output is correct
14 Correct 16 ms 5464 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 2 ms 2908 KB Output is correct
17 Correct 10 ms 4440 KB Output is correct
18 Correct 18 ms 6516 KB Output is correct
19 Correct 18 ms 6748 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 2908 KB Output is correct
22 Correct 10 ms 4444 KB Output is correct
23 Correct 23 ms 6488 KB Output is correct
24 Correct 24 ms 6484 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 3 ms 2908 KB Output is correct
31 Correct 2 ms 2908 KB Output is correct
32 Correct 10 ms 4360 KB Output is correct
33 Correct 10 ms 4444 KB Output is correct
34 Correct 19 ms 5980 KB Output is correct
35 Correct 19 ms 5968 KB Output is correct
36 Correct 21 ms 6256 KB Output is correct
37 Correct 20 ms 6232 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 21 ms 6260 KB Output is correct
40 Correct 18 ms 6236 KB Output is correct
41 Correct 21 ms 6236 KB Output is correct
42 Correct 18 ms 6492 KB Output is correct