QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#395205 | #8218. 水镜 | thangthang | 0 | 0ms | 3628kb | C++20 | 2.0kb | 2024-04-21 10:38:06 | 2024-04-21 10:38:07 |
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];
ll ans = 0;
multiset <ll> mn, mx;
mn.insert(0);
mx.insert(inf);
int ed = 1;
for (int i = 1; i <= n; ++ i){
if (i > 1 && i < n){
if (h[i] >= h[i - 1] && h[i] >= h[i + 1]){
mn.erase(mn.lower_bound(h[i] + min(h[i - 1], h[i + 1])));
}
if (h[i] <= h[i - 1] && h[i] <= h[i + 1]){
mx.erase(mx.lower_bound(h[i] + max(h[i - 1], h[i + 1])));
}
}
if (ed == i && i != n) ++ ed;
while (ed < n){
if (h[ed] >= h[ed - 1] && h[ed] >= h[ed + 1]){
mn.insert(h[ed] + min(h[ed - 1], h[ed + 1]));
}
if (h[ed] <= h[ed - 1] && h[ed] <= h[ed + 1]){
mx.insert(h[ed] + max(h[ed - 1], h[ed + 1]));
}
if (*mx.begin() < *mn.rbegin()) break;
++ ed;
}
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: 0ms
memory: 3628kb
input:
2 2 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: -7
Wrong Answer
time: 0ms
memory: 3468kb
input:
10 2 2 2 2 1 4 5 3 3 2
output:
33
result:
wrong answer 1st numbers differ - expected: '20', found: '33'
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%