# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
211436 |
2020-03-20T10:38:17 Z |
VEGAnn |
Bridges (APIO19_bridges) |
C++14 |
|
3000 ms |
26584 KB |
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define pll pair<ll, ll>
#define MP make_pair
#define PB push_back
#define pii pair<int, int>
#define pi3 pair<pii, int>
#define ft first
#define sd second
#define MP3(a,b,c) MP(MP(a,b),c)
using namespace std;
typedef long long ll;
const int N = 50100;
const int M = 100100;
const int Q = 100100;
const int CO = 200100;
const int oo = 2e9;
const int B = 1500;
const int MB = M / B + 10;
stack<pi3> stk;
vector<int> g[N], vc, ed[CO], vec, qr;
int n, m, U[M], V[M], D[M], q, ans[Q], tt = 0, mrk[M], loc[M];
int vls[B][B], tp[Q], l[Q], r[Q], siz[N], pr[N];
bool cmp(int x, int y){
return r[x] > r[y];
}
int Get(int x){ return (x == pr[x] ? x : Get(pr[x])); }
void Link(int x, int y){
x = Get(x);
y = Get(y);
if (x == y) return;
if (siz[x] < siz[y]) swap(x, y);
stk.push(MP3(x, y, pr[y]));
pr[y] = x;
siz[x] += siz[y];
}
int get(int x){ return (x == pr[x] ? x : pr[x] = get(pr[x]));}
void link(int x, int y){
x = get(x);
y = get(y);
if (x == y) return;
if (siz[x] < siz[y]) swap(x, y);
pr[y] = x;
siz[x] += siz[y];
}
int main(){
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#else
ios_base::sync_with_stdio(0); cin.tie(0);
#endif // _LOCAL
cin >> n >> m;
for (int i = 0; i < m; i++){
cin >> U[i] >> V[i] >> D[i];
U[i]--; V[i]--;
g[U[i]].PB(i);
g[V[i]].PB(i);
vc.PB(D[i]);
}
cin >> q;
for (int i = 0; i < q; i++) {
cin >> tp[i] >> l[i] >> r[i];
l[i]--;
vc.PB(r[i]);
}
sort(all(vc));
vc.resize(unique(all(vc)) - vc.begin());
for (int i = 0; i < m; i++)
D[i] = lower_bound(all(vc), D[i]) - vc.begin();
for (int i = 0; i < q; i++)
r[i] = lower_bound(all(vc), r[i]) - vc.begin();
for (int it = 0; it < q; it += B){
int bd = min(q, it + B);
tt++;
vec.clear();
qr.clear();
for (int i = it; i < bd; i++)
if (tp[i] == 1) {
if (mrk[l[i]] < tt) {
mrk[l[i]] = tt;
loc[l[i]] = sz(vec);
vec.PB(l[i]);
}
} else qr.PB(i);
for (int i = it; i < bd; i++){
int nm = i - it;
if (i == it){
for (int j = 0; j < sz(vec); j++)
vls[nm][j] = D[vec[j]];
} else {
for (int j = 0; j < sz(vec); j++)
vls[nm][j] = vls[nm - 1][j];
}
if (tp[i] == 1)
vls[nm][loc[l[i]]] = r[i];
}
for (int i = 0; i < m; i++)
if (mrk[i] < tt)
ed[D[i]].PB(i);
for (int i = 0; i < n; i++){
siz[i] = 1;
pr[i] = i;
}
if (sz(qr)){
sort(all(qr), cmp);
}
while (sz(stk)) stk.pop();
int lst = sz(vc) - 1;
for (int nm : qr){
while (lst >= 0 && lst >= r[nm]){
if (sz(ed[lst])){
for (int nw : ed[lst])
link(U[nw], V[nw]);
ed[lst].clear();
}
lst--;
}
int gt = nm - it;
for (int i = 0; i < sz(vec); i++)
if (vls[gt][i] >= r[nm])
Link(U[vec[i]], V[vec[i]]);
ans[nm] = siz[Get(l[nm])];
while (sz(stk) > 0){
pi3 cr = stk.top();
stk.pop();
siz[cr.ft.ft] -= siz[cr.ft.sd];
pr[cr.ft.sd] = cr.sd;
}
}
while (lst >= 0){
ed[lst].clear();
lst--;
}
//end
for (int i = 0; i < sz(vec); i++)
D[vec[i]] = vls[bd - it - 1][i];
}
for (int i = 0; i < q; i++)
if (tp[i] == 2)
cout << ans[i] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
6272 KB |
Output is correct |
2 |
Correct |
11 ms |
6272 KB |
Output is correct |
3 |
Correct |
51 ms |
15392 KB |
Output is correct |
4 |
Correct |
16 ms |
6528 KB |
Output is correct |
5 |
Correct |
23 ms |
13056 KB |
Output is correct |
6 |
Correct |
26 ms |
13056 KB |
Output is correct |
7 |
Correct |
25 ms |
13184 KB |
Output is correct |
8 |
Correct |
24 ms |
13184 KB |
Output is correct |
9 |
Correct |
24 ms |
13184 KB |
Output is correct |
10 |
Correct |
25 ms |
13184 KB |
Output is correct |
11 |
Correct |
25 ms |
13184 KB |
Output is correct |
12 |
Correct |
27 ms |
13184 KB |
Output is correct |
13 |
Correct |
79 ms |
13440 KB |
Output is correct |
14 |
Correct |
29 ms |
13440 KB |
Output is correct |
15 |
Correct |
27 ms |
13184 KB |
Output is correct |
16 |
Correct |
23 ms |
13184 KB |
Output is correct |
17 |
Correct |
23 ms |
13184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1734 ms |
23368 KB |
Output is correct |
2 |
Correct |
1687 ms |
23364 KB |
Output is correct |
3 |
Correct |
1673 ms |
23584 KB |
Output is correct |
4 |
Correct |
1747 ms |
23404 KB |
Output is correct |
5 |
Correct |
1761 ms |
23304 KB |
Output is correct |
6 |
Correct |
2588 ms |
23676 KB |
Output is correct |
7 |
Correct |
2563 ms |
23504 KB |
Output is correct |
8 |
Correct |
2594 ms |
23636 KB |
Output is correct |
9 |
Correct |
89 ms |
8564 KB |
Output is correct |
10 |
Correct |
1366 ms |
20688 KB |
Output is correct |
11 |
Correct |
1243 ms |
20760 KB |
Output is correct |
12 |
Correct |
1183 ms |
20752 KB |
Output is correct |
13 |
Correct |
1541 ms |
24372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1428 ms |
21668 KB |
Output is correct |
2 |
Correct |
1163 ms |
19328 KB |
Output is correct |
3 |
Correct |
1656 ms |
22080 KB |
Output is correct |
4 |
Correct |
1413 ms |
21740 KB |
Output is correct |
5 |
Correct |
79 ms |
8564 KB |
Output is correct |
6 |
Correct |
1593 ms |
21788 KB |
Output is correct |
7 |
Correct |
1290 ms |
21672 KB |
Output is correct |
8 |
Correct |
1120 ms |
21868 KB |
Output is correct |
9 |
Correct |
835 ms |
18984 KB |
Output is correct |
10 |
Correct |
711 ms |
18920 KB |
Output is correct |
11 |
Correct |
1014 ms |
22732 KB |
Output is correct |
12 |
Correct |
876 ms |
22764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1403 ms |
16028 KB |
Output is correct |
2 |
Correct |
81 ms |
8564 KB |
Output is correct |
3 |
Correct |
158 ms |
12140 KB |
Output is correct |
4 |
Correct |
64 ms |
9712 KB |
Output is correct |
5 |
Correct |
308 ms |
13340 KB |
Output is correct |
6 |
Correct |
1361 ms |
15560 KB |
Output is correct |
7 |
Correct |
321 ms |
13420 KB |
Output is correct |
8 |
Correct |
604 ms |
12808 KB |
Output is correct |
9 |
Correct |
570 ms |
12780 KB |
Output is correct |
10 |
Correct |
461 ms |
13164 KB |
Output is correct |
11 |
Correct |
989 ms |
13908 KB |
Output is correct |
12 |
Correct |
974 ms |
13996 KB |
Output is correct |
13 |
Correct |
904 ms |
14116 KB |
Output is correct |
14 |
Correct |
321 ms |
13628 KB |
Output is correct |
15 |
Correct |
302 ms |
13600 KB |
Output is correct |
16 |
Correct |
1419 ms |
15228 KB |
Output is correct |
17 |
Correct |
1427 ms |
15244 KB |
Output is correct |
18 |
Correct |
1560 ms |
15312 KB |
Output is correct |
19 |
Correct |
1477 ms |
15312 KB |
Output is correct |
20 |
Correct |
1016 ms |
14700 KB |
Output is correct |
21 |
Correct |
1002 ms |
14628 KB |
Output is correct |
22 |
Correct |
1376 ms |
15128 KB |
Output is correct |
23 |
Correct |
375 ms |
12400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1734 ms |
23368 KB |
Output is correct |
2 |
Correct |
1687 ms |
23364 KB |
Output is correct |
3 |
Correct |
1673 ms |
23584 KB |
Output is correct |
4 |
Correct |
1747 ms |
23404 KB |
Output is correct |
5 |
Correct |
1761 ms |
23304 KB |
Output is correct |
6 |
Correct |
2588 ms |
23676 KB |
Output is correct |
7 |
Correct |
2563 ms |
23504 KB |
Output is correct |
8 |
Correct |
2594 ms |
23636 KB |
Output is correct |
9 |
Correct |
89 ms |
8564 KB |
Output is correct |
10 |
Correct |
1366 ms |
20688 KB |
Output is correct |
11 |
Correct |
1243 ms |
20760 KB |
Output is correct |
12 |
Correct |
1183 ms |
20752 KB |
Output is correct |
13 |
Correct |
1541 ms |
24372 KB |
Output is correct |
14 |
Correct |
1428 ms |
21668 KB |
Output is correct |
15 |
Correct |
1163 ms |
19328 KB |
Output is correct |
16 |
Correct |
1656 ms |
22080 KB |
Output is correct |
17 |
Correct |
1413 ms |
21740 KB |
Output is correct |
18 |
Correct |
79 ms |
8564 KB |
Output is correct |
19 |
Correct |
1593 ms |
21788 KB |
Output is correct |
20 |
Correct |
1290 ms |
21672 KB |
Output is correct |
21 |
Correct |
1120 ms |
21868 KB |
Output is correct |
22 |
Correct |
835 ms |
18984 KB |
Output is correct |
23 |
Correct |
711 ms |
18920 KB |
Output is correct |
24 |
Correct |
1014 ms |
22732 KB |
Output is correct |
25 |
Correct |
876 ms |
22764 KB |
Output is correct |
26 |
Correct |
1788 ms |
23444 KB |
Output is correct |
27 |
Correct |
2132 ms |
23524 KB |
Output is correct |
28 |
Correct |
1895 ms |
23428 KB |
Output is correct |
29 |
Correct |
1252 ms |
23336 KB |
Output is correct |
30 |
Correct |
2313 ms |
23452 KB |
Output is correct |
31 |
Correct |
2360 ms |
23356 KB |
Output is correct |
32 |
Correct |
2384 ms |
23456 KB |
Output is correct |
33 |
Correct |
1980 ms |
23452 KB |
Output is correct |
34 |
Correct |
1886 ms |
23348 KB |
Output is correct |
35 |
Correct |
1940 ms |
23380 KB |
Output is correct |
36 |
Correct |
1392 ms |
23244 KB |
Output is correct |
37 |
Correct |
1379 ms |
23324 KB |
Output is correct |
38 |
Correct |
1393 ms |
23264 KB |
Output is correct |
39 |
Correct |
1056 ms |
20452 KB |
Output is correct |
40 |
Correct |
1002 ms |
20516 KB |
Output is correct |
41 |
Correct |
916 ms |
20548 KB |
Output is correct |
42 |
Correct |
1189 ms |
24320 KB |
Output is correct |
43 |
Correct |
1198 ms |
24428 KB |
Output is correct |
44 |
Correct |
1187 ms |
24524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
6272 KB |
Output is correct |
2 |
Correct |
11 ms |
6272 KB |
Output is correct |
3 |
Correct |
51 ms |
15392 KB |
Output is correct |
4 |
Correct |
16 ms |
6528 KB |
Output is correct |
5 |
Correct |
23 ms |
13056 KB |
Output is correct |
6 |
Correct |
26 ms |
13056 KB |
Output is correct |
7 |
Correct |
25 ms |
13184 KB |
Output is correct |
8 |
Correct |
24 ms |
13184 KB |
Output is correct |
9 |
Correct |
24 ms |
13184 KB |
Output is correct |
10 |
Correct |
25 ms |
13184 KB |
Output is correct |
11 |
Correct |
25 ms |
13184 KB |
Output is correct |
12 |
Correct |
27 ms |
13184 KB |
Output is correct |
13 |
Correct |
79 ms |
13440 KB |
Output is correct |
14 |
Correct |
29 ms |
13440 KB |
Output is correct |
15 |
Correct |
27 ms |
13184 KB |
Output is correct |
16 |
Correct |
23 ms |
13184 KB |
Output is correct |
17 |
Correct |
23 ms |
13184 KB |
Output is correct |
18 |
Correct |
1734 ms |
23368 KB |
Output is correct |
19 |
Correct |
1687 ms |
23364 KB |
Output is correct |
20 |
Correct |
1673 ms |
23584 KB |
Output is correct |
21 |
Correct |
1747 ms |
23404 KB |
Output is correct |
22 |
Correct |
1761 ms |
23304 KB |
Output is correct |
23 |
Correct |
2588 ms |
23676 KB |
Output is correct |
24 |
Correct |
2563 ms |
23504 KB |
Output is correct |
25 |
Correct |
2594 ms |
23636 KB |
Output is correct |
26 |
Correct |
89 ms |
8564 KB |
Output is correct |
27 |
Correct |
1366 ms |
20688 KB |
Output is correct |
28 |
Correct |
1243 ms |
20760 KB |
Output is correct |
29 |
Correct |
1183 ms |
20752 KB |
Output is correct |
30 |
Correct |
1541 ms |
24372 KB |
Output is correct |
31 |
Correct |
1428 ms |
21668 KB |
Output is correct |
32 |
Correct |
1163 ms |
19328 KB |
Output is correct |
33 |
Correct |
1656 ms |
22080 KB |
Output is correct |
34 |
Correct |
1413 ms |
21740 KB |
Output is correct |
35 |
Correct |
79 ms |
8564 KB |
Output is correct |
36 |
Correct |
1593 ms |
21788 KB |
Output is correct |
37 |
Correct |
1290 ms |
21672 KB |
Output is correct |
38 |
Correct |
1120 ms |
21868 KB |
Output is correct |
39 |
Correct |
835 ms |
18984 KB |
Output is correct |
40 |
Correct |
711 ms |
18920 KB |
Output is correct |
41 |
Correct |
1014 ms |
22732 KB |
Output is correct |
42 |
Correct |
876 ms |
22764 KB |
Output is correct |
43 |
Correct |
1403 ms |
16028 KB |
Output is correct |
44 |
Correct |
81 ms |
8564 KB |
Output is correct |
45 |
Correct |
158 ms |
12140 KB |
Output is correct |
46 |
Correct |
64 ms |
9712 KB |
Output is correct |
47 |
Correct |
308 ms |
13340 KB |
Output is correct |
48 |
Correct |
1361 ms |
15560 KB |
Output is correct |
49 |
Correct |
321 ms |
13420 KB |
Output is correct |
50 |
Correct |
604 ms |
12808 KB |
Output is correct |
51 |
Correct |
570 ms |
12780 KB |
Output is correct |
52 |
Correct |
461 ms |
13164 KB |
Output is correct |
53 |
Correct |
989 ms |
13908 KB |
Output is correct |
54 |
Correct |
974 ms |
13996 KB |
Output is correct |
55 |
Correct |
904 ms |
14116 KB |
Output is correct |
56 |
Correct |
321 ms |
13628 KB |
Output is correct |
57 |
Correct |
302 ms |
13600 KB |
Output is correct |
58 |
Correct |
1419 ms |
15228 KB |
Output is correct |
59 |
Correct |
1427 ms |
15244 KB |
Output is correct |
60 |
Correct |
1560 ms |
15312 KB |
Output is correct |
61 |
Correct |
1477 ms |
15312 KB |
Output is correct |
62 |
Correct |
1016 ms |
14700 KB |
Output is correct |
63 |
Correct |
1002 ms |
14628 KB |
Output is correct |
64 |
Correct |
1376 ms |
15128 KB |
Output is correct |
65 |
Correct |
375 ms |
12400 KB |
Output is correct |
66 |
Correct |
1788 ms |
23444 KB |
Output is correct |
67 |
Correct |
2132 ms |
23524 KB |
Output is correct |
68 |
Correct |
1895 ms |
23428 KB |
Output is correct |
69 |
Correct |
1252 ms |
23336 KB |
Output is correct |
70 |
Correct |
2313 ms |
23452 KB |
Output is correct |
71 |
Correct |
2360 ms |
23356 KB |
Output is correct |
72 |
Correct |
2384 ms |
23456 KB |
Output is correct |
73 |
Correct |
1980 ms |
23452 KB |
Output is correct |
74 |
Correct |
1886 ms |
23348 KB |
Output is correct |
75 |
Correct |
1940 ms |
23380 KB |
Output is correct |
76 |
Correct |
1392 ms |
23244 KB |
Output is correct |
77 |
Correct |
1379 ms |
23324 KB |
Output is correct |
78 |
Correct |
1393 ms |
23264 KB |
Output is correct |
79 |
Correct |
1056 ms |
20452 KB |
Output is correct |
80 |
Correct |
1002 ms |
20516 KB |
Output is correct |
81 |
Correct |
916 ms |
20548 KB |
Output is correct |
82 |
Correct |
1189 ms |
24320 KB |
Output is correct |
83 |
Correct |
1198 ms |
24428 KB |
Output is correct |
84 |
Correct |
1187 ms |
24524 KB |
Output is correct |
85 |
Correct |
2484 ms |
26420 KB |
Output is correct |
86 |
Correct |
240 ms |
21828 KB |
Output is correct |
87 |
Correct |
124 ms |
19312 KB |
Output is correct |
88 |
Correct |
883 ms |
22732 KB |
Output is correct |
89 |
Correct |
2554 ms |
26584 KB |
Output is correct |
90 |
Correct |
916 ms |
22428 KB |
Output is correct |
91 |
Correct |
2073 ms |
23320 KB |
Output is correct |
92 |
Correct |
2067 ms |
23372 KB |
Output is correct |
93 |
Execution timed out |
3030 ms |
23372 KB |
Time limit exceeded |
94 |
Halted |
0 ms |
0 KB |
- |