QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#113571 | #5374. 数圈 | Scintilla | 10 | 39ms | 4572kb | C++14 | 1.8kb | 2023-06-18 17:19:02 | 2023-06-18 17:19:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl
using i64 = long long;
const int N = 1e5 + 10;
int read() {
int x = 0, f = 1; char c = getchar();
for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
return x * f;
}
namespace bit {
int c[N], lim;
void reset(int n) { lim = n, fill(c + 1, c + n + 1, 0); }
void add(int u, int k) { for (; u <= lim; u += u & -u) c[u] += k; }
int ask(int u) { int res = 0; for (; u; u -= u & -u) res += c[u]; return res; }
}
using bit::reset;
using bit::add;
using bit::ask;
int n, a[N], s, id[N], x[N], y[N], val[N], cnt;
i64 ans;
i64 solve() {
n = read();
rep(i, 1, n) a[i] = a[i - 1] + read(), id[i] = i;
s = a[n];
if (s <= 0) {
return *min_element(a + 1, a + n + 1) >= 0 ? 0 : -1;
}
ans = 0;
sort(id + 1, id + n + 1, [&](int i, int j) {
return a[i] == a[j] ? i > j : a[i] < a[j];
});
reset(n), cnt = 0;
rep(i, 1, n) {
ans -= ask(id[i]), add(id[i], 1);
x[i] = (a[i] % s + s) % s, y[i] = (a[i] - x[i]) / s;
val[++ cnt] = x[i];
}
rep(i, 1, n) {
ans += 1ll * ((i - 1) - (n - i)) * y[id[i]];
}
sort(val + 1, val + cnt + 1);
cnt = unique(val + 1, val + cnt + 1) - val - 1;
reset(cnt);
rep(i, 1, n) {
x[i] = lower_bound(val + 1, val + cnt + 1, x[i]) - val;
ans += ask(x[i] - 1), add(x[i], 1);
}
return ans;
}
int main() {
for (int tc = read(); tc; -- tc) {
printf("%lld\n", solve());
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3628kb
input:
10 3 2 -9 -4 3 4 6 0 3 3 -10 0 3 7 -6 3 3 -6 7 10 3 -3 9 -2 3 6 1 -2 3 5 2 -2 3 -9 -5 7 3 -4 -5 6
output:
-1 0 -1 1 1 3 0 0 -1 -1
result:
wrong answer 4th lines differ - expected: '3', found: '1'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 10
Accepted
Test #4:
score: 10
Accepted
time: 39ms
memory: 4572kb
input:
10 30000 -3879 -556 4570 1863 2815 -4010 2471 -270 2835 3071 -3331 -1251 -2243 4221 -5249 -4134 3376 1978 858 2545 -4207 386 3875 2029 1706 1119 3065 -3097 4399 4385 -3021 2473 2506 2157 3946 -886 3929 1478 2728 -4239 4091 -151 -4762 -2136 -1424 2162 -669 267 190 -1180 2640 -757 -2078 -1409 3165 216...
output:
121860198793245 46938573692959 57703965834328 59944493006183 81807878531011 49309954483988 78546660217267 113040545520897 33896072757379 62212580026212
result:
ok 10 lines
Subtask #5:
score: 0
Wrong Answer
Dependency #4:
100%
Accepted
Test #5:
score: 0
Wrong Answer
time: 34ms
memory: 4288kb
input:
10 30000 -2595 -3716 4165 858 -5266 -3829 811 -2088 3328 3550 4682 -4106 1810 -1775 -470 189 2599 -4024 2125 1382 2756 3173 1951 975 3411 389 4564 3431 -4952 4333 -2522 2676 2205 -105 -3087 -1781 4430 2299 4505 1113 -826 312 1429 52 -985 2395 2056 -2832 1613 -3243 3271 2772 -2816 -3652 4580 1365 123...
output:
-1 66307718106454 20087857269995 17527605573680 14265304644402 24031061433648 6589862448604 11905530271378 8996204105304 6585175833244
result:
wrong answer 3rd lines differ - expected: '20087854603233', found: '20087857269995'
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%