QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#407528#8226. 堆操作练习题2Xiaohuba40 7ms5696kbC++234.8kb2024-05-08 21:53:592024-05-08 21:54:01

Judging History

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

  • [2024-05-22 20:40:58]
  • hack成功,自动添加数据
  • (/hack/631)
  • [2024-05-08 21:54:01]
  • 评测
  • 测评结果:40
  • 用时:7ms
  • 内存:5696kb
  • [2024-05-08 21:53:59]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

// #define LOCK_GETCHAR
// #define USE_INT_128

#if __cplusplus < 201400
#warning "Please use c++14 or higher."
#define CONSTEXPR_FUNC
#define ENABLE_IF_INT
#else
#define CONSTEXPR_FUNC constexpr
#define ENABLE_IF_INT , enable_if_t<_is_integer<T>, int> = 0
template <class T> constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <> constexpr bool _is_integer<bool> = false;
template <> constexpr bool _is_integer<char> = false;
#ifdef USE_INT_128
template <> constexpr bool _is_integer<__int128> = true;
template <> constexpr bool _is_integer<__uint128_t> = true;
#endif
template <class T ENABLE_IF_INT>
constexpr T INF = numeric_limits<T>::max() >> 1;
#endif

#if !defined(_WIN32) && !defined(LOCK_GETCHAR)
#define getchar getchar_unlocked
#endif

#define il inline
#define mkp make_pair
#define fi first
#define se second
#define For(i, j, k) for (decltype(j - k) i = (j); i <= (k); ++i)     // NOLINT
#define ForDown(i, j, k) for (decltype(j - k) i = (j); i >= (k); --i) // NOLINT
#define pb push_back
#define eb emplace_back
#ifndef ONLINE_JUDGE
#define FileIO(filename)                                                       \
  freopen(filename ".in", "r", stdin);                                         \
  freopen(filename ".out", "w", stdout)
#else
#define FileIO(filename) void(0)
#endif

using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using db = double;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef USE_INT_128
using lll = __int128_t;
using ulll = __uint128_t;
#endif

// clang-format off
#define lg(x) (31 ^ __builtin_clz((x)))
#define lgll(x) (31ll ^ __builtin_clzll((x)))
template<typename T> constexpr il T sq(const T & x){ return x * x; }
template<typename T> CONSTEXPR_FUNC il void cmin(T & x, const T &y){ x = min(x, y); }
template<typename T> CONSTEXPR_FUNC il void cmax(T & x, const T &y){ x = max(x, y);}
template<typename T> CONSTEXPR_FUNC il T qpow(T x, ull y, T mod){T ans = 1; x %= mod; while (y) { if(y & 1)(ans *= x) %= mod;(x *= x) %= mod; y >>= 1;} return ans;}
template<typename T> CONSTEXPR_FUNC il T qpow(T x, ull y){T ans = 1; while (y) {if(y & 1) ans *= x;x *= x;y >>= 1;} return ans;}
template<typename T ENABLE_IF_INT> il void read(T &x){ x = 0; int f = 1; int c = getchar(); while(!isdigit(c)) {if (c == '-') f = -1;c = getchar();} while(isdigit(c)) {x = x * 10 + c - '0';c = getchar();} x *= f;}
template<typename T, typename ... Args> il void read(T &x, Args &... y){ read(x); read(y...); }
int gcd(int a, int b) { if (!a | !b) return a + b; int az = __builtin_ctz(a); int bz = __builtin_ctz(b); int z = min(az, bz); a >>= az, b >>= bz; while (a != b) { int diff = b - a; az = __builtin_ctz(diff); b = min(a, b), a = abs(diff) >> az; } return a << z; }
ll gcd(ll a, ll b) { if (!a | !b) return a + b; ll az = __builtin_ctzll(a); ll bz = __builtin_ctzll(b); ll z = min(az, bz); a >>= az, b >>= bz; while (a != b) { ll diff = b - a; az = __builtin_ctzll(diff); b = min(a, b), a = abs(diff) >> az; } return a << z; }
// clang-format on

// File head end

