QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#331597 | #8226. 堆操作练习题2 | djwj233 | 0 | 0ms | 26492kb | C++14 | 2.0kb | 2024-02-18 15:39:54 | 2024-02-18 15:39:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fo(v,a,b) for(int v = a; v <= b; v++)
#define fr(v,a,b) for(int v = a; v >= b; v--)
#define cl(a,v) memset(a, v, sizeof(a))
typedef long long ll;
const ll P = 1e9 + 7;
const int N = 3e5 + 10, QMAX = 5e5 + 10, M = 1e6 + 10;
int h, n, arr[N];
struct query { int o, x, y; } q[QMAX];
ll ans[N], pw[N]; vector<int> V[N], des[N];
int val[N], tmp[M], mark[M], pos[N];
struct Fenwick {
int b[N];
void add(int x, int C) {
for(; x <= n; x += x & -x) b[x] += C;
}
int ask(int x) {
int res = 0; for(; x; x -= x & -x) res += b[x];
return res;
}
} F[3];
int main()
{
scanf("%d", &h), n = (1 << h) - 1;
fo(i, 1, n) {
scanf("%d", &arr[i]);
int p = i; while(p) des[p].push_back(i), p >>= 1;
}
pw[0] = 1; fo(i, 1, n) pw[i] = 2 * pw[i - 1] % P;
int Q; scanf("%d", &Q);
fo(i, 1, Q) {
scanf("%d%d%d", &q[i].o, &q[i].x, &q[i].y);
int p = q[i].x; if(q[i].o == 3) { V[p].push_back(i); continue; }
while(p) V[p].push_back(i), p >>= 1;
}
fo(i, 1, n) {
int m = 0, sum = 0;
for(int x : des[i]) m++, val[m] = arr[x];
sort(val + 1, val + m + 1);
fo(j, 1, m) tmp[val[j]] = j, mark[val[j]] = i;
for(int x : des[i]) pos[x] = tmp[arr[x]];
for(int id : V[i]) {
if(q[id].o == 1) {
F[q[id].y].add(pos[q[id].x], 1), sum += (q[id].y == 2);
} else if(q[id].o == 2) {
F[q[id].y].add(pos[q[id].x], -1), sum -= (q[id].y == 2);
} else {
if(mark[q[id].y] != i) { ans[id] = 0; continue; }
int p = m - tmp[q[id].y] + 1, u = F[1].ask(p), v = F[2].ask(p);
if(F[1].ask(p - 1) == 0 && (u == 1 || (v - F[2].ask(p - 1)) == 1))
ans[id] = pw[sum - v];
}
}
}
fo(i, 1, Q) if(q[i].o == 3) printf("%lld\n", ans[i]);
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: 0ms
memory: 26492kb
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 0 1 0 1 1 1 0 0 0 0 0 0 0 0
result:
wrong answer 2nd numbers differ - expected: '1', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 0ms
memory: 20480kb
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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 13th numbers differ - expected: '1', found: '0'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%