QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#572663 | #8218. 水镜 | guosoun | 0 | 2ms | 11804kb | C++17 | 2.1kb | 2024-09-18 15:52:16 | 2024-09-18 15:52:16 |
Judging History
answer
#include <bits/stdc++.h>
template <class T>
void chkmax(T &x, const T &y) {
if (x < y) x = y;
}
template <class T>
void chkmin(T &x, const T &y) {
if (x > y) x = y;
}
using ll = long long;
const int N = 5e5 + 10;
int n;
ll h[N];
std::pair<ll, ll> s[N];
int tg[N * 30], tr[N * 30], ls[N * 30], rs[N * 30], ntot = 1, rt = 1;
void get_down(int &i, int t) {
if (!i) i = ++ntot;
tr[i] += t, tg[i] += t;
}
void push_down(int i) {
if (tg[i]) get_down(ls[i], tg[i]), get_down(rs[i], tg[i]), tg[i] = 0;
}
void add(int &i, ll l, ll r, ll ql, ll qr, int v) {
if (ql > qr) return;
if (!i) i = ++ntot;
if (ql <= l && r <= qr) return get_down(i, v);
ll mid = (l + r) >> 1;
push_down(i);
if (ql <= mid) add(ls[i], l, mid, ql, qr, v);
if (qr > mid) add(rs[i], mid + 1, r, ql, qr, v);
tr[i] = std::min(tr[ls[i]], tr[rs[i]]);
}
bool check(int l, int r) {
if (l + 1 == r) return 1;
bool res = 0;
for (int i = l + 1; i < r; i++) {
auto [ql, qr] = s[i];
if (ql <= qr) add(rt, -1e12, 1e12, ql, qr, 1);
}
res |= tr[rt] == 0;
for (int i = l + 1; i < r; i++) {
auto [ql, qr] = s[i];
if (ql <= qr) add(rt, -1e12, 1e12, ql, qr, -1);
}
return res;
}
int main() {
std::cin.tie(0)->sync_with_stdio(0);
std::cin >> n;
for (int i = 1; i <= n; i++) std::cin >> h[i], h[i] *= 2;
for (int i = 2; i < n; i++) {
ll v1 = (h[i - 1] + h[i]) / 2;
s[i] = {-1e12, 1e12};
if (h[i] < h[i - 1]) chkmax(s[i].first, v1);
if (h[i] > h[i - 1]) chkmin(s[i].second, v1 - 1);
ll v2 = (h[i] + h[i + 1]) / 2;
if (h[i] < h[i + 1]) chkmax(s[i].first, v2);
if (h[i] > h[i + 1]) chkmin(s[i].second, v2 - 1);
}
ll ans = n - 1;
for (int i = 2, j = 1; i < n; ) {
if (j < i - 1) j = i - 1;
for (;;) {
if (j == n - 1) break;
j++;
add(rt, -1e12, 1e12, s[j].first, s[j].second, 1);
if (tr[rt]) {
add(rt, -1e12, 1e12, s[j].first, s[j].second, -1);
j--;
break;
}
}
ans += j - i + 1;
if (j >= i) add(rt, -1e12, 1e12, s[i].first, s[i].second, -1);
i++;
}
std::cout << ans << '\n';
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 1ms
memory: 5652kb
input:
2 2 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 7
Accepted
time: 2ms
memory: 11804kb
input:
10 2 2 2 2 1 4 5 3 3 2
output:
20
result:
ok 1 number(s): "20"
Test #3:
score: 7
Accepted
time: 0ms
memory: 9840kb
input:
10 2 2 1 2 2 2 1 4 1 4
output:
17
result:
ok 1 number(s): "17"
Test #4:
score: 7
Accepted
time: 0ms
memory: 9888kb
input:
10 1 5 2 2 5 4 4 4 1 3
output:
20
result:
ok 1 number(s): "20"
Test #5:
score: 7
Accepted
time: 1ms
memory: 9824kb
input:
10 904418845477 67070474418 839309493679 528132965435 512894488193 602880026087 180594485896 804608714469 235337679831 584564033737
output:
33
result:
ok 1 number(s): "33"
Test #6:
score: 0
Wrong Answer
time: 1ms
memory: 7800kb
input:
10 2550179579 103777915839 144714526810 113623620429 670640709602 630479108288 925117980861 409440663027 851501568790 70823805701
output:
21
result:
wrong answer 1st numbers differ - expected: '24', found: '21'
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%