记录详情

Time Exceeded


  
# 状态 耗时 内存占用
#1 Accepted 50ms 16.461 MiB
#2 Accepted 48ms 18.312 MiB
#3 Accepted 44ms 16.457 MiB
#4 Accepted 45ms 16.461 MiB
#5 Accepted 42ms 16.445 MiB
#6 Accepted 1342ms 49.297 MiB
#7 Accepted 1433ms 55.18 MiB
#8 Accepted 1261ms 51.109 MiB
#9 Accepted 1469ms 56.594 MiB
#10 Accepted 1419ms 53.676 MiB
#11 Time Exceeded ≥10001ms ≥193.727 MiB
#12 Time Exceeded ≥10000ms ≥192.527 MiB
#13 Time Exceeded ≥10001ms ≥193.066 MiB
#14 Time Exceeded ≥10001ms ≥191.281 MiB
#15 Time Exceeded ≥10000ms ≥196.758 MiB
#16 Time Exceeded ≥10000ms ≥193.172 MiB
#17 Time Exceeded ≥10002ms ≥195.008 MiB
#18 Time Exceeded ≥10003ms ≥194.262 MiB
#19 Time Exceeded ≥10000ms ≥196.879 MiB
#20 Time Exceeded ≥10004ms ≥202.77 MiB

代码

#include <bits/stdc++.h>
using namespace std;
int seed, n;
int rnd() { return seed = (seed * 19260817ll + 20230853) & INT_MAX; }
const int N = 4e7 + 20, inf = INT_MAX, K = 80;
int rt, rth = 1, tot, mn = inf, mnb = 2;
int f[N], l[N], r[N], v[N], cnt[N], ch[N][2];
bool ok[N];
inline void pup(int x) { v[x] = max(v[ch[x][0]], v[ch[x][1]]); }
inline bool meg(int ls, int rs) {
  if (f[ls]) {
    ch[f[ls]][0] = ls;
    ch[f[ls]][1] = rs;
    f[rs] = f[ls];
    pup(f[ls]);
  } else if (f[rs]) {
    ch[f[rs]][0] = ls;
    ch[f[rs]][1] = rs;
    f[ls] = f[rs];
    pup(f[rs]);
  } else {
    int x = f[r[rs]];
    r[++tot] = x;
    l[tot] = l[x];
    r[l[x]] = tot;
    l[x] = tot;
    f[ls] = f[rs] = tot;
    ch[tot][0] = ls;
    ch[tot][1] = rs;
    v[tot] = max(v[ls], v[rs]);
    return 0;
  }
  return 1;
}
inline void push(int x) {
  int now = rt, nh = rth, op1, op2; 
  op1 = (nh << 1) - 1;  
  while (nh > 1) {
    l[now] = op1;
    r[op1] = now;
    if (mn > v[ch[now][0]]) {
      if (now == rt) {
        r[op1] = op1 + 1;
        l[op1 + 1] = op1;
        rt = ch[now][1];
        f[rt] = 0;  
        rth--;      
      }
      ch[now][0] = 0;
      ok[ch[now][1]] = 0;
      now = ch[now][1];
    } else
      now = ch[now][0];
    nh--;
    op1 -= 2;
  }
  l[now] = 1;
  r[1] = now;
  now = rt, nh = rth;
  while (nh > 1) {
    now = ch[now][(x > v[ch[now][0]])];
    nh--;
  }
  if (x == v[now]) {
    cnt[now]++;
    return;
  }
  r[++tot] = now;
  l[tot] = l[now];
  r[l[now]] = tot;
  l[now] = tot;
  v[tot] = x;
  cnt[tot] = 1;
  if (x < mn) {
    mn = x;
    mnb = tot;
  }
  now = tot;
  nh = 1;
  while (1) {
    op1 = l[now];
    op2 = r[now];
    if (!ok[op1]) {  
      ok[now] = ok[op1] = 1;
      if (meg(op1, now)) {
        while (now != rt) { 
          now = f[now];
          pup(now);
        }
        return;
      }
    } else if (!ok[op2]) {  
      ok[now] = ok[op2] = 1;
      if (meg(now, op2)) return;
    } else if (f[op1] == f[op2]) {  
      ch[f[op1]][0] = 0;
      f[now] = f[op1] = 0;
      meg(op1, now);
      ok[now] = ok[op1] = 1;
      ok[op2] = 0;
    } else if (op1 > K || op2 > K) {  
      meg(now, now);
    } else {  
      rt = now;
      rth = nh;  
      return;
    }
    now = f[now];
    nh++;
  }
}
inline int top() { return mn; }
inline void pop() {
  if (--cnt[mnb] > 0) return;
  mnb = r[mnb];
  mn = v[mnb];
}
int main() {
  v[0] = -inf;
  for (int i = 1; i <= K; ++i) {
    f[i] = i + 2;
    ok[i] = 1;
    if (i & 1) {
      r[i] = i + 1;
      v[i] = -inf;
    } else {
      l[i] = i - 1;
      v[i] = inf;
    }
  }
  rt = tot = K + 1;
  v[rt] = inf;
  l[rt] = 1;
  r[rt] = 2;
  cin >> n >> seed;
  int ans = 0;
  for (int i = 1; i <= (n >> 1); ++i) push(rnd());
  for (int i = 1; i <= (n >> 1); ++i) {
    switch (rnd() % 3) {
      case 0:
        push(rnd());
        break;
      case 1:
        pop();
        break;
      default:
        ans ^= top();
    }
  }
  cout << ans << endl;
  return 0;
}

信息

递交者
类型
递交
题目
P1004 Heaptester
语言
C++
递交时间
2020-12-20 09:12:09
评测时间
2020-12-20 09:12:11
评测机
分数
50
总耗时
≥107175ms
峰值内存
≥202.77 MiB