QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#559171 | #8218. 水镜 | Lu_xZ | 0 | 1ms | 9780kb | C++20 | 1.5kb | 2024-09-11 20:38:18 | 2024-09-11 20:38:21 |
answer
#include<bits/stdc++.h>
#define eb emplace_back
#define ep emplace
using namespace std;
using ll = long long;
constexpr int N = 1e6 + 5;
int n, m; ll h[N], b[N], x[N], ans;
struct Node {
int mi, tag;
void addtag(int v) {mi = tag = v;}
} t[N << 2];
#define ls x << 1
#define rs ls | 1
void pushup(int x) {
t[x].mi = min(t[ls].mi, t[rs].mi);
}
void pushdown(int x) {
if(t[x].tag) {
t[ls].addtag(t[x].tag), t[rs].addtag(t[x].tag);
t[x].tag = 0;
}
}
void assign(int L, int R, int v, int x = 1, int l = 1, int r = m) {
if(L > R) return;
if(L <= l && r <= R) return t[x].addtag(v);
pushdown(x);
int mid = l + r >> 1;
if(L <= mid) assign(L, R, v, ls, l, mid);
if(R > mid) assign(L, R, v, rs, mid + 1, r);
pushup(x);
}
int F(ll val) {
return lower_bound(b + 1, b + m + 1, val) - b;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i = 1; i <= n; ++ i) {
cin >> h[i], h[i] <<= 2;
}
for(int i = 1; i < n; ++ i) {
b[++ m] = x[i] = (h[i] + h[i + 1]) / 2;
b[++ m] = x[i] + 1;
}
sort(b + 1, b + m + 1);
m = unique(b + 1, b + m + 1) - b - 1;
ans = n * ll(n - 1) / 2;
for(int i = 2; i < n; ++ i) {
int l, r, L, R;
if(h[i] == h[i - 1]) l = 1, r = m;
else {
if(h[i] < h[i - 1]) l = F(x[i - 1]), r = m;
else l = 1, r = F(x[i - 1]);
}
if(h[i] == h[i + 1]) L = 1, R = m;
else {
if(h[i] < h[i + 1]) L = F(x[i]), R = m;
else L = 1, R = F(x[i]);
}
assign(max(l, L), min(r, R), i - 1);
ans -= t[1].mi;
}
cout << ans;
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 1ms
memory: 9696kb
input:
2 2 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 7
Accepted
time: 1ms
memory: 9772kb
input:
10 2 2 2 2 1 4 5 3 3 2
output:
20
result:
ok 1 number(s): "20"
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 9780kb
input:
10 2 2 1 2 2 2 1 4 1 4
output:
16
result:
wrong answer 1st numbers differ - expected: '17', found: '16'
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%