algo

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub kuhaku-space/algo

:heavy_check_mark: test/yosupo/data_structure/static_range_inversions.test.cpp

Depends on

Code

// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/static_range_inversions_query
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>
#include "algorithm/compress.hpp"
#include "algorithm/mo.hpp"
#include "binary_tree/fenwick_tree.hpp"

int main(void) {
    int n, q;
    std::cin >> n >> q;
    std::vector<int> a(n);
    for (auto &e : a) std::cin >> e;
    a = compress(a);
    std::int64_t sum = 0;
    int size = *max_element(a.begin(), a.end()) + 1;
    fenwick_tree<int> ft(size);
    auto fl = [&](int idx) {
        sum += ft.sum(a[idx]);
        ft.add(a[idx], 1);
    };
    auto fr = [&](int idx) {
        sum += ft.sum(a[idx] + 1, size);
        ft.add(a[idx], 1);
    };
    auto gl = [&](int idx) {
        sum -= ft.sum(a[idx]);
        ft.add(a[idx], -1);
    };
    auto gr = [&](int idx) {
        sum -= ft.sum(a[idx] + 1, size);
        ft.add(a[idx], -1);
    };
    std::vector<std::int64_t> ans(q);
    auto rem = [&](int idx) { return ans[idx] = sum; };
    Mo mo(n);
    mo.input(q, 0);
    mo.solve(fl, fr, gl, gr, rem);
    for (auto x : ans) std::cout << x << '\n';

    return 0;
}
Traceback (most recent call last):
  File "/home/runner/.local/lib/python3.12/site-packages/competitive_verifier/oj/resolver.py", line 291, in resolve
    bundled_code = language.bundle(path, basedir=basedir)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.local/lib/python3.12/site-packages/competitive_verifier/oj/verify/languages/cplusplus.py", line 242, in bundle
    bundler.update(path)
  File "/home/runner/.local/lib/python3.12/site-packages/competitive_verifier/oj/verify/languages/cplusplus_bundle.py", line 479, in update
    self._resolve(pathlib.Path(included), included_from=path)
  File "/home/runner/.local/lib/python3.12/site-packages/competitive_verifier/oj/verify/languages/cplusplus_bundle.py", line 286, in _resolve
    raise BundleErrorAt(path, -1, "no such header")
competitive_verifier.oj.verify.languages.cplusplus_bundle.BundleErrorAt: algorithm/compress.hpp: line -1: no such header

Test cases

Env Name Status Elapsed Memory
g++ example_00 :heavy_check_mark: AC 3 ms 3 MB
g++ max_00 :heavy_check_mark: AC 832 ms 6 MB
g++ max_01 :heavy_check_mark: AC 830 ms 6 MB
g++ max_02 :heavy_check_mark: AC 830 ms 6 MB
g++ random_00 :heavy_check_mark: AC 141 ms 5 MB
g++ random_01 :heavy_check_mark: AC 242 ms 4 MB
g++ random_02 :heavy_check_mark: AC 316 ms 5 MB
g++ small_a_00 :heavy_check_mark: AC 474 ms 6 MB
g++ small_n_00 :heavy_check_mark: AC 8 ms 4 MB
g++ small_n_01 :heavy_check_mark: AC 25 ms 5 MB
g++ small_n_02 :heavy_check_mark: AC 20 ms 4 MB
g++ small_n_03 :heavy_check_mark: AC 14 ms 4 MB
g++ small_n_04 :heavy_check_mark: AC 7 ms 4 MB
Back to top page