QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#450016#7760. 化学实验Made_in_Code0 41ms15372kbC++143.3kb2024-06-21 22:44:222024-06-21 22:44:23

Judging History

This is the latest submission verdict.

  • [2024-06-21 22:44:23]
  • Judged
  • Verdict: 0
  • Time: 41ms
  • Memory: 15372kb
  • [2024-06-21 22:44:22]
  • Submitted

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#include <iostream>

using namespace std;

const int kMaxN = 5e5 + 1;
struct V {
  int mn, c, t;
  int f, s[2];
} v[kMaxN];
int u, n, m;

void TagC(int x, int y) {
  v[x].c += y, v[x].t += y;
}

void Pushdown(int x) {
  if (v[x].t) {
    TagC(v[x].s[0], v[x].t);
    TagC(v[x].s[1], v[x].t);
    v[x].t = 0;
  }
}

void Pushup(int x) {
  v[x].mn = x;
  v[x].s[0] && (v[x].mn = min(v[x].mn, v[v[x].s[0]].mn));
  v[x].s[1] && (v[x].mn = min(v[x].mn, v[v[x].s[1]].mn));
}

int Son(int x) {
  return (v[v[x].f].s[0] == x) + (v[v[x].f].s[1] == x) * 2 - 1;
}

void RePush(int x) {
  ~Son(x) ? RePush(v[x].f) : void(), Pushdown(x);
}

void Rotate(int x, bool o) {
  int y = v[x].s[!o], s = Son(x);
  v[x].s[!o] = v[y].s[o], v[y].s[o] = x;
  v[y].f = v[x].f, v[x].f = y;
  v[v[x].s[!o]].f = x, ~s && (v[v[y].f].s[s] = y);
  Pushup(x), Pushup(y);
}

void Splay(int x) {
  RePush(x);
  while (~Son(x)) {
    int s = Son(x), t = Son(v[x].f);
    if (~t) {
      Rotate(s == t ? v[v[x].f].f : v[x].f, !s);
      Rotate(v[x].f, !t);
    } else {
      Rotate(v[x].f, !s);
    }
  }
}

void Access(int x) {
  for (int y = 0; x; y = x, x = v[x].f) {
    Splay(x), v[x].s[1] = y, Pushup(x);
  }
}

int FindTop(int x) {
  Splay(x);
  for (; v[x].s[0];) {
    x = v[x].s[0], Pushdown(x);
  }
  return Splay(x), x;
}

int FindRoot(int x) {
  return Access(x), FindTop(x);
}

int FindFa(int x) {
  Splay(x);
  for (x = v[x].s[0]; v[x].s[1]; x = v[x].s[1]) {
    Pushdown(x);
  }
  return Splay(x), x;
}

int FindGap(int x, int y) {
  Pushdown(x);
  if (v[x].s[0] && v[v[x].s[0]].mn <= y) {
    return FindGap(v[x].s[0], y);
  } else if (x <= y) {
    return Splay(x), x;
  }
  return FindGap(v[x].s[1], y);
}

void Merge(int x, int y) {
  int topx, topy, _x, _y, f, mid;
  Access(x), topx = FindTop(x);
  if (topx == FindTop(y)) {
    return;
  }
  Access(y), topy = FindTop(y);
  if (FindTop(x) == topy) {
    return;
  }
  _x = FindTop(x), Access(f = v[_x].f), _y = FindTop(y);
  if (topx == topy) {
    _x < _y ? swap(_x, _y), swap(x, y) : void();
    Splay(f), TagC(f, -v[_y].c), v[_y].f = 0;  // Cut(_y, f)
    Access(x), Access(y);
  }
  for (; Splay(_x), v[_x].mn < _y;) {
    _x = FindGap(_x, _y);
    if (~Son(_x)) {
      mid = FindFa(_x);
      Access(mid), Splay(mid), Splay(_x);  // Cut(mid, _x);
      v[_x].f = 0, TagC(mid, -v[_x].c);
      Access(_y), Splay(_y), v[_y].f = mid;  // Link(_y, mid);
      Access(mid), Splay(mid), TagC(mid, v[_y].c);
      Access(x), Access(y);
    }
    swap(_x, _y), swap(x, y);
  }
  Access(_y), Splay(_y), v[_y].f = x;  // Link(x, _y);
  Access(x), Splay(x), TagC(x, v[_y].c);
}

int Ask(int x, int y) {
  x = FindGap(FindRoot(x), y);
  return Access(x), v[x].c;
}

int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(0);
  for (int i = 0; i < kMaxN; i++) {
    v[i].mn = i, v[i].c = 1;
  }
  cin >> u >> n >> m;
  for (int i = 1, o, x, y, p = 0; i <= m; i++) {
    cin >> o >> x >> y;
    if (u) {
      x = (x + p - 1) % n + 1, y = (y + p - 1) % n + 1;
    }
    if (o == 1) {
      Merge(x, y);
    } else {
      cout << (p = Ask(x, y)) << '\n';
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 15372kb

input:

1 7500 7500
1 263 1446
1 6338 3037
1 5651 6129
1 572 3137
1 3159 5472
1 6038 4451
1 5988 5462
1 3873 1562
1 3516 5142
1 3375 2376
1 5832 1884
1 6243 3066
1 4001 6195
1 5301 6851
1 4382 2910
1 5299 562
1 452 335
1 3459 814
1 6681 6391
1 5816 4975
1 2244 1118
1 1410 1067
1 331 6324
1 6305 1294
1 4251 ...

output:

20

result:

wrong answer 1st lines differ - expected: '3984', found: '20'

Subtask #2:

score: 0
Time Limit Exceeded

Test #11:

score: 0
Time Limit Exceeded

input:

1 5000 100000
2 872 876
1 2895 4566
1 2676 1220
2 1852 1856
2 4153 4153
2 3675 3685
2 1489 1493
2 2782 2784
2 206 207
2 555 560
2 4149 4157
2 1875 1885
2 364 374
2 8 17
2 746 754
2 4785 4786
2 2394 2394
2 3386 3389
2 365 373
2 2290 2296
2 1419 1428
2 3651 3659
2 1922 1927
2 4877 4882
2 2597 2599
2 4...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:


Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 41ms
memory: 15360kb

input:

0 100000 100000
1 29135 32144
1 58340 30601
1 68869 18606
1 73019 84578
1 13050 79881
1 22773 20030
1 74542 28744
1 46491 64238
1 26985 17174
1 93308 48003
1 90547 4510
1 18373 35069
1 34019 14080
1 13461 19407
1 33811 60169
1 22131 76457
1 88085 38979
1 49749 20241
1 90505 42660
1 25889 75426
1 420...

output:

28

result:

wrong answer 1st lines differ - expected: '80930', found: '28'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #4:

0%