QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#395189 | #8218. 水镜 | thangthang | 0 | 1ms | 3648kb | C++20 | 1.8kb | 2024-04-21 10:21:35 | 2024-04-21 10:21:35 |
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]){
ed = j - 1;
break;
}
if (j == n) break;
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;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 1ms
memory: 3648kb
input:
2 2 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: -7
Wrong Answer
time: 1ms
memory: 3584kb
input:
10 2 2 2 2 1 4 5 3 3 2
output:
10
result:
wrong answer 1st numbers differ - expected: '20', found: '10'
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%