QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#133530#4936. Shopping ChangesRd_rainydays#Compile Error//Python21.9kb2023-08-02 10:45:422023-08-02 10:45:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 10:45:43]
  • 评测
  • [2023-08-02 10:45:42]
  • 提交

answer

#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
const int N = 8e5 + 5;
int n, m, C[N], L[N];
std::vector<int> W[N];

struct fwt {
  #define lb(x) (x & -x)
  std::vector<int> used;
  int tr[N];

  void add(int x, int y) {
    used.push_back(x);
    for (; x < N; x += lb(x))
      tr[x] += y;
  }
  int qry(int x = N - 1) {
    int y = 0;
    for (; x; x -= lb(x))
      y += tr[x];
    return y;
  }
  void reset() {
    for (auto x : used) {
      for (; x < N; x += lb(x)) {
        if (!tr[x]) break;
        else tr[x] = 0;
      }
    }
    used.clear();
  }
} t, ts;

signed main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", C + i);

  long long raw = 0;
  for (int i = 1; i <= n; i++) {
    raw += t.qry() - t.qry(C[i]);
    t.add(C[i], 1);
  }

  for (int i = 1; i <= m; i++) {
    scanf("%d", L + i);
    W[i].resize(L[i]);
    for (int &x : W[i]) scanf("%d", &x);
  }

  std::vector<int> dis(C + 1, C + 1 + n);
  for (int i = 1; i <= m; i++)
    dis.insert(dis.end(), all(W[i]));
  std::sort(all(dis));
  dis.erase(std::unique(all(dis)), dis.end());

  for (int i = 1; i <= n; i++)
    C[i] = std::lower_bound(all(dis), C[i]) - dis.begin() + 1;
  for (int i = 1; i <= m; i++)
    for (auto &x : W[i])
      x = std::lower_bound(all(dis), x) - dis.begin() + 1;
  fprintf(stderr, " > %lld\n", raw);

  for (int i = 1; i <= m; i++) {
    auto &w = W[i];
    int l = L[i];
    ts.reset();

    long long ans = raw, fin = 0;
    for (int j = 0; j < l; j++) {
      ans += t.qry() - t.qry(w[j]);
      ans += ts.qry() - ts.qry(w[j]);
      ts.add(w[j], 1);
    }
    fin = ans;

    for (int j = 0; j < l; j++) {
      ans -= t.qry() - t.qry(w[j]);
      ans += t.qry(w[j] - 1);
      fin = std::min(fin, ans);
      printf(" >> %lld\n", ans);
    }

    printf("%lld\n", fin);
  }

  return 0;
}

Details

  File "answer.code", line 4
    const int N = 8e5 + 5;
            ^
SyntaxError: invalid syntax