답안 #1114217

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114217 2024-11-18T11:29:08 Z raczek Joker (BOI20_joker) C++17
0 / 100
252 ms 102384 KB
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
#define int long long
struct DSU{
	int isOddCyc = 0;
	vector<int> par;
	vector<int> rnk;
	vector<pair<int, int> > edg;
	vector<pair<int&, int> > stck;
	vector<int> operWght;
	int Find(int a){
		return (par[a] == a) ? a : Find(par[a]);
	}
	void Union(int a, int b){
		a = Find(a), b = Find(b);
		if(a == b) return;
		if(rnk[a] < rnk[b]) swap(a, b);
		stck.push_back({rnk[a], rnk[a]});
		stck.push_back({par[b], par[b]});
		rnk[a] += rnk[b];
		par[b] = a;
	}
	int add(int x){
		int t = stck.size();
		Union(edg[x].first, edg[x].second^1);
		Union(edg[x].first^1, edg[x].second);
		if(Find(edg[x].first) == Find(edg[x].first^1)){
			stck.push_back({isOddCyc, isOddCyc});
			isOddCyc = true;
		}
		if(Find(edg[x].second) == Find(edg[x].second^1)){
			stck.push_back({isOddCyc, isOddCyc});
			isOddCyc = true;
		}
		operWght.push_back(stck.size() - t);
		return +1;
	}
	int rollback(){
		while(operWght.back() --> 0){
			stck.back().first = stck.back().second;
			stck.pop_back();
		}
		operWght.pop_back();
		return -1;
	}
	void init(int n, vector<pair<int, int >> e){
		edg = e;
		for(auto& v : edg) v.first--, v.second--;
		par.resize(n*2);
		rnk.resize(n*2);
		for(int i=0;i<2*n;i++) par[i] = i, rnk[i] = 1;
	}

};
struct solve{
	vector<int> pos;
	DSU dsu;
	void rec(int l1, int l2, int r1, int r2){
		debug(l1, l2, r1, r2);
		if(l1 > l2) return;
		if(r1 > r2) return;
		if(r2 < l1) return;
		int mid = (l1 + l2) >> 1;
		for(int i=l1;i<=mid;i++) 
			dsu.add(i);
		int opt = -1;
		int cnt = 0;
		for(int i=r2;i>=r1;i--){
			cnt += dsu.add(i);
			if(dsu.isOddCyc == true){
				opt = i;
				break;
			}
		}
		pos[mid] = opt;
		int d = r2 - opt + 1;
		while(d --> 0) cnt += dsu.rollback();
		for(int i=r1;i<max(mid+1, opt);i++) cnt += dsu.add(i);
		rec(mid+1, l2, max(mid+1, opt), r2);
		d = opt - r1 + mid - l1 + 1;
		while(d --> 0) cnt += dsu.rollback();
		for(int i=r2;i>opt;i--) cnt += dsu.add(i);
		for(int i=l2;i>mid;i--) cnt += dsu.add(i);
		rec(l1, mid-1, r1, opt); 
		while(cnt --> 0) dsu.rollback();
	}
	solve()
	{
		int n, m, q;
		cin>>n>>m>>q;
		pos.resize(m+1);
		vector<pair<int, int> > e(m);
		for(auto& v : e) cin>>v.first>>v.second;
		dsu.init(n, e);
		rec(0, m-1, 0, m-1);
		while(q --> 0)
		{
			int l, r;
			cin>>l>>r;
			l--; r--;
			if(pos[l] > r) cout<<"YES\n";
			else cout<<"NO\n";
		}
	}
};
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve a;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 252 ms 102384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -