QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276415#6520. Classic ProblemisaunoyaWA 314ms22232kbC++232.6kb2023-12-05 20:59:192023-12-06 00:10:51

Judging History

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

  • [2023-12-06 00:10:51]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:WA
  • 用时:314ms
  • 内存:22232kb
  • [2023-12-05 20:59:19]
  • 评测
  • 测评结果:100
  • 用时:307ms
  • 内存:22732kb
  • [2023-12-05 20:59:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T> ostream &operator<<(ostream &out, const vector<T> &x) {
  if (x.empty())
    return out << "[]";
  out << '[' << x[0];
  for (int len = x.size(), i = 1; i < len; i++)
    out << ',' << x[i];
  return out << ']';
}
template <typename T> vector<T> ary(const T *a, int l, int r) {
  return vector<T>{a + l, a + 1 + r};
}
template <typename T> void debug(T x) { cerr << x << '\n'; }
template <typename T, typename... S> void debug(T x, S... y) {
  cerr << x << ' ', debug(y...);
}
const int N = 2e5 + 10, E = 4e7 + 10;
int T, n, m, k;
struct edges {
  int u, v, w;
} e[E];
int p[N];
ll ans;
vector<int> to[N];
int cnt, fa[N];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
bool merge(int x, int y) {
  x = find(x), y = find(y);
  if (x == y)
    return 0;
  return cnt--, fa[x] = y, 1;
}
int vis[N], cur[N];
void link(int lim) {
  for (int i = 1; i <= n; i++) {
    for (int v : to[i])
      vis[v] = 1;
    int t = p[i - 1] + 1;
    for (int l; (l = cur[i]) >= 1; cur[i]--) {
      int d = -1;
      if (!vis[l])
        d = t - p[l];
      else if (p[i] > t)
        d = t - p[l];
      else if (p[l - 1] + 1 < p[l])
        d = t - p[l] + 1;
      else
        continue;
      if (d > lim)
        break;
      if (merge(l, i))
        ans += d;
    }
    for (int v : to[i])
      vis[v] = 0;
  }
}
void get() {
  scanf("%d%d", &m, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
    p[++n] = e[i].u, p[++n] = e[i].v;
  }
  sort(p + 1, p + 1 + n), n = unique(p + 1, p + 1 + n) - p - 1;
  if (p[n] != m)
    p[++n] = m;
  auto trs = [&](int &x) { x = lower_bound(p + 1, p + 1 + n, x) - p; };
  for (int i = 1; i <= k; i++) {
    trs(e[i].u), trs(e[i].v);
    to[e[i].v].push_back(e[i].u);
  }
  for (int i = 1; i <= n; i++) {
    ans += p[i] - p[i - 1] - 1;
    cnt -= p[i] - p[i - 1] - 1;
  }
  for (int i = 1; i <= n; i++)
    cur[i] = i - 1;
  iota(fa, fa + 1 + n, 0);
  sort(e + 1, e + 1 + k, [](edges x, edges y) { return x.w < y.w; });
  cnt = n;
  int i = 1;
  for (int x = 0, lim = sqrt(k * 2) + 10; cnt > 1 && x < lim; x++) {
    for (; i <= k && e[i].w <= x; i++)
      if (merge(e[i].u, e[i].v))
        ans += e[i].w;
    link(x);
  }
  for (; i <= k; i++)
    if (merge(e[i].u, e[i].v))
      ans += e[i].w;
  printf("%lld\n", ans);
}
void clr() {
  for (int i = 1; i <= n; i++)
    to[i].clear();
  n = ans = 0;
}
int main() {
  for (scanf("%d", &T); T--; clr())
    get();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11840kb

input:

3
5 3
1 2 5
2 3 4
1 5 0
5 0
5 4
1 2 1000000000
1 3 1000000000
1 4 1000000000
1 5 1000000000

output:

4
4
1000000003

result:

ok 3 number(s): "4 4 1000000003"

Test #2:

score: 0
Accepted
time: 282ms
memory: 18224kb

input:

16
1000000000 0
447 99681
1 2 1000000000
1 3 1000000000
2 3 1000000000
1 4 1000000000
2 4 1000000000
3 4 1000000000
1 5 1000000000
2 5 1000000000
3 5 1000000000
4 5 1000000000
1 6 1000000000
2 6 1000000000
3 6 1000000000
4 6 1000000000
5 6 1000000000
1 7 1000000000
2 7 1000000000
3 7 1000000000
4 7 ...

output:

999999999
446000000000
732256441
999999680
999899999
999966830
127
4
2186
1562
1176
5100
5
503
679
4

result:

ok 16 numbers

Test #3:

score: 0
Accepted
time: 303ms
memory: 22232kb

input:

5
1000000000 100000
158260500 877914550 822889311
24979400 861648750 548830120
433933400 476190600 342858071
211047200 971407750 480845266
731963950 822804750 449656269
430302150 982631900 545923679
880895700 923078500 816372580
189330700 910286900 135599877
303238500 404539650 605997004
492686550 7...

output:

999999999
999999999
999999999
999999999
999999999

result:

ok 5 number(s): "999999999 999999999 999999999 999999999 999999999"

Test #4:

score: 0
Accepted
time: 284ms
memory: 21252kb

input:

5
2000 100000
1873 1874 822889311
1290 1291 548830120
1162 1163 342858071
814 815 480845266
742 743 449656269
1609 1610 545923679
1431 1432 816372580
1143 1144 135599877
414 415 605997004
1117 1118 921749002
121 122 786119025
1672 1673 655702582
38 39 211428413
1639 1640 393671555
922 923 501983447
...

output:

4097
20020
198635
2099999
1000099999

result:

ok 5 number(s): "4097 20020 198635 2099999 1000099999"

Test #5:

score: 0
Accepted
time: 236ms
memory: 17412kb

input:

5
100000 100000
36426 60522 446755913
60522 90081 181424399
3497 60522 625711486
60522 94325 647639160
60522 68417 160714711
35902 60522 61020590
23857 60522 626006012
29211 60522 547865075
60522 63340 561330066
60016 60522 650693494
24593 60522 849028504
60522 90310 285323416
11431 60522 990607689
...

output:

100024
150003
200003
250000
999999999

result:

ok 5 number(s): "100024 150003 200003 250000 999999999"

Test #6:

score: 0
Accepted
time: 224ms
memory: 15560kb

input:

5
4000 100000
694 696 619136615
1611 1614 829153748
2551 2552 370724298
3034 3037 49559541
98 105 443754249
822 827 735959328
878 885 201346483
2729 2731 304071225
3961 3965 557890416
1631 1637 430215474
3195 3205 212882505
503 507 937363346
3141 3150 47574456
577 583 727402691
3673 3675 279029853
3...

output:

43935
6913
4336
18350
12678

result:

ok 5 number(s): "43935 6913 4336 18350 12678"

Test #7:

score: 0
Accepted
time: 314ms
memory: 19532kb

input:

5
100000 100000
73979 73980 5250107
1946 1947 757506029
87433 87434 443673136
64352 64354 338125488
69103 69104 235256717
60843 60845 20769731
23601 23602 214534313
92417 92419 669411181
57364 57365 519766962
42029 42031 827237806
98524 98525 593643533
71482 71483 662414293
6709 6710 745687608
36460...

output:

166767
127085
110197
1000033410
1000009975

result:

ok 5 number(s): "166767 127085 110197 1000033410 1000009975"

Test #8:

score: 0
Accepted
time: 132ms
memory: 15432kb

input:

5
1000000000 50000
46934929 214668318 1
539508531 807854772 3
81957905 439197851 0
259767671 917896915 1
415730678 521821941 0
728421737 764345460 2
266428928 403328188 2
287022349 739465773 2
374255863 866291129 2
260858097 908362294 1
413843056 908357026 3
498835884 656136616 4
294506717 617875204...

output:

999989920
999949999
999990020
999949999
999991707

result:

ok 5 number(s): "999989920 999949999 999990020 999949999 999991707"

Test #9:

score: 0
Accepted
time: 262ms
memory: 12460kb

input:

10
318 50000
202 215 664792164
27 240 237398902
211 303 234481289
30 100 677362025
22 264 146815592
119 291 400424695
259 315 252405962
216 247 5088627
157 290 178189323
155 316 734981880
193 247 88649525
111 284 566532841
131 228 543880192
35 295 517550073
11 162 662675576
222 260 74089536
317 318 ...

output:

23819960
39448612
8097046
59114094
45057369
51858561
4062351
79061552
43095015
16693179

result:

ok 10 numbers

Test #10:

score: 0
Accepted
time: 185ms
memory: 11884kb

input:

100
102 5000
48 70 8432902
25 75 334675824
56 84 328506917
62 66 204777391
14 27 171625816
26 63 83629619
57 101 321540985
41 85 311469363
15 66 351390467
25 26 211230409
35 74 290758638
11 52 127872342
29 41 36722590
7 40 305168650
57 59 281651751
13 19 227794663
11 68 263248839
11 13 201312984
4 3...

output:

26178167
22787545
57728222
59428785
9611076
18313917
46857052
2980349
14019519
7766478
32126352
23015186
24398047
5999746
38936614
16904414
35847382
20532753
4984654
19717352
5263678
25996814
15710632
604534
14654144
6955086
27641478
3343419
23105160
26432195
5553390
7056453
53902303
169550500
23592...

result:

ok 100 numbers

Test #11:

score: 0
Accepted
time: 152ms
memory: 11836kb

input:

500
50 1000
30 37 244841531
34 50 162121748
2 24 54057560
13 25 99874751
6 23 8670341
34 39 89926367
1 22 221235953
6 24 105286564
13 34 326397341
3 46 290792604
11 24 346530259
28 36 211580979
3 9 238363354
11 28 280948971
6 36 179816637
18 32 156586941
20 23 98299400
12 50 111363373
22 26 11434081...

output:

189
220
230
182
158
173
200
220
189
164
176
202
142
198
172
239
197
192
183
162
157
250
152
216
243
164
196
189
201
180
183
210
191
202
191
184
178
181
228
210
192
204
219
200
198
215
224
202
143
182
223
186
187
196
218
179
209
178
177
184
182
223
227
199
182
220
208
203
165
205
187
191
201
188
197
...

result:

ok 500 numbers

Test #12:

score: 0
Accepted
time: 138ms
memory: 11840kb

input:

5000
16 100
7 11 287768961
9 16 301149044
4 6 274782222
9 10 450284038
4 7 235183489
2 16 58894948
2 7 238261638
1 15 4511525
4 14 199094011
9 15 18708487
10 14 424492139
5 12 289396677
6 10 205753555
14 16 379921511
9 14 361051609
8 11 462083923
12 16 49451818
7 13 207151488
9 11 468320084
7 9 4016...

output:

84
71179265
61
63
4255393
72
25533862
58
87249761
71
84
19481903
71
46709478
822790
10042255
24930386
63
69894
58
48150185
862500
224220
42138089
740049
8599540
58154641
67865973
14516424
70
87090761
67494787
13034240
91
5581460
331588
67
9506689
80
34867161
43217292
75264458
56
1335841
22470126
266...

result:

ok 5000 numbers

Test #13:

score: 0
Accepted
time: 159ms
memory: 11832kb

input:

5000
2000 100
268 269 623604670
964 965 850016410
1696 1697 958745313
1507 1508 723608729
970 971 753143786
1384 1385 247122568
1448 1449 877299742
1096 1097 795129348
1042 1043 221000653
357 358 298701522
1767 1768 316413195
515 516 229633720
1682 1683 901777899
1181 1182 693437267
1960 1961 867110...

output:

2099
10099
100099
2000099
1000000099
2099
10099
100099
2000099
1000000099
2099
10099
100099
2000099
1000000099
2099
10099
100099
2000099
1000000099
2099
10099
100099
2000099
1000000099
2099
10099
100099
2000099
1000000099
2099
10099
100099
2000099
1000000099
2099
10099
100099
2000099
1000000099
2099...

result:

ok 5000 numbers

Extra Test:

score: -3
Extra Test Failed : Wrong Answer on 1
time: 287ms
memory: 18640kb

input:

1
100000 99998
1 2 1000000000
1 3 1000000000
1 4 1000000000
1 5 1000000000
1 6 1000000000
1 7 1000000000
1 8 1000000000
1 9 1000000000
1 10 1000000000
1 11 1000000000
1 12 1000000000
1 13 1000000000
1 14 1000000000
1 15 1000000000
1 16 1000000000
1 17 1000000000
1 18 1000000000
1 19 1000000000
1 20 ...

output:

1000099998

result:

wrong answer 1st numbers differ - expected: '199997', found: '1000099998'