namespace {
constexpr ll MAXN = (1 << 18) + 5;
int h, N, Q, a[MAXN], b[MAXN];
set<int> s[2];
bool vis[MAXN];
void dfs(int x) {
  auto check = [&](int x) -> bool {
    if (!b[x])
      return 0;
    while ((x << 1) <= N) {
      if (!b[x << 1] && !b[x << 1 | 1])
        break;
      if (b[x << 1] > b[x << 1 | 1])
        x <<= 1;
      else
        (x <<= 1) |= 1;
    }
    return !vis[x];
  };
  auto shiftDown = [&](int x) -> void {
    b[x] = 0;
    while ((x << 1) <= N) {
      if (!b[x << 1] && !b[x << 1 | 1])
        break;
      if (b[x << 1] > b[x << 1 | 1])
        swap(b[x], b[x << 1]), x <<= 1;
      else
        swap(b[x], b[x << 1 | 1]), (x <<= 1) |= 1;
    }
  };
  while (check(x)) {
    shiftDown(x);
  }
  if ((x << 1) <= N)
    dfs(x << 1), dfs(x << 1 | 1);
}
il void Main() {
  read(h), N = (1 << h) - 1;
  For(i, 1, N) read(a[i]);
  read(Q);
  while (Q--) {
    int op, x, y;
    read(op, x, y);
    fill(vis + 1, vis + 1 + N, 0);
    if (op == 1)
      s[y - 1].emplace(x);
    else if (op == 2)
      s[y - 1].erase(x);
    else {
      int maxv = (1 << s[1].size()) - 1, Ans = 0;
      for (int i : s[0])
        vis[i] = 1;
      For(S, 0, maxv) {
        for (auto [j, k] = mkp(s[1].begin(), 0); j != s[1].end(); ++j, ++k)
          if (S >> k & 1)
            vis[*j] = 1;
        copy(a + 1, a + 1 + N, b + 1);
        dfs(1), Ans += b[x] == y;
        for (auto [j, k] = mkp(s[1].begin(), 0); j != s[1].end(); ++j, ++k)
          if (S >> k & 1)
            vis[*j] = 0;
      }
      cout << Ans << '\n';
    }
  }
}
} // namespace

signed main() { return Main(), 0; }

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 3516kb

input:

2
3 2 1
50
3 3 1
1 1 2
1 2 1
2 2 1
1 2 2
2 1 2
1 1 1
1 3 2
2 1 1
2 2 2
3 1 2
3 1 3
2 3 2
1 3 2
1 2 2
2 2 2
1 2 1
1 1 2
3 1 1
2 1 2
1 1 1
2 1 1
3 1 2
3 1 3
2 3 2
1 3 2
2 2 1
1 2 1
1 1 1
3 1 2
2 1 1
1 1 1
3 3 1
2 1 1
2 3 2
1 3 1
2 3 1
1 1 2
3 1 3
2 1 2
3 3 1
3 1 3
3 1 1
3 1 1
1 3 2
1 1 1
2 1 1
3 1 1
2...

output:

0
1
0
0
0
2
0
1
2
0
1
0
0
0
0

result:

ok 15 numbers

Test #2:

score: 10
Accepted
time: 0ms
memory: 3576kb

input:

2
3 1 2
50
1 2 2
3 3 2
2 2 2
1 3 1
1 1 1
3 3 2
2 1 1
3 1 3
2 3 1
1 3 1
1 1 1
1 2 2
2 1 1
3 1 3
2 3 1
2 2 2
1 1 2
1 2 1
1 3 1
2 1 2
3 3 2
1 1 1
2 3 1
1 3 2
2 3 2
1 3 1
2 2 1
3 3 2
3 1 1
2 3 1
2 1 1
1 3 1
2 3 1
3 1 3
3 1 3
3 1 3
1 1 1
2 1 1
3 1 2
1 2 1
3 1 1
3 3 2
3 1 3
2 2 1
1 1 1
2 1 1
1 2 1
1 1 2
2...

output:

0
1
1
2
1
1
0
0
0
0
0
0
0
0
0

result:

ok 15 numbers

Subtask #2:

score: 10
Accepted

Dependency #1:

100%
Accepted

Test #3:

score: 10
Accepted
time: 1ms
memory: 3512kb

input:

