/ WOJ /

记录详情

System Error


  
Testdata configuration incorrect.
Memory limit larger than memory_max

代码

#include <bits/extc++.h>
#define endl '\n'
typedef long long ll;
#define int ll
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

int get_dep(const int &u) {
  if (!u) return 0ll;
  return 64ll - __builtin_clzll(u);
}

int ar[1919810];

void Main() {
  int n, m;
  cin >> n >> m;
  gp_hash_table<int, int> ht, cut;
  auto get_sz = [&](const int &u) {
    const int &d = get_dep(u), &chk = n - d + 1;
    if (chk <= 0) {
      return 1ll;
    }
    return (1ll << chk) - 1ll;
  };
  auto f = [&](const int &u) {
    if (u < 1919810) {
      if (ar[u] != -1) {
        return ar[u];
      }
      return get_sz(u);
    }
    if (const auto &it = ht.find(u); it != ht.end()) {
      return it->second;
    }
    return get_sz(u);
  };
  auto get_rt = [&](const int &u) {
    int rt = u;
    while (rt != 1) {
      if (cut.find(rt) != cut.end()) {
        break;
      }
      rt >>= 1;
    }
    return rt;
  };
  int res = 0;
  while (m--) {
    int op, x;
    cin >> op >> x;
    if (op == 1) {
      if (x == 1 || cut.find(x) != cut.end()) {
        continue;
      }
      cut.insert({x, 0});
      const int &a = f(x), p = x >> 1;
      int nd = p;
      while (nd) {
        if (cut.find(nd) != cut.end()) {
          if (nd < 1919810) {
            if (ar[nd] == -1) {
              ar[nd] = get_sz(nd);
            }
            ar[nd] -= a;
          } else {
            if (ht.find(nd) == ht.end()) {
              ht[nd] = get_sz(nd);
            }
            ht[nd] -= a;
          }
          break;
        }
        if (nd < 1919810) {
          if (ar[nd] == -1) {
            ar[nd] = get_sz(nd);
          }
          ar[nd] -= a;
        } else {
          if (ht.find(nd) == ht.end()) {
            ht[nd] = get_sz(nd);
          }
          ht[nd] -= a;
        }
        if (nd == 1) {
          break;
        }
        nd >>= 1;
      }
    } else if (op == 2) {
      res ^= f(get_rt(x));
    }
  }
  cout << res << endl;
}

// #define __CP_MULTI_TEST_CASES

signed main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  memset(ar, -1, sizeof(ar));
  int t = 1;
#ifdef __CP_MULTI_TEST_CASES
  cin >> t;
#endif
  while (t--) {
    Main();
  }
  return cout << flush, fflush(stdout), 0;
}

信息

递交者
类型
递交
题目
P1000 云剪贴板
题目数据
下载
语言
C++
递交时间
2025-07-17 09:36:19
评测时间
2025-07-17 12:52:02
评测机
分数
0
总耗时
0ms
峰值内存
0 Bytes