QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#218336 | #6330. XOR Reachable | ucup-team963 | Compile Error | / | / | C++14 | 2.9kb | 2023-10-18 01:42:23 | 2023-10-18 01:42:24 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 1e5 + 10, M = 1e5 + 10, Q = 1e5 + 10;
pair<int,int> d[N];
struct { int x, y, w; } e[M];
ll ans[Q], q;
vector<int> opt[Q << 2];
int par[N], siz[N];
ll tans = 0;
vector<pair<int,int>> oprs;
inline int find(int x) { return x == par[x] ? x : find(par[x]); }
inline void merge(int x, int y) {
x = find(x), y = find(y);
if(x == y) return ;
if(siz[x] < siz[y]) swap(x, y);
tans -= 1ll * siz[x] * (siz[x] - 1) / 2;
tans -= 1ll * siz[y] * (siz[y] - 1) / 2;
par[y] = x; siz[x] += siz[y];
tans += 1ll * siz[x] * (siz[x] - 1) / 2;
oprs.pb({y, x});
}
void undo() {
int x = oprs.back().se, y = oprs.back().fi;
par[y] = y;
tans -= 1ll * siz[x] * (siz[x] - 1) / 2;
siz[x] -= siz[y];
tans += 1ll * siz[x] * (siz[x] - 1) / 2;
tans += 1ll * siz[y] * (siz[y] - 1) / 2;
oprs.pop_back();
}
void change(int p, int lp, int rp, int l, int r, int v) {
if(l <= lp && rp <= r) {
opt[p].pb(v);
return ;
}
int mid = (lp + rp) >> 1;
if(l <= mid) change(p << 1, lp, mid, l, r, v);
if(r > mid) change(p << 1 | 1, mid + 1, rp, l, r, v);
}
void add(int l, int r, int c) {
// cout << "addin " << l << ' ' << r << ' ' << c << endl;
int L = lower_bound(d + 1, d + q + 1, make_pair(l, 0)) - d;
int R = lower_bound(d + 1, d + q + 1, make_pair(r, q + 1)) - d;
-- R;
if(R < L) return ;
// cout << "add " << L << ' ' << R << ' ' << c << endl;
change(1, 1, q, L, R, c);
}
void dfs(int p, int lp, int rp) {
// cout << lp << ' ' << rp << endl;
auto ssz = oprs.size();
for(int cid : opt[p]) {
merge(e[cid].x, e[cid].y);
}
if(lp == rp) {
ans[d[lp].se] = tans;
} else {
int mid = (lp + rp) >> 1;
dfs(p << 1, lp, mid);
dfs(p << 1 | 1, mid + 1, rp);
}
while(oprs.size() != ssz) undo();
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
rep(i,1,m)
cin >> e[i].x >> e[i].y >> e[i].w;
cin >> q;
rep(qr,1,q) {
cin >> d[qr].fi;
d[qr].se = qr;
}
sort(d + 1, d + q + 1);
rep(i,1,m) {
int val = 0;
per(dig,29,0) {
int cc = (e[i].w >> dig) & 1, kk = (k >> dig) & 1;
if(kk) {
int v = val | (cc << dig);
add(v, v + (1 << dig) - 1, i);
val |= ((cc ^ 1) << dig);
} else {
val |= cc << dig;
}
}
}
rep(i,1,n) par[i] = i;
rep(i,1,n) siz[i] = 1;
dfs(1, 1, q);
rep(i,1,q) cout << ans[i] << endl;
return 0;
}
詳細信息
In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/istream:38, from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from answer.code:1: /usr/include/c++/11/bits/predefined_ops.h: In instantiation of ‘bool __gnu_cxx::__ops::_Iter_less_val::operator()(_Iterator, _Value&) const [with _Iterator = std::pair<int, int>*; _Value = const std::pair<int, long long int>]’: /usr/include/c++/11/bits/stl_algobase.h:1464:14: required from ‘_ForwardIterator std::__lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = std::pair<int, int>*; _Tp = std::pair<int, long long int>; _Compare = __gnu_cxx::__ops::_Iter_less_val]’ /usr/include/c++/11/bits/stl_algobase.h:1499:32: required from ‘_ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = std::pair<int, int>*; _Tp = std::pair<int, long long int>]’ answer.code:53:24: required from here /usr/include/c++/11/bits/predefined_ops.h:69:22: error: no match for ‘operator<’ (operand types are ‘std::pair<int, int>’ and ‘const std::pair<int, long long int>’) 69 | { return *__it < __val; } | ~~~~~~^~~~~~~ In file included from /usr/include/c++/11/bits/stl_algobase.h:67, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/istream:38, from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from answer.code:1: /usr/include/c++/11/bits/stl_iterator.h:1187:5: note: candidate: ‘template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)’ 1187 | operator<(const __normal_iterator<_IteratorL, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/11/bits/stl_iterator.h:1187:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/istream:38, from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from answer.code:1: /usr/include/c++/11/bits/predefined_ops.h:69:22: note: ‘std::pair<int, int>’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’ 69 | { return *__it < __val; } | ~~~~~~^~~~~~~ In file included from /usr/include/c++/11/bits/stl_algobase.h:67, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/istream:38, from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from answer.code:1: /usr/include/c++/11/bits/stl_iterator.h:1195:5: note: candidate: ‘template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)’ 1195 | operator<(const __normal_iterator<_Iterator, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/11/bits/stl_iterator.h:1195:5: note: template argument deduction/substitution failed: In file included from /usr/include/c++/11/bits/stl_algobase.h:71, from /usr/include/c++/11/bits/char_traits.h:39, from /usr/include/c++/11/ios:40, from /usr/include/c++/11/istream:38, from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from answer.code:1: /usr/include/c++/11/bits/predefined_ops.h:69:22: note: ‘std::pair<int, int>’ is not derived from ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’ 69 | { return *__it < __val; } | ~~~~~~...