4
15 14 13 9 10 11 12 2 7 4 5 1 6 8 3
500
3 1 15
3 1 13
1 9 1
1 6 2
1 15 2
1 14 1
1 10 2
1 5 2
3 12 1
1 1 1
1 4 1
3 6 6
3 10 4
1 3 1
3 13 6
1 11 2
2 4 1
2 14 1
3 6 6
3 1 11
3 1 14
3 2 4
2 6 2
2 15 2
3 1 9
3 7 12
1 13 2
2 9 1
2 5 2
3 14 8
1 15 2
1 12 1
3 11 5
1 5 2
3 1 15
3 5 10
3 1 11
1 14 1
2 13 2
...

output:

0
0
0
0
8
0
0
8
0
0
0
0
0
8
16
16
0
0
0
32
0
0
32
16
0
0
16
0
0
0
0
4
0
0
0
0
8
0
0
0
0
0
64
64
0
128
0
0
0
128
64
256
0
64
64
0
0
0
8
4
2
0
2
0
0
0
0
8
4
16
0
0
2
0
2
8
0
0
16
0
8
0
0
16
32
0
32
0
4
4
0
4
0
0
0
0
4
0
0
0
2
0
0
0
0
0
4
2
0
0
0
16
8
0
0
0
0
8
2
4
0
4
4
4
16
0
8
8
16
16
0
0
8
0
0
0
0
...

result:

ok 171 numbers

Test #4:

score: 10
Accepted
time: 1ms
memory: 5696kb

input:

4
15 13 14 7 12 8 11 3 4 9 2 5 6 1 10
500
1 2 1
1 14 2
1 4 1
3 1 12
1 15 2
3 1 15
1 9 2
2 4 1
1 13 1
3 7 1
2 13 1
2 15 2
1 7 2
1 13 1
3 15 10
2 2 1
3 2 2
1 2 2
2 2 2
1 15 2
1 11 1
2 9 2
3 3 11
1 1 1
1 12 2
3 10 9
3 4 3
3 7 1
2 7 2
1 4 1
1 5 1
2 15 2
2 12 2
1 10 2
3 2 7
3 2 13
1 3 1
3 1 15
2 1 1
3 14...

output:

1
2
0
0
0
2
0
0
2
0
2
0
2
0
8
4
0
0
8
4
0
4
4
4
1
0
0
4
0
0
8
0
0
0
32
128
0
0
0
16
0
16
0
0
0
0
8
0
0
0
0
0
16
0
32
0
0
0
8
4
0
0
4
0
0
0
0
0
8
8
0
8
0
0
0
8
0
0
16
0
0
0
0
0
0
2
0
2
0
0
2
0
0
2
1
0
0
0
0
8
16
16
0
0
0
0
0
0
0
0
0
0
0
16
0
0
16
32
0
0
16
0
32
0
0
64
0
4
0
8
0
0
0
4
1
0
0
16
4
0
0
0...

result:

ok 148 numbers

Subtask #3:

score: 20
Accepted

Test #5:

score: 20
Accepted
time: 7ms
memory: 3588kb

input:

9
511 509 510 504 507 505 508 501 503 506 502 494 500 499 493 473 483 495 475 491 497 461 487 490 489 498 496 478 485 480 488 378 469 482 477 462 448 422 470 424 467 421 492 439 454 484 451 376 385 458 464 463 486 411 472 449 474 459 468 479 413 457 455 371 315 432 437 466 453 476 418 433 363 434 38...

output:

0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
1
1
1
0
0
0
0
1
0
0
1
1
1
1
0
1
1
1
1
0
1
1
0
0
0
0
1
0
0
1
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
1
1
0
1
0
0
1
0
0
0
0
1
1
0
0
1
1
1
1
1
0
0
1
1
1
1
1
0
1
0
0
1
1
0
1
0
0
1
0
0
0
0
1
0
1
1
0
1
0
0
1
0
0
1
1
1
0
0
1
1
1
0
0
0
0
1
1
0
1
1
1
1
0
1
0
0
0
1
0
1
1
1
0
0
1
0
0
0
1
1
...

result:

ok 1644 numbers

Test #6:

score: 20
Accepted
time: 7ms
memory: 5672kb

input:

