QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#178528#1228. I 君的探险hos_lyric#76 286ms41484kbC++144.9kb2023-09-14 02:35:262023-09-14 03:59:06

Judging History

This is the latest submission verdict.

  • [2023-09-14 03:59:06]
  • 管理员手动重测该提交记录
  • Verdict: 76
  • Time: 286ms
  • Memory: 41484kb
  • [2023-09-14 02:35:27]
  • Judged
  • Verdict: 0
  • Time: 296ms
  • Memory: 41860kb
  • [2023-09-14 02:35:26]
  • Submitted

answer

#include "explore.h"

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


unsigned xrand() {
  static unsigned x = 314159265, y = 358979323, z = 846264338, w = 327950288;
  unsigned t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8;
}


int N, M;

int E;
vector<int> xs;
void getXs() {
  E = (31 - __builtin_clz(N)) + 1;
  xs.assign(N, 0);
  for (int e = 0; e < E; ++e) {
    for (int u = 0; u < N; ++u) if (u >> e & 1) {
      modify(u);
    }
    for (int u = 0; u < N; ++u) {
      xs[u] |= query(u) << e;
    }
  }
  for (int u = 0; u < N; ++u) {
    xs[u] ^= xs[u] << 1;
    xs[u] &= ~(1 << E);
  }
}


void run0() {
  vector<int> now(N, 0);
  for (int u = 0; u < N - 1; ++u) {
    modify(u);
    for (int v = u + 1; v < N; ++v) {
      const int res = query(v);
      if (now[v] ^ res) {
        report(u, v);
      }
      now[v] = res;
    }
  }
}

void runA() {
  getXs();
  for (int u = 0; u < N; ++u) {
    const int v = xs[u] ^ u;
    if (u < v) {
      report(u, v);
    }
  }
}

void runB() {
  getXs();
  for (int u = N; --u > 0; ) {
    const int p = xs[u] ^ u;
    report(p, u);
    xs[p] ^= u;
  }
}

void runC() {
  getXs();
  vector<int> now(N, 0);
  for (int u = 0; u < N; ++u) {
    now[u] = __builtin_parity(xs[u]);
  }
  modify(0);
  vector<int> us;
  for (int u = 1; u < N; ++u) {
    if (now[u] ^ query(u)) {
      us.push_back(u);
    }
  }
  assert(us.size() <= 2);
  for (const int u : us) {
    int v = 0, w = u;
    for (; ; ) {
      report(v, w);
      const int x = xs[w] ^ v ^ w;
      if (!x) {
        break;
      }
      v = w;
      w = x;
    }
  }
}

void runD() {
  getXs();
  set<pair<int, int>> used;
  auto ae = [&](int u, int v) -> void {
    if (used.insert(minmax(u, v)).second) {
      xs[u] ^= v;
      xs[v] ^= u;
      report(u, v);
    }
  };
  queue<int> que;
  for (int u = 0; u < N; ++u) {
    que.push(u);
  }
  for (; !que.empty(); ) {
    const int u = que.front();
    que.pop();
    const int v = xs[u] ^ u;
    if (0 <= v && v < N && u != v) {
      const int res0 = query(u);
      modify(v);
      const int res1 = query(u);
      if (res0 ^ res1) {
        ae(u, v);
        if (check(u)) {
          que.push(v);
        }
      }
    }
  }
}

void run4() {
  for (int u = 0; u < N; ++u) {
    modify(u);
  }
  vector<int> deg(N);
  for (int u = 0; u < N; ++u) {
    deg[u] = query(u) ^ 1;
  }
  for (int u = 0; u < N; ++u) {
    set<int> vis;
    for (; deg[u] || !check(u); ) {
      vector<int> vs;
      for (int v = u + 1; v < N; ++v) if (!vis.count(v)) {
        vs.push_back(v);
      }
      assert(vs.size() >= 1);
      int last = query(u);
      for (; ; ) {
        const int vsLen = vs.size();
        if (vsLen == 1) {
          break;
        }
        for (int j = 0; j < vsLen; ++j) {
          swap(vs[xrand() % (j + 1)], vs[j]);
        }
        const int half = vsLen / 2;
        for (int j = 0; j < half; ++j) {
          modify(vs[j]);
        }
        const int res = query(u);
        if (last ^ res) {
          vs.resize(half);
        } else if (deg[u]) {
          vs.erase(vs.begin(), vs.begin() + half);
        } else {
          // retry
        }
        last = res;
      }
      {
        const int v = vs[0];
        deg[u] ^= 1;
        deg[v] ^= 1;
        vis.insert(v);
        report(u, v);
      }
    }
  }
}

void explore(int N_, int M_) {
  N = N_;
  M = M_;
  switch (N % 10) {
    case 8: runA(); break;
    case 7: runB(); break;
    case 6: runC(); break;
    case 5: runD(); break;
    case 4: run4(); break;
    default: {
      if (N <= 500) {
        run0();
      } else {
        run4();
      }
    }
  }
}

詳細信息

Test #1:

score: 4
Accepted
time: 2ms
memory: 16004kb

Test #2:

score: 4
Accepted
time: 1ms
memory: 18060kb

Test #3:

score: 4
Accepted
time: 2ms
memory: 18112kb

Test #4:

score: 4
Accepted
time: 0ms
memory: 24176kb

Test #5:

score: 4
Accepted
time: 7ms
memory: 16108kb

Test #6:

score: 4
Accepted
time: 7ms
memory: 16980kb

Test #7:

score: 4
Accepted
time: 20ms
memory: 22908kb

Test #8:

score: 4
Accepted
time: 52ms
memory: 30072kb

Test #9:

score: 4
Accepted
time: 61ms
memory: 23532kb

Test #10:

score: 4
Accepted
time: 34ms
memory: 24928kb

Test #11:

score: 4
Accepted
time: 67ms
memory: 30844kb

Test #12:

score: 4
Accepted
time: 21ms
memory: 31476kb

Test #13:

score: 4
Accepted
time: 82ms
memory: 29080kb

Test #14:

score: 4
Accepted
time: 91ms
memory: 25096kb

Test #15:

score: 4
Accepted
time: 66ms
memory: 23052kb

Test #16:

score: 0
Wrong Answer
time: 72ms
memory: 28376kb

Test #17:

score: 4
Accepted
time: 183ms
memory: 41484kb

Test #18:

score: 4
Accepted
time: 22ms
memory: 18096kb

Test #19:

score: 4
Accepted
time: 44ms
memory: 22152kb

Test #20:

score: 4
Accepted
time: 47ms
memory: 16100kb

Test #21:

score: 0
Wrong Answer
time: 137ms
memory: 18412kb

Test #22:

score: 0
Wrong Answer
time: 253ms
memory: 22424kb

Test #23:

score: 0
Wrong Answer
time: 219ms
memory: 28536kb

Test #24:

score: 0
Wrong Answer
time: 237ms
memory: 34748kb

Test #25:

score: 0
Wrong Answer
time: 286ms
memory: 32040kb