QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#516577#4401. PrizeJWRuixi0 290ms228212kbC++203.1kb2024-08-12 19:04:192024-08-12 19:04:19

Judging History

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

  • [2024-08-12 19:04:19]
  • 评测
  • 测评结果:0
  • 用时:290ms
  • 内存:228212kb
  • [2024-08-12 19:04:19]
  • 提交

answer

#ifdef LOCAL
#include "stdafx.h"
#else
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;

using vi = vector<int>;
#endif

constexpr int N = 1e6 + 9;
int n, K, Q, T;
vi S;

struct tree {
  int rt, hd[N], tot;

  struct {
    int v, nx;
  } e[N];

  void add_edge (int u, int v) {
    e[++tot] = {v, hd[u]};
    hd[u] = tot;
  }

  int dfn[N], dfc, st[20][N];

  void dfs (int u, int f) {
    st[0][dfn[u] = ++dfc] = f;
    for (int i = hd[u], v; i; i = e[i].nx) {
      dfs(v = e[i].v, u);
    }
  }

  int C (int x, int y) {
    return dfn[x] < dfn[y] ? x : y;
  }

  void init () {
    L (i, 1, 19) {
      L (j, 1, n - (1 << i) + 1) {
        st[i][j] = C(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
      }
    }
  }

  int lca (int x, int y) {
    if (x == y) {
      return x;
    }
    if ((x = dfn[x]) > (y = dfn[y])) {
      swap(x, y);
    }
    int i = __lg(y - x++);
    return C(st[i][x], st[i][y - (1 << i) + 1]);
  }

  void in () {
    L (x, 1, n) {
      int y;
      scanf("%d", &y);
      if (~y) {
        add_edge(y, x);
      } else {
        rt = x;
      }
    }
    dfs(rt, 0);
    init();
  }

  vector<pair<int, int>> g[N];
  int d[N];

  void add (int u, int v, int w) {
    g[u].eb(v, w);
    g[v].eb(u, -w);
  }

  void sol () {
    int R = S[0];
    L (i, 1, K - 1) {
      R = lca(R, S[i]);
    }
    memset(d, -1, (n + 1) << 2);
    queue<int> q;
    q.push(R);
    d[R] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (auto [v, w] : g[u]) {
        if (d[v] == -1) {
          d[v] = d[u] + w;
          assert(d[v] >= 0);
          q.push(v);
        }
      }
    }
  }

  int dis (int x, int y) {
    return d[x] + d[y] - 2 * d[lca(x, y)];
  }
} t[2];

int main () {
  scanf("%d%d%d%d", &n, &K, &Q, &T);
  L (i, 0, 1) {
    t[i].in();
  }
  S.reserve(K);
  // L (i, 1, n) {
  //   if (t[0].dfn[i] <= K) {
  //     S.eb(i);
  //   }
  // }
  L (i, 1, K) {
    S.eb(i);
  }
  L (i, 0, K - 1) {
    printf("%d ", S[i]);
  }
  printf("\n");
  fflush(stdout);
  // sort(S.begin(), S.end(), [] (int x, int y) {
  //   return t[1].dfn[x] < t[1].dfn[y];
  // });
  // L (i, 1, K - 1) {
  //   printf("? %d %d\n", S[i - 1], S[i]);
  // }
  printf("!\n");
  fflush(stdout);
  // L (i, 1, K - 1) {
    // int l = t[0].lca(S[i - 1], S[i]);
    // int d1, d2;
    // scanf("%d%d", &d1, &d2);
    // t[0].add(l, S[i - 1], d1);
    // t[0].add(l, S[i], d2);
    // l = t[1].lca(S[i - 1], S[i]);
    // scanf("%d%d", &d1, &d2);
    // t[1].add(l, S[i - 1], d1);
    // t[1].add(l, S[i], d2);
  // }
  // t[0].sol();
  // t[1].sol();
  while (T--) {
    int x, y;
    scanf("%d%d", &x, &y);
    // printf("%d %d\n", t[0].dis(x, y), t[1].dis(x, y));
    printf("2 2\n");
  }
  fflush(stdout);
}
// I love WHQ!

詳細信息

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

500000 64682 64681 100000
46115
470589
209303
2979
473162
343535
79503
299539
404621
102085
237721
279170
392890
165201
441593
456314
218991
358478
86614
410800
159785
169761
95368
285837
297549
370283
378974
26449
444381
39320
149913
404523
144109
174828
263837
49847
468694
478535
152644
216598
301...

output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...

result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #13:

score: 0
Time Limit Exceeded

input:

500000 88721 177440 100000
30974
23891
211201
125199
180489
387190
218020
498838
230147
307989
484136
257785
353027
304420
311738
169842
334090
486070
126212
328609
174959
368840
238722
418092
488389
226349
427271
457322
332454
12958
197530
264474
355717
482774
221286
282148
216441
266659
213750
628...

output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...

result:


Subtask #3:

score: 0
Wrong Answer

Test #25:

score: 0
Wrong Answer
time: 290ms
memory: 228212kb

input:

500000 200 199 40000
76296
130139
291501
292412
139543
433345
372726
451574
18315
465578
324564
477223
237354
81532
65170
465332
342130
9670
193303
193680
129668
149532
268907
89969
398275
356210
324593
433492
482232
466692
135343
433758
102545
287283
432859
351864
305769
489532
101532
450535
295762...

output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...

result:

wrong answer wrong answer on the first integer of query #1: read 2 but expected 22200089

Subtask #4:

score: 0
Time Limit Exceeded

Test #37:

score: 0
Time Limit Exceeded

input:

1000000 1000 999 100000
678746
439069
32542
85937
936926
284219
461661
203235
533462
940676
230275
621140
780674
254931
562355
229273
201341
493976
358955
963527
880412
91220
474599
160086
698841
591551
718276
844558
39859
765917
34722
401724
219774
443004
682244
545401
968419
968020
354030
411187
1...

output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...

result:


Subtask #5:

score: 0
Skipped

Dependency #4:

0%