# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
211416 |
2020-03-20T10:13:16 Z |
VEGAnn |
Bridges (APIO19_bridges) |
C++14 |
|
2698 ms |
25084 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 = 1300;
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 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 mem = sz(stk);
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) > mem){
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 |
8 ms |
6272 KB |
Output is correct |
2 |
Correct |
8 ms |
6248 KB |
Output is correct |
3 |
Correct |
41 ms |
13304 KB |
Output is correct |
4 |
Correct |
15 ms |
6528 KB |
Output is correct |
5 |
Correct |
21 ms |
12288 KB |
Output is correct |
6 |
Correct |
18 ms |
12288 KB |
Output is correct |
7 |
Correct |
28 ms |
12280 KB |
Output is correct |
8 |
Correct |
23 ms |
12288 KB |
Output is correct |
9 |
Correct |
25 ms |
12288 KB |
Output is correct |
10 |
Correct |
23 ms |
12288 KB |
Output is correct |
11 |
Correct |
23 ms |
12288 KB |
Output is correct |
12 |
Correct |
25 ms |
12288 KB |
Output is correct |
13 |
Correct |
29 ms |
12608 KB |
Output is correct |
14 |
Correct |
31 ms |
12544 KB |
Output is correct |
15 |
Correct |
24 ms |
12288 KB |
Output is correct |
16 |
Correct |
22 ms |
12288 KB |
Output is correct |
17 |
Correct |
22 ms |
12288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1751 ms |
21776 KB |
Output is correct |
2 |
Correct |
1690 ms |
21836 KB |
Output is correct |
3 |
Correct |
1642 ms |
21812 KB |
Output is correct |
4 |
Correct |
1757 ms |
21764 KB |
Output is correct |
5 |
Correct |
1756 ms |
21796 KB |
Output is correct |
6 |
Correct |
2481 ms |
22008 KB |
Output is correct |
7 |
Correct |
2449 ms |
22040 KB |
Output is correct |
8 |
Correct |
2441 ms |
21944 KB |
Output is correct |
9 |
Correct |
87 ms |
8564 KB |
Output is correct |
10 |
Correct |
1227 ms |
19284 KB |
Output is correct |
11 |
Correct |
1113 ms |
19008 KB |
Output is correct |
12 |
Correct |
1194 ms |
20464 KB |
Output is correct |
13 |
Correct |
1547 ms |
22968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1406 ms |
19964 KB |
Output is correct |
2 |
Correct |
1058 ms |
17424 KB |
Output is correct |
3 |
Correct |
1624 ms |
20168 KB |
Output is correct |
4 |
Correct |
1342 ms |
19900 KB |
Output is correct |
5 |
Correct |
89 ms |
8524 KB |
Output is correct |
6 |
Correct |
1578 ms |
19988 KB |
Output is correct |
7 |
Correct |
1216 ms |
20076 KB |
Output is correct |
8 |
Correct |
1067 ms |
20148 KB |
Output is correct |
9 |
Correct |
824 ms |
18284 KB |
Output is correct |
10 |
Correct |
728 ms |
18284 KB |
Output is correct |
11 |
Correct |
1018 ms |
20932 KB |
Output is correct |
12 |
Correct |
915 ms |
20980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1594 ms |
16580 KB |
Output is correct |
2 |
Correct |
100 ms |
8560 KB |
Output is correct |
3 |
Correct |
152 ms |
12144 KB |
Output is correct |
4 |
Correct |
77 ms |
9712 KB |
Output is correct |
5 |
Correct |
487 ms |
13928 KB |
Output is correct |
6 |
Correct |
1503 ms |
16252 KB |
Output is correct |
7 |
Correct |
475 ms |
13804 KB |
Output is correct |
8 |
Correct |
698 ms |
13396 KB |
Output is correct |
9 |
Correct |
799 ms |
13520 KB |
Output is correct |
10 |
Correct |
598 ms |
13544 KB |
Output is correct |
11 |
Correct |
1220 ms |
14624 KB |
Output is correct |
12 |
Correct |
1236 ms |
14624 KB |
Output is correct |
13 |
Correct |
969 ms |
14800 KB |
Output is correct |
14 |
Correct |
466 ms |
13916 KB |
Output is correct |
15 |
Correct |
476 ms |
13928 KB |
Output is correct |
16 |
Correct |
1592 ms |
16220 KB |
Output is correct |
17 |
Correct |
1606 ms |
15876 KB |
Output is correct |
18 |
Correct |
1584 ms |
16108 KB |
Output is correct |
19 |
Correct |
1573 ms |
15840 KB |
Output is correct |
20 |
Correct |
1039 ms |
15352 KB |
Output is correct |
21 |
Correct |
1059 ms |
15356 KB |
Output is correct |
22 |
Correct |
1396 ms |
15992 KB |
Output is correct |
23 |
Correct |
456 ms |
13024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1751 ms |
21776 KB |
Output is correct |
2 |
Correct |
1690 ms |
21836 KB |
Output is correct |
3 |
Correct |
1642 ms |
21812 KB |
Output is correct |
4 |
Correct |
1757 ms |
21764 KB |
Output is correct |
5 |
Correct |
1756 ms |
21796 KB |
Output is correct |
6 |
Correct |
2481 ms |
22008 KB |
Output is correct |
7 |
Correct |
2449 ms |
22040 KB |
Output is correct |
8 |
Correct |
2441 ms |
21944 KB |
Output is correct |
9 |
Correct |
87 ms |
8564 KB |
Output is correct |
10 |
Correct |
1227 ms |
19284 KB |
Output is correct |
11 |
Correct |
1113 ms |
19008 KB |
Output is correct |
12 |
Correct |
1194 ms |
20464 KB |
Output is correct |
13 |
Correct |
1547 ms |
22968 KB |
Output is correct |
14 |
Correct |
1406 ms |
19964 KB |
Output is correct |
15 |
Correct |
1058 ms |
17424 KB |
Output is correct |
16 |
Correct |
1624 ms |
20168 KB |
Output is correct |
17 |
Correct |
1342 ms |
19900 KB |
Output is correct |
18 |
Correct |
89 ms |
8524 KB |
Output is correct |
19 |
Correct |
1578 ms |
19988 KB |
Output is correct |
20 |
Correct |
1216 ms |
20076 KB |
Output is correct |
21 |
Correct |
1067 ms |
20148 KB |
Output is correct |
22 |
Correct |
824 ms |
18284 KB |
Output is correct |
23 |
Correct |
728 ms |
18284 KB |
Output is correct |
24 |
Correct |
1018 ms |
20932 KB |
Output is correct |
25 |
Correct |
915 ms |
20980 KB |
Output is correct |
26 |
Correct |
1748 ms |
21840 KB |
Output is correct |
27 |
Correct |
2189 ms |
22120 KB |
Output is correct |
28 |
Correct |
1868 ms |
21980 KB |
Output is correct |
29 |
Correct |
1263 ms |
21752 KB |
Output is correct |
30 |
Correct |
2070 ms |
21904 KB |
Output is correct |
31 |
Correct |
1963 ms |
22096 KB |
Output is correct |
32 |
Correct |
1983 ms |
22188 KB |
Output is correct |
33 |
Correct |
1709 ms |
21764 KB |
Output is correct |
34 |
Correct |
1772 ms |
21680 KB |
Output is correct |
35 |
Correct |
1776 ms |
21752 KB |
Output is correct |
36 |
Correct |
1389 ms |
21732 KB |
Output is correct |
37 |
Correct |
1328 ms |
21752 KB |
Output is correct |
38 |
Correct |
1354 ms |
21736 KB |
Output is correct |
39 |
Correct |
989 ms |
20076 KB |
Output is correct |
40 |
Correct |
948 ms |
20040 KB |
Output is correct |
41 |
Correct |
971 ms |
20076 KB |
Output is correct |
42 |
Correct |
1178 ms |
22756 KB |
Output is correct |
43 |
Correct |
1152 ms |
22880 KB |
Output is correct |
44 |
Correct |
1132 ms |
22868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
6272 KB |
Output is correct |
2 |
Correct |
8 ms |
6248 KB |
Output is correct |
3 |
Correct |
41 ms |
13304 KB |
Output is correct |
4 |
Correct |
15 ms |
6528 KB |
Output is correct |
5 |
Correct |
21 ms |
12288 KB |
Output is correct |
6 |
Correct |
18 ms |
12288 KB |
Output is correct |
7 |
Correct |
28 ms |
12280 KB |
Output is correct |
8 |
Correct |
23 ms |
12288 KB |
Output is correct |
9 |
Correct |
25 ms |
12288 KB |
Output is correct |
10 |
Correct |
23 ms |
12288 KB |
Output is correct |
11 |
Correct |
23 ms |
12288 KB |
Output is correct |
12 |
Correct |
25 ms |
12288 KB |
Output is correct |
13 |
Correct |
29 ms |
12608 KB |
Output is correct |
14 |
Correct |
31 ms |
12544 KB |
Output is correct |
15 |
Correct |
24 ms |
12288 KB |
Output is correct |
16 |
Correct |
22 ms |
12288 KB |
Output is correct |
17 |
Correct |
22 ms |
12288 KB |
Output is correct |
18 |
Correct |
1751 ms |
21776 KB |
Output is correct |
19 |
Correct |
1690 ms |
21836 KB |
Output is correct |
20 |
Correct |
1642 ms |
21812 KB |
Output is correct |
21 |
Correct |
1757 ms |
21764 KB |
Output is correct |
22 |
Correct |
1756 ms |
21796 KB |
Output is correct |
23 |
Correct |
2481 ms |
22008 KB |
Output is correct |
24 |
Correct |
2449 ms |
22040 KB |
Output is correct |
25 |
Correct |
2441 ms |
21944 KB |
Output is correct |
26 |
Correct |
87 ms |
8564 KB |
Output is correct |
27 |
Correct |
1227 ms |
19284 KB |
Output is correct |
28 |
Correct |
1113 ms |
19008 KB |
Output is correct |
29 |
Correct |
1194 ms |
20464 KB |
Output is correct |
30 |
Correct |
1547 ms |
22968 KB |
Output is correct |
31 |
Correct |
1406 ms |
19964 KB |
Output is correct |
32 |
Correct |
1058 ms |
17424 KB |
Output is correct |
33 |
Correct |
1624 ms |
20168 KB |
Output is correct |
34 |
Correct |
1342 ms |
19900 KB |
Output is correct |
35 |
Correct |
89 ms |
8524 KB |
Output is correct |
36 |
Correct |
1578 ms |
19988 KB |
Output is correct |
37 |
Correct |
1216 ms |
20076 KB |
Output is correct |
38 |
Correct |
1067 ms |
20148 KB |
Output is correct |
39 |
Correct |
824 ms |
18284 KB |
Output is correct |
40 |
Correct |
728 ms |
18284 KB |
Output is correct |
41 |
Correct |
1018 ms |
20932 KB |
Output is correct |
42 |
Correct |
915 ms |
20980 KB |
Output is correct |
43 |
Correct |
1594 ms |
16580 KB |
Output is correct |
44 |
Correct |
100 ms |
8560 KB |
Output is correct |
45 |
Correct |
152 ms |
12144 KB |
Output is correct |
46 |
Correct |
77 ms |
9712 KB |
Output is correct |
47 |
Correct |
487 ms |
13928 KB |
Output is correct |
48 |
Correct |
1503 ms |
16252 KB |
Output is correct |
49 |
Correct |
475 ms |
13804 KB |
Output is correct |
50 |
Correct |
698 ms |
13396 KB |
Output is correct |
51 |
Correct |
799 ms |
13520 KB |
Output is correct |
52 |
Correct |
598 ms |
13544 KB |
Output is correct |
53 |
Correct |
1220 ms |
14624 KB |
Output is correct |
54 |
Correct |
1236 ms |
14624 KB |
Output is correct |
55 |
Correct |
969 ms |
14800 KB |
Output is correct |
56 |
Correct |
466 ms |
13916 KB |
Output is correct |
57 |
Correct |
476 ms |
13928 KB |
Output is correct |
58 |
Correct |
1592 ms |
16220 KB |
Output is correct |
59 |
Correct |
1606 ms |
15876 KB |
Output is correct |
60 |
Correct |
1584 ms |
16108 KB |
Output is correct |
61 |
Correct |
1573 ms |
15840 KB |
Output is correct |
62 |
Correct |
1039 ms |
15352 KB |
Output is correct |
63 |
Correct |
1059 ms |
15356 KB |
Output is correct |
64 |
Correct |
1396 ms |
15992 KB |
Output is correct |
65 |
Correct |
456 ms |
13024 KB |
Output is correct |
66 |
Correct |
1748 ms |
21840 KB |
Output is correct |
67 |
Correct |
2189 ms |
22120 KB |
Output is correct |
68 |
Correct |
1868 ms |
21980 KB |
Output is correct |
69 |
Correct |
1263 ms |
21752 KB |
Output is correct |
70 |
Correct |
2070 ms |
21904 KB |
Output is correct |
71 |
Correct |
1963 ms |
22096 KB |
Output is correct |
72 |
Correct |
1983 ms |
22188 KB |
Output is correct |
73 |
Correct |
1709 ms |
21764 KB |
Output is correct |
74 |
Correct |
1772 ms |
21680 KB |
Output is correct |
75 |
Correct |
1776 ms |
21752 KB |
Output is correct |
76 |
Correct |
1389 ms |
21732 KB |
Output is correct |
77 |
Correct |
1328 ms |
21752 KB |
Output is correct |
78 |
Correct |
1354 ms |
21736 KB |
Output is correct |
79 |
Correct |
989 ms |
20076 KB |
Output is correct |
80 |
Correct |
948 ms |
20040 KB |
Output is correct |
81 |
Correct |
971 ms |
20076 KB |
Output is correct |
82 |
Correct |
1178 ms |
22756 KB |
Output is correct |
83 |
Correct |
1152 ms |
22880 KB |
Output is correct |
84 |
Correct |
1132 ms |
22868 KB |
Output is correct |
85 |
Correct |
2359 ms |
25084 KB |
Output is correct |
86 |
Correct |
203 ms |
19568 KB |
Output is correct |
87 |
Correct |
136 ms |
17136 KB |
Output is correct |
88 |
Correct |
1076 ms |
21036 KB |
Output is correct |
89 |
Correct |
2319 ms |
24916 KB |
Output is correct |
90 |
Correct |
1070 ms |
20716 KB |
Output is correct |
91 |
Correct |
1858 ms |
21740 KB |
Output is correct |
92 |
Correct |
1869 ms |
21696 KB |
Output is correct |
93 |
Correct |
2651 ms |
21772 KB |
Output is correct |
94 |
Correct |
2102 ms |
23184 KB |
Output is correct |
95 |
Correct |
2088 ms |
23136 KB |
Output is correct |
96 |
Correct |
2516 ms |
23024 KB |
Output is correct |
97 |
Correct |
663 ms |
20204 KB |
Output is correct |
98 |
Correct |
853 ms |
20332 KB |
Output is correct |
99 |
Correct |
2460 ms |
24676 KB |
Output is correct |
100 |
Correct |
2447 ms |
24596 KB |
Output is correct |
101 |
Correct |
2470 ms |
24712 KB |
Output is correct |
102 |
Correct |
2413 ms |
24556 KB |
Output is correct |
103 |
Correct |
2698 ms |
23624 KB |
Output is correct |
104 |
Correct |
2693 ms |
23500 KB |
Output is correct |
105 |
Correct |
2067 ms |
24540 KB |
Output is correct |
106 |
Correct |
1700 ms |
24240 KB |
Output is correct |
107 |
Correct |
1425 ms |
21924 KB |
Output is correct |
108 |
Correct |
2445 ms |
24064 KB |
Output is correct |
109 |
Correct |
1414 ms |
19648 KB |
Output is correct |