QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#138690 | #6627. Line Town | Cyanmond | 0 | 1ms | 3488kb | C++17 | 1.7kb | 2023-08-12 08:13:26 | 2023-08-12 08:13:28 |
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, l, r) for (int i = (r - 1); i >= (l); --i)
#define ALL(x) (x).begin(), (x).end()
class SegTree {
int n, internalSize;
vector<int> data;
public:
SegTree(int n_) : n(n_) {
internalSize = 1;
while (internalSize < n) internalSize *= 2;
data.assign(2 * internalSize, 0);
}
void set(int i, int v) {
i += internalSize;
data[i] = v;
while (i != 1) {
i /= 2;
data[i] = data[2 * i] + data[2 * i + 1];
}
}
int fold(int l, int r) {
int ret = 0;
for (l += internalSize, r += internalSize; l < r; l /= 2, r /= 2) {
if (l & 1) ret += data[l++];
if (r & 1) ret += data[--r];
}
return ret;
}
};
int main() {
int N;
cin >> N;
vector<i64> H(N);
for (auto &e : H) cin >> e;
priority_queue<pair<int, int>> pq;
rep (i, 0, N) pq.push({abs(H[i]), i});
SegTree seg(N);
rep (i, 0, N) seg.set(i, 1);
i64 ans = 0;
while (not pq.empty()) {
const auto [val, i] = pq.top();
pq.pop();
seg.set(i, 0);
const auto a = seg.fold(0, i), b = seg.fold(i + 1, N);
int v = 1 << 30;
if (H[i] >= 0 and a % 2 == 1) v = min(v, a);
if (H[i] <= 0 and a % 2 == 0) v = min(v, a);
if (H[i] >= 0 and b % 2 == 0) v = min(v, b);
if (H[i] <= 0 and b % 2 == 1) v = min(v, b);
cerr << v << endl;
if (v == (1 << 30)) {
ans = -1;
break;
}
ans += v;
}
cout << ans << endl;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 1ms
memory: 3488kb
input:
10 1 1 1 1 1 -1 -1 -1 1 -1
output:
-1
result:
ok 1 number(s): "-1"
Test #2:
score: -3
Wrong Answer
time: 1ms
memory: 3432kb
input:
10 1 1 1 1 1 1 -1 1 1 -1
output:
-1
result:
wrong answer 1st numbers differ - expected: '3', found: '-1'
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
Wrong Answer
Test #60:
score: 4
Accepted
time: 1ms
memory: 3436kb
input:
10 3 10 5 -9 7 2 -6 1 8 0
output:
-1
result:
ok 1 number(s): "-1"
Test #61:
score: -4
Wrong Answer
time: 1ms
memory: 3476kb
input:
10 -9 0 -1 7 5 10 6 3 2 -8
output:
-1
result:
wrong answer 1st numbers differ - expected: '13', found: '-1'
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%