Submission #968324

# Submission time Handle Problem Language Result Execution time Memory
968324 2024-04-23T10:04:05 Z phoenix0423 Real Mountains (CCO23_day1problem2) C++17
3 / 25
8 ms 6744 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
#define lowbit(x) x&-x
const int maxn = 1e6 + 1;
const int N = 1e6 + 3;
const int INF = 1e18;
int h[maxn], l[maxn], r[maxn], cl[maxn], cr[maxn];

signed main(void){
    fastio;
    int n;
    cin>>n;
    int mn = 0;
    for(int i = 0; i < n; i++){
        cin>>h[i];
        if(h[i] < h[mn]) mn = i;
    }
    for(int i = 0; i < n; i++) r[i] = -1;
    for(int i = 0; i < n; i++){
        l[i] = r[i] = -1;
        for(int j = i - 1; j >= 0; j--){
            if(h[j] > h[i]){
                l[i] = j;
                break;
            }
        }
        for(int j = i + 1; j < n; j++){
            if(h[j] >= h[i]){
                r[i] = j;
                break;
            }
        }
    }
    int ans = 0;
    for(int i = 1; i < n; i++){
        if(r[i] == -1 || l[i] == -1) continue;
        if(h[r[i]] == h[i]) continue;
        int cnt = r[i] - l[i] - 1;
        int dif = min(h[r[i]], h[l[i]]) - h[i];
        // cout<<i<<" "<<cnt<<" "<<dif<<"\n";
        // cout<<h[l[i]]<<" "<<h[r[i]]<<"\n";
        ans += dif * (h[l[i]] + h[i] + h[r[i]]) + dif * (dif - 1) / 2;
        if(cnt >= 2)
            ans += dif * (min(h[l[i]], h[r[i]]) + h[i] * 2) + dif * (dif + 1) - dif;
        if(cnt > 2)
            ans += (cnt - 2) * (dif * h[i] * 3 + dif * (dif + 1) + dif * (dif - 1) / 2);
        // cout<<"ans : "<<ans<<"\n";
    }
    cout<<ans % N<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6500 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 6 ms 6492 KB Output is correct
5 Correct 6 ms 6492 KB Output is correct
6 Correct 5 ms 6492 KB Output is correct
7 Correct 5 ms 6488 KB Output is correct
8 Correct 7 ms 6492 KB Output is correct
9 Correct 8 ms 6636 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 7 ms 6492 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6500 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 6 ms 6492 KB Output is correct
5 Correct 6 ms 6492 KB Output is correct
6 Correct 5 ms 6492 KB Output is correct
7 Correct 5 ms 6488 KB Output is correct
8 Correct 7 ms 6492 KB Output is correct
9 Correct 8 ms 6636 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 7 ms 6492 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
13 Incorrect 2 ms 6492 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6500 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 6 ms 6492 KB Output is correct
5 Correct 6 ms 6492 KB Output is correct
6 Correct 5 ms 6492 KB Output is correct
7 Correct 5 ms 6488 KB Output is correct
8 Correct 7 ms 6492 KB Output is correct
9 Correct 8 ms 6636 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 7 ms 6492 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
13 Incorrect 2 ms 6492 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6500 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 6 ms 6492 KB Output is correct
5 Correct 6 ms 6492 KB Output is correct
6 Correct 5 ms 6492 KB Output is correct
7 Correct 5 ms 6488 KB Output is correct
8 Correct 7 ms 6492 KB Output is correct
9 Correct 8 ms 6636 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 7 ms 6492 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
13 Incorrect 2 ms 6492 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6500 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 6 ms 6492 KB Output is correct
5 Correct 6 ms 6492 KB Output is correct
6 Correct 5 ms 6492 KB Output is correct
7 Correct 5 ms 6488 KB Output is correct
8 Correct 7 ms 6492 KB Output is correct
9 Correct 8 ms 6636 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 7 ms 6492 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
13 Incorrect 2 ms 6492 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6500 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 6 ms 6492 KB Output is correct
5 Correct 6 ms 6492 KB Output is correct
6 Correct 5 ms 6492 KB Output is correct
7 Correct 5 ms 6488 KB Output is correct
8 Correct 7 ms 6492 KB Output is correct
9 Correct 8 ms 6636 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 7 ms 6492 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
13 Incorrect 2 ms 6492 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6500 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 6 ms 6492 KB Output is correct
5 Correct 6 ms 6492 KB Output is correct
6 Correct 5 ms 6492 KB Output is correct
7 Correct 5 ms 6488 KB Output is correct
8 Correct 7 ms 6492 KB Output is correct
9 Correct 8 ms 6636 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 7 ms 6492 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
13 Incorrect 2 ms 6492 KB Output isn't correct
14 Halted 0 ms 0 KB -