QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#105084#5374. 数圈HgCl210 201ms5816kbC++143.2kb2023-05-12 22:42:132023-05-12 22:42:16

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-12 22:42:16]
  • 评测
  • 测评结果:10
  • 用时:201ms
  • 内存:5816kb
  • [2023-05-12 22:42:13]
  • 提交

answer

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/container_base_dispatch.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <fstream>
#include <functional>
#include <iostream>
#include <string>

namespace __gnu_pbds {
struct null_type;
struct rb_tree_tag;
}  // namespace __gnu_pbds

namespace {
using std::cin;
using std::cout;
using std::int64_t;
using std::size_t;
using Tree = __gnu_pbds::tree<int64_t, __gnu_pbds::null_type, std::less<>,
                              __gnu_pbds::rb_tree_tag,
                              __gnu_pbds::tree_order_statistics_node_update>;

namespace base {
template <typename T, size_t... sizes>
struct NestedArray {};

template <typename T, size_t size, size_t... sizes>
struct NestedArray<T, size, sizes...> {
  using Type = std::array<typename NestedArray<T, sizes...>::Type, size>;
};

template <typename T>
struct NestedArray<T> {
  using Type = T;
};

template <typename T, size_t... sizes>
using Array = typename NestedArray<T, sizes...>::Type;

void OptimizeIO() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
}

void OptimizeIO(const std::string &input_file, const std::string &output_file) {
  static std::ifstream input_stream(input_file);
  static std::ofstream output_stream(output_file);
  cin.rdbuf(input_stream.rdbuf());
  cout.rdbuf(output_stream.rdbuf());
  cin.tie(nullptr), cout.tie(nullptr);
}
}  // namespace base

using base::Array;

const int kMaxN = 1.0e5 + 5;
const int64_t kBase = 1 << 20;
int n, m;
Array<int, kMaxN> a, sum_a;
Tree tree;

struct Node {
  int val, num;
};

Array<Node, kMaxN> b;

int Divide(int x, int y) { return x >= 0 ? x / y : (x - y + 1) / y; }

void Solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sum_a[0] = 0;
  for (int i = 1; i <= n; i++) sum_a[i] = sum_a[i - 1] + a[i];
  int s = sum_a[n];

  if (s < 0) {
    cout << "-1\n";
    return;
  }

  if (s == 0) {
    if (std::count(a.begin() + 1, a.begin() + n + 1, 0) == n) {
      cout << "0\n";
    } else {
      cout << "-1\n";
    }

    return;
  }

  int64_t ans = 0;

  for (int i = 0; i < n; i++) {
    ans += tree.size() - tree.order_of_key((sum_a[i] + 1) * kBase);
    tree.insert(sum_a[i] * kBase + i);
  }

  tree.clear();
  std::sort(sum_a.begin(), sum_a.begin() + n);
  m = 0;

  for (int i = 0; i < n;) {
    int j = i;
    while (j < n && sum_a[i] == sum_a[j]) j++;
    b[++m] = {sum_a[i], j - i};
    i = j;
  }

  int64_t sum_q = 0;
  int num = 0;

  for (int i = 1; i <= m; i++) {
    int q = Divide(b[i].val, s);
    int r = b[i].val - q * s;
    ans += static_cast<int64_t>(num) * q - sum_q;
    ans -= static_cast<int64_t>(b[i].num) *
           (tree.size() - tree.order_of_key((r + 1) * kBase));
    r++;
    if (r == s) r = 0, q++;
    sum_q += static_cast<int64_t>(b[i].num) * q;
    for (int j = 0; j < b[i].num; j++) tree.insert(r * kBase + (++num));
  }

  tree.clear();
  cout << ans << "\n";
}

int Main() {
  base::OptimizeIO();
  int t;
  cin >> t;
  while (t--) Solve();
  return 0;
}
}  // namespace

int main() { return Main(); }

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 3484kb

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
3
1
4
2
1
-1
-1

result:

ok 10 lines

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #2:

score: 0
Wrong Answer
time: 2ms
memory: 3432kb

input:

10
50
-5 -5 3 8 0 0 3 8 5 -7 6 -9 5 5 2 7 -9 1 -7 5 0 10 -6 -2 -6 -8 9 7 4 3 -9 9 5 9 8 1 7 0 0 -5 -1 -3 5 -7 5 -4 6 8 -1 1
50
-6 4 3 -6 -9 -8 -5 -2 -10 7 -4 1 -1 -5 2 1 -10 8 8 7 -8 -5 3 -6 10 3 2 -1 10 0 4 -6 9 3 -6 3 9 -4 4 -2 -3 4 -9 -7 7 1 5 2 -4 5
50
2 -10 5 3 -1 1 9 -1 -5 3 -2 -10 7 0 5 -5 -1...

output:

107
-1
129
-1
13057
-1
335
-1
-1
263

result:

wrong answer 1st lines differ - expected: '161', found: '107'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 201ms
memory: 5816kb

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:

119787583088489
44816647566595
56265864130031
58360024327100
79768789113989
47401446804715
76567450454816
110835105866874
32188054460542
59892613535270

result:

wrong answer 1st lines differ - expected: '121860198793245', found: '119787583088489'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%