9
511 510 506 509 508 505 504 500 507 501 503 497 498 502 484 454 495 485 494 488 496 493 474 491 460 487 490 486 499 468 467 408 448 451 469 479 478 412 492 482 476 440 466 489 411 462 470 384 407 438 452 430 464 439 481 456 483 449 422 420 446 441 370 372 376 404 443 369 417 405 416 465 444 275 45...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
1
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
1
1
0
0
1
0
1
0
0
1
1
1
1
0
1
0
1
0
0
1
0
1
0
1
1
1
1
0
1
1
0
1
1
0
1
0
0
1
1
1
0
1
1
1
1
1
1
0
0
1
1
1
0
1
0
0
0
1
1
1
1
0
0
1
1
1
0
1
1
1
1
1
0
0
1
1
1
1
1
1
0
1
1
1
1
0
0
1
1
1
1
1
0
0
0
0
1
...

result:

ok 1657 numbers

Test #7:

score: 20
Accepted
time: 7ms
memory: 5628kb

input:

9
511 508 510 502 505 506 509 497 489 501 504 496 500 507 499 494 486 466 482 472 442 503 453 492 469 481 477 488 491 483 484 493 416 480 485 420 465 436 471 353 447 437 384 490 498 399 381 487 468 461 457 478 479 474 473 248 430 412 448 429 421 449 475 423 476 338 410 435 444 438 462 379 415 372 39...

output:

0
0
0
1
0
0
1
0
1
0
0
0
0
0
1
0
0
0
0
0
1
0
1
1
0
0
1
1
1
0
0
0
0
0
1
1
0
1
0
1
1
1
0
0
1
0
0
1
0
0
1
1
1
1
0
1
1
0
0
1
0
0
0
1
0
1
1
1
0
0
1
1
0
0
0
0
1
0
0
0
0
1
0
1
1
0
1
1
0
1
0
0
0
1
0
1
1
1
0
1
0
0
1
1
0
1
1
0
1
1
0
0
1
1
1
1
1
0
0
0
1
0
1
1
0
1
0
1
1
1
1
1
0
1
1
1
1
1
0
0
0
0
1
1
1
1
1
0
0
0
...

result:

ok 1644 numbers

Test #8:

score: 20
Accepted
time: 7ms
memory: 3632kb

input:

9
511 509 510 505 506 508 490 499 484 497 501 507 504 477 481 494 469 479 468 458 486 496 487 503 495 498 449 461 467 476 480 448 470 424 459 413 478 441 466 429 446 485 438 489 463 473 483 502 500 491 492 474 493 443 430 385 433 453 447 460 472 379 408 363 415 367 445 401 405 426 259 383 351 322 45...

output:

0
0
0
0
0
0
0
0
0
1
1
0
1
0
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
1
0
1
0
0
0
1
0
1
1
1
1
0
0
1
0
0
1
0
0
0
0
1
0
0
0
1
1
0
0
0
1
0
0
1
0
0
1
1
0
0
0
1
0
1
0
1
0
0
0
0
1
1
1
0
0
0
0
1
0
1
0
1
1
0
1
1
1
0
1
0
0
0
1
1
1
1
0
1
1
1
0
1
0
0
0
1
1
1
1
1
1
1
1
0
1
1
...

result:

ok 1620 numbers

Subtask #4:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #9:

score: 0
Time Limit Exceeded

input:

9
511 509 510 504 507 508 503 488 502 493 501 505 506 481 483 468 476 495 498 490 487 491 496 447 500 482 499 474 462 453 464 465 461 457 428 448 427 492 472 471 454 484 478 459 489 485 494 393 440 470 497 463 475 477 480 445 473 452 399 436 419 443 396 407 348 409 423 451 397 420 357 435 366 389 33...

output:


result:


Subtask #5:

score: 0
Time Limit Exceeded

Dependency #3:

100%
Accepted

Test #13:

score: 0
Time Limit Exceeded

input:

18
262143 262142 262141 262135 262134 262140 262137 262119 262122 262133 262117 262136 262139 262129 262130 262114 262088 262099 262080 262126 262131 262091 262101 262128 262132 262138 262115 262103 262121 262069 262094 262111 262078 261968 262042 262032 262097 262059 262074 262086 262113 262124 262...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

0%