QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#89562#5358. 宝石游戏Scintilla0 2ms17932kbC++143.2kb2023-03-20 16:18:512023-03-20 16:18:56

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-20 16:18:56]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:17932kb
  • [2023-03-20 16:18:51]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl

using pii = pair <int, int>;

const int N = 2e5 + 10;

int read() {
  int x = 0, f = 1; char c = getchar();
  for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  return x * f;
}

int n, m, B, a[N], dfn[N], dn, sz[N], mx[N], mson[N], dep[N], ans[N], l, r;
int pool[N << 1], *fcur, *f[N], *gcur, *g[N], ca[N], cf[N];
vector <int> e[N];

struct node {
  int op, u, k;
} o[N];

void dfs0(int u, int fa) {
  dfn[u] = ++ dn, sz[u] = 1;
  for (int v : e[u]) if (v != fa) {
    dep[v] = dep[u] + 1, dfs0(v, u), sz[u] += sz[v];
    if (mx[v] + 1 > mx[u]) mx[u] = mx[v] + 1, mson[u] = v;
  }
}

void dfs1(int u, int fa) {
  f[u] = ++ fcur, g[u] = ++ gcur;
  if (mson[u]) dfs1(mson[u], u);
  for (int v : e[u]) if (v != fa && v != mson[u]) dfs1(v, u);
}

bool in(int u, int v) {
  return dfn[u] <= dfn[v] && dfn[v] < dfn[u] + sz[u];
}

void dfs2(int u, int fa) {
  f[u][0] = g[u][0] = a[u];
  if (mson[u]) dfs2(mson[u], u), g[u][0] ^= g[u][1];
  for (int v : e[u]) if (v != fa && v != mson[u]) {
    dfs2(v, u);
    rep(i, 0, mx[v]) f[u][i + 1] += f[v][i];
    g[u][mx[v] + 1] = f[u][mx[v] + 1];
    if (mx[v] + 1 < mx[u]) g[u][mx[v] + 1] ^= g[u][mx[v] + 2];
    drep(i, mx[v], 0) g[u][i] = g[u][i + 1] ^ f[u][i];
  }
  // cout << "------- u = " << u << endl;
  // pa(f[u], 0, mx[u]);
  // pa(g[u], 0, mx[u]);
  rep(i, l, r) if (o[i].op == 2 && o[i].u == u) {
    // pv(i);
    int res = g[u][0], lim = o[i].k;
    // cout << "lim, mx[u] = " << lim << ' ' << mx[u] << endl;
    // pv(res);
    if (lim < mx[u]) res ^= g[u][lim + 1];
    // pv(res);
    for (int j = l, v, d; j < i; ++ j)  {
      if (o[j].op == 1 && in(u, v = o[j].u) && (d = dep[v] - dep[u]) <= lim) {
        // pv(j);
        if (!~ca[v]) ca[v] = a[v];
        if (!~cf[d]) cf[d] = f[u][d];
        // cout << "d, cf[d] = " << d << ' ' << cf[d] << endl;
        res ^= cf[d], cf[d] -= a[v];
        a[v] = o[j].k;
        cf[d] += a[v], res ^= cf[d];
      }
    }
    for (int j = l, v, d; j < i; ++ j)  {
      if (o[j].op == 1 && in(u, v = o[j].u) && (d = dep[v] - dep[u]) <= lim) cf[d] = -1;
    }
    ans[i] = res;
  }
}

int main() {
  n = read(), m = read(), B = sqrt(m);
  rep(i, 0, n) ca[i] = cf[i] = -1;
  rep(i, 1, n) a[i] = read();
  rep(i, 1, n - 1) {
    int u = read(), v = read();
    e[u].emplace_back(v);
    e[v].emplace_back(u);
  }
  dfs0(1, 0);
  fcur = pool, gcur = pool + 2 * n;
  dfs1(1, 0);
  // pa(mson, 1, n);
  rep(i, 1, m) o[i].op = read(), o[i].u = read(), o[i].k = read();
  for (l = 1, r; l <= m; l = r + 1) {
    r = min(l + B - 1, m), dfs2(1, 0);
    rep(i, l, r) if (o[i].op == 1) a[o[i].u] = o[i].k;
  }
  rep(i, 1, m) if (o[i].op == 2) printf("%d\n", ans[i]);
  return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 1ms
memory: 17932kb

input:

7 5
1 2 3 4 5 6 7
3 1
2 4
3 7
6 7
5 4
4 1
2 1 1
2 4 0
2 7 2
1 6 0
2 7 1

output:

6
4
1
7

result:

ok 4 lines

Test #2:

score: -7
Wrong Answer
time: 2ms
memory: 15768kb

input:

1000 1000
168301431 651266519 181230331 997564131 922958564 240686472 828844423 997226083 101127334 549182223 815802272 962217487 872007143 308493550 875871642 388491137 726655288 632336322 36483715 91926885 973887125 969715766 903583959 709995095 551483747 454472802 645719871 210282402 246763026 76...

output:

247568283
-1537711525
1022133674
1742312761
1584695524
1590263843
-510792285
-232917572
-2028567613
-2083073458
-1994651746
-825476931
-947965767
-778729642
1131710643
1370093099
1607160706
1972665914
1120695178
-1707079430
1783198543
-1635664461
1377531468
910569544
1455205342
-2029833898
-30664552...

result:

wrong answer 1st lines differ - expected: '13348898220', found: '247568283'

Subtask #2:

score: 0
Time Limit Exceeded

Test #14:

score: 0
Time Limit Exceeded

input:

100000 100000
405003099 610837546 348589233 875137317 862931320 731758484 582603782 989991623 184749683 961137536 740146957 148627391 849777698 445045421 119699522 266347287 445197848 974544475 91680144 328247730 665144499 422991113 252383902 770011580 393442268 470439648 712319066 315986988 4789186...

output:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #20:

score: 0
Time Limit Exceeded

input:

100000 100000
391636738 188947351 607003168 699971181 102753269 291890533 830830147 76057458 623517854 58958317 449828617 773557323 669394342 548355126 601286710 238603435 809091745 772998770 894693501 564199529 196062134 2803096 781469712 870912328 138245421 273392139 476952377 787775209 401014779 ...

output:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #26:

score: 0
Time Limit Exceeded

input:

100000 100000
620733757 384382313 514191349 902009280 482178057 905939364 286556695 762555921 287205978 88334200 437152915 320217018 981790168 254780145 881516456 779810222 814317342 292303220 272120273 65511383 98150102 177581894 12582058 656218139 789187030 442791738 134622788 62465827 954191430 1...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%