QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395190 | #8218. 水镜 | thangthang | 0 | 0ms | 3736kb | C++20 | 1.7kb | 2024-04-21 10:23:07 | 2024-04-21 10:23:08 |
answer
// author : HuuHung
// 25.3.2024
#include <bits/stdc++.h>
#define ii pair <int, int>
#define F first
#define S second
#define ll long long
#define lb long double
#define pb push_back
#define vi vector <int>
#define vll vector <ll>
#define Bit(x, i) ((x) >> (i) & 1)
#define Mask(i) (1ll << (i))
#define All(v) (v).begin(), (v).end()
using namespace std;
void maxzi(auto &a, auto b){
a = max(a, b);
}
void minzi(auto &a, auto b){
a = min(a, b);
}
const int N = 5e5 + 5;
const int mod = 1e9 + 7;
const int LG = 20;
void add(auto &a, auto b){
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
}
auto Pow(auto a, auto b){
if (b == 0) return 1;
if (b % 2) return 1ll * a * Pow(a, b - 1) % mod;
auto c = Pow(a, b / 2);
return 1ll * c * c % mod;
}
// * end
const ll inf = 1e18;
ll h[N];
void solve(){
int n; cin >> n ;
for (int i = 1; i <= n; ++ i) cin >> h[i];
int ans = 0;
for (int i = 1; i <= n; ++ i){
int ed = n;
ll L = 0;
ll R = inf;
for (int j = i + 1; j <= n; ++ j){
if (h[j] >= h[j - 1] && h[j] >= h[j + 1]){
maxzi(L, h[j] + min(h[j - 1], h[j + 1]) + 1);
}
if (h[j] <= h[j - 1] && h[j] <= h[j + 1]){
minzi(R, h[j] + max(h[j - 1], h[j + 1]) - 1);
}
if (L > R){
ed = j;
break;
}
}
ans += ed - i ;
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t --) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 0ms
memory: 3544kb
input:
2 2 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
10 2 2 2 2 1 4 5 3 3 2
output:
20
result:
ok 1 number(s): "20"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
10 2 2 1 2 2 2 1 4 1 4
output:
17
result:
ok 1 number(s): "17"
Test #4:
score: -7
Wrong Answer
time: 0ms
memory: 3668kb
input:
10 1 5 2 2 5 4 4 4 1 3
output:
18
result:
wrong answer 1st numbers differ - expected: '20', found: '18'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%