都是在上万的位置 WA 的。
#include <bits/stdc++.h>
#define int long long
#define min(x,y) (((x)<(y))?(x):(y))
#define max(x,y) (((x)>(y))?(x):(y))
#define lowbit(x) ((x)&-(x))
#define abs(x) (((x)<(0))?(-(x)):(x))
#define swap(a,b) a^=b^=a^=b
#define INF 1e18
#define MAXN 2000005
using namespace std;
int n, m, k, u, v, b, e, fa[MAXN], len[MAXN], de[MAXN], ans[MAXN];
vector<pair<int, int> > newedge[MAXN];
vector<pair<int, pair<int, pair<int, int> > > > newupdate[MAXN];
pair<int, int> getfa(int id)
{
if (fa[id] == id)
{
return {id, 0};
}
pair<int, int> ans = getfa(fa[id]);
return {ans.first, ans.second ^ len[id]};
}
void update(const int id, const int l, const int r, int &x, int &y, const pair<int, int> k)
{
if (x <= l && y >= r)
{
newedge[id].push_back(k);
return;
}
const int mid = (l + r) / 2;
if (x <= mid)
{
update(id * 2, l, mid, x, y, k);
}
if (y > mid)
{
update(id * 2 + 1, mid + 1, r, x, y, k);
}
}
void dfs(const int id, const int l, const int r)
{
const int mid = (l + r) / 2;
// cout << id << " " << l << " " << r << endl;
for (pair<int, int> nowedge : newedge[id])
{
u = nowedge.first, v = nowedge.second;
pair<int, int> gu = getfa(u), gv = getfa(v);
if (gu.first == gv.first && gu.second == gv.second)
{
// cout << u << " " << v << endl;
goto IMPOSSIBLE;
}
else if (gu.first == gv.first)
{
continue;
}
newupdate[id].push_back({gu.first, {fa[gu.first], {len[gu.first], de[gu.first]}}});
newupdate[id].push_back({gv.first, {fa[gv.first], {len[gv.first], de[gv.first]}}});
if (de[gu.first] > de[gv.first])
{
de[gu.first] = max(de[gu.first], de[gv.first] + 1);
fa[gv.first] = gu.first;
len[gv.first] = gu.second ^ gv.second ^ 1;
}
else
{
de[gv.first] = max(de[gv.first], de[gu.first] + 1);
fa[gu.first] = gv.first;
len[gu.first] = gv.second ^ gu.second ^ 1;
}
}
if (l == r)
{
ans[l] = 1;
return;
}
dfs(id * 2, l, mid);
dfs(id * 2 + 1, mid + 1, r);
IMPOSSIBLE:;
for (pair<int, pair<int, pair<int, int> > > i : newupdate[id])
{
fa[i.first] = i.second.first;
len[i.first] = i.second.second.first;
de[i.first] = i.second.second.second;
}
}
signed main()
{
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
{
fa[i] = i;
}
for (int i = 1; i <= m; i++)
{
cin >> u >> v >> b >> e;
b++;
if (u > v)
{
swap(u, v);
}
if (b > e)
{
continue;
}
update(1, 1, k, b, e, {u, v});
}
// cout << 1 << endl;
// return 0;
dfs(1, 1, k);
// cout << 2 << endl;
for (int i = 1; i <= k; i++)
{
cout << (ans[i] ? "Yes\n" : "No\n");
}
return 0;
}