QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#296587 | #6626. Real Mountains | chy12321 | 0 | 7ms | 54412kb | C++14 | 2.4kb | 2024-01-03 10:46:22 | 2024-01-03 10:46:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int N = 1e6 + 3;
int n, m, h[N], fh[N], b[N];
vector<int> add[N], del[N];
set<int> s;
namespace SGT {
#define lson pos << 1
#define rson pos << 1 | 1
int mn[N << 2];
void build(int pos, int l, int r) {
if (l == r) {mn[pos] = h[l]; return;}
int mid = (l + r) >> 1;
build(lson, l, mid), build(rson, mid + 1, r);
mn[pos] = min(mn[lson], mn[rson]);
}
void upd(int pos, int l, int r, int x, int c) {
mn[pos] = c; if (l == r) return;
int mid = (l + r) >> 1;
x <= mid ? upd(lson, l, mid, x, c) : upd(rson, mid + 1, r, x, c);
mn[pos] = min(mn[lson], mn[rson]);
}
int query(int pos, int l, int r, int x, int y) {
if (x <= l && r <= y) return mn[pos];
int mid = (l + r) >> 1, res = 2e9;
if (x <= mid) res = query(lson, l, mid, x, y);
if (y > mid) res = min(res, query(rson, mid + 1, r, x, y));
return res;
}
}
inline int rk(int w) {return lower_bound(b + 1, b + m + 1, w) - b;}
inline ll sum(int l, int r) {
return 1ll * (l + r) * (r - l + 1) / 2 % N;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(nullptr), cout.tie(nullptr);
cin >> n; for (int i = 1; i <= n; i++) cin >> h[i];
int p = max_element(h + 1, h + n + 1) - h;
for (int i = 1; i <= p; i++) fh[i] = max(fh[i - 1], h[i]);
for (int i = n; i >= p; i--) fh[i] = max(fh[i + 1], h[i]);
memcpy(b, h, sizeof(b)), sort(b + 1, b + n + 1), m = unique(b + 1, b + n + 1) - b - 1;
for (int i = 1; i <= n; i++) add[rk(h[i])].emplace_back(i), del[rk(fh[i])].emplace_back(i);
SGT::build(1, 1, n); ll ans = 0;
for (int i = 1; i < m; i++) {
for (int x : add[i]) SGT::upd(1, 1, n, x, 2e9), s.insert(x);
for (int x : del[i]) s.erase(x);
if (s.empty()) continue;
int l = *s.begin(), r = *s.rbegin(), L = SGT::query(1, 1, n, 1, l - 1), R = SGT::query(1, 1, n, r + 1, n);
if (l == r) ans = (ans + sum(b[i], b[i + 1] - 1) + 1ll * (L + R) * (b[i + 1] - b[i])) % N;
else ans = (ans + 1ll * (b[i + 1] - b[i]) * (L + R + min(SGT::query(1, 1, n, 1, r - 1), SGT::query(1, 1, n, l + 1, n))) + 3 * (s.size() - 1) * sum(b[i], b[i + 1] - 1) + 2 * (s.size() - 2) * (b[i + 1] - b[i])) % N;
}
cout << ans;
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 4ms
memory: 54412kb
input:
3 29 9 9
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 3ms
memory: 54256kb
input:
3 62 20 71
output:
7287
result:
ok 1 number(s): "7287"
Test #3:
score: -3
Wrong Answer
time: 7ms
memory: 54144kb
input:
10 72 33 22 22 13 49 53 57 72 85
output:
40353
result:
wrong answer 1st numbers differ - expected: '40403', found: '40353'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #3:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%