QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#482194#21403. 文艺平衡树mfeitveerWA 1ms5904kbC++142.0kb2024-07-17 18:07:562024-07-17 18:07:56

Judging History

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

  • [2024-07-17 18:07:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5904kb
  • [2024-07-17 18:07:56]
  • 提交

answer

/*
  ! 以渺小启程,以伟大结束。
  ! Created: 2024/07/17 18:00:31
*/
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
// #define int long long
#define mp(x, y) make_pair(x, y)
#define eb(...) emplace_back(__VA_ARGS__)
#define fro(i, x, y) for (int i = (x); i <= (y); i++)
#define pre(i, x, y) for (int i = (x); i >= (y); i--)
inline void JYFILE19();

typedef long long i64;
typedef pair<int, int> PII;

bool ST;
const int N = 1e6 + 10;
const int mod = 998244353;

int n, m, rt;
int ls[N], rs[N], tg[N], sz[N], rd[N];

inline void psh(int p) {
  if (p) swap(ls[p], rs[p]), tg[p] ^= 1;
}
inline void pdo(int p) {
  if (tg[p]) {
    psh(ls[p]), psh(rs[p]), tg[p] = 0;
  }
}
inline void pup(int p) {
  sz[p] = 1;
  sz[p] += sz[ls[p]];
  sz[p] += sz[rs[p]];
}
inline auto mer(int x, int y) {
  if (!x || !y) return x + y; pdo(x), pdo(y);
  if (rd[x] < rd[y]) return rs[x] = mer(rs[x], y), pup(x), x;
  return ls[y] = mer(x, ls[y]), pup(y), y;
}
inline void spl(int p, int k, int &x, int &y) {
  if (!p) return x = y = 0, void(); pdo(p);
  if (k <= sz[ls[p]]) spl(ls[p], k, x, ls[y = p]);
  else spl(rs[p], k - sz[ls[p]] - 1, rs[x = p], y); pup(p);
}
inline void rev(int l, int r) {
  int x, y, z;
  spl(rt, r, y, z);
  spl(y, l - 1, x, y);
  psh(y);
  rt = mer(x, mer(y, z));
}
inline void print(int p) {
  if (ls[p]) print(ls[p]);
  cout << p << " ";
  if (rs[p]) print(rs[p]);
}

signed main() {
  JYFILE19();
  cin >> n >> m;
  fro(i, 1, n) sz[i] = 1;
  fro(i, 1, n) rd[i] = rand();
  fro(i, 1, n) rt = mer(rt, i);
  fro(i, 1, m) {
    int l, r;
    cin >> l >> r;
    rev(l, r);
  }
  print(rt);
  return 0;
}

bool ED;
inline void JYFILE19() {
  // freopen("", "r", stdin);
  // freopen("", "w", stdout);
  srand(random_device{}());
  ios::sync_with_stdio(0), cin.tie(0);
  double MIB = fabs((&ED-&ST)/1048576.), LIM = 32;
  cerr << "MEMORY: " << MIB << endl, assert(MIB<=LIM);
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5904kb

input:

30 5
7 26
7 18
5 9
4 15
3 15

output:

1 2 4 17 16 15 6 5 18 19 20 21 22 23 3 24 25 26 14 13 9 10 11 12 8 7 27 28 29 30 

result:

wrong answer 1st lines differ - expected: '1 2 4 17 16 15 6 5 18 19 20 21...4 13 12 11 10 9 8 7 27 28 29 30', found: '1 2 4 17 16 15 6 5 18 19 20 21... 13 9 10 11 12 8 7 27 28 29 30 '