답안 #257891

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257891 2020-08-05T02:30:37 Z arnold518 Joker (BOI20_joker) C++14
100 / 100
710 ms 16544 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 4e5;

int N, M, Q;
pii E[MAXN+10];
int ans[MAXN+10];

struct UF
{
	vector<int> par, sz, opp;
	bool state;
	vector<int> V;
	void init()
	{
		par.resize(2*N+10); sz.resize(2*N+10); opp.resize(2*N+10);
		int i, j;
		for(i=1; i<=N; i++) par[i]=i, sz[i]=1, opp[i]=N+i;
		for(i=1; i<=N; i++) par[i+N]=i+N, sz[i+N]=1, opp[i+N]=i;
		V.clear(); state=true;
	}
	int Find(int x)
	{
		if(x==par[x]) return x;
		return Find(par[x]);
	}
	void Union(int x, int y)
	{
		x=Find(x); y=Find(y);
		int nx=opp[x], ny=opp[y];

		if(x==y || !state)
		{
			if(state) V.push_back(-1);
			else V.push_back(-2);
			state=false;
			return;
		}

		if(sz[x]<sz[ny]) swap(x, ny);
		if(sz[y]<sz[nx]) swap(y, nx);
		
		if(sz[x]==sz[ny]) sz[x]++, V.push_back(-3);
		if(sz[y]==sz[nx]) sz[y]++, V.push_back(-4);
		V.push_back(opp[x]); V.push_back(opp[y]); V.push_back(ny); V.push_back(nx);
		par[ny]=x;
		par[nx]=y;
		opp[x]=y; opp[y]=x;
	}
	void restore()
	{
		int ny, nx, x, y, oppx, oppy;
		if(V.empty()) while(1);
		if(V.back()==-1 || V.back()==-2)
		{
			if(V.back()==-1) state=true;
			V.pop_back();
		 	return;
		}

		nx=V.back(); V.pop_back();
		ny=V.back(); V.pop_back();
		oppy=V.back(); V.pop_back();
		oppx=V.back(); V.pop_back();
		x=par[ny]; y=par[nx];
		if(!V.empty() && V.back()==-4) sz[x]--, V.pop_back();
		if(!V.empty() && V.back()==-3) sz[y]--, V.pop_back();
		opp[x]=oppx; opp[y]=oppy;
		sz[x]-=sz[ny]; sz[y]-=sz[nx];
		par[ny]=ny; par[nx]=nx;
	}
}uf;

int P[MAXN+10];

void solve(int l1, int l2, int r1, int r2)
{
	int i, j;
	if(l1>l2) return;

	//printf("DNC %d %d %d %d\n", l1, l2, r1, r2);
	int lmid=l1+l2>>1;
	int cnt=0;
	for(i=max(1, l1); i<=lmid; i++) uf.Union(E[i].first, E[i].second), cnt++;
	for(i=r2; i>=r1 && i>lmid && uf.state; i--) uf.Union(E[i].first, E[i].second), cnt++;
	while(cnt--) uf.restore();
	int rmid=i; P[lmid]=rmid;
	for(i=r2; i>rmid; i--) uf.Union(E[i].first, E[i].second);
	solve(l1, lmid-1, r1, rmid);
	for(i=r2; i>rmid; i--) uf.restore();
	for(i=max(1, l1); i<=lmid; i++) uf.Union(E[i].first, E[i].second);
	solve(lmid+1, l2, rmid, r2);
	for(i=max(1, l1); i<=lmid; i++) uf.restore();
}

int main()
{
	int i, j, k;

	scanf("%d%d%d", &N, &M, &Q);
	for(i=1; i<=M; i++) scanf("%d%d", &E[i].first, &E[i].second);

	uf.init();
	solve(0, M, 1, M);
	//for(i=0; i<=M; i++) printf("%d ", P[i]);
	while(Q--)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		if(r<=P[l-1]) printf("YES\n");
		else printf("NO\n");
	}
}

Compilation message

Joker.cpp: In member function 'void UF::init()':
Joker.cpp:22:10: warning: unused variable 'j' [-Wunused-variable]
   int i, j;
          ^
Joker.cpp: In function 'void solve(int, int, int, int)':
Joker.cpp:87:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int lmid=l1+l2>>1;
           ~~^~~
Joker.cpp:83:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
Joker.cpp: In function 'int main()':
Joker.cpp:103:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j, k;
         ^
Joker.cpp:103:12: warning: unused variable 'k' [-Wunused-variable]
  int i, j, k;
            ^
Joker.cpp:105:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &M, &Q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:106:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=M; i++) scanf("%d%d", &E[i].first, &E[i].second);
                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:114:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 4 ms 512 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 4 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 4 ms 512 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 3 ms 512 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 4 ms 384 KB Output is correct
52 Correct 3 ms 384 KB Output is correct
53 Correct 3 ms 384 KB Output is correct
54 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 335 ms 8040 KB Output is correct
4 Correct 602 ms 11536 KB Output is correct
5 Correct 244 ms 10728 KB Output is correct
6 Correct 325 ms 7788 KB Output is correct
7 Correct 351 ms 7836 KB Output is correct
8 Correct 399 ms 7912 KB Output is correct
9 Correct 431 ms 9192 KB Output is correct
10 Correct 555 ms 10420 KB Output is correct
11 Correct 387 ms 9196 KB Output is correct
12 Correct 399 ms 9704 KB Output is correct
13 Correct 385 ms 6632 KB Output is correct
14 Correct 394 ms 7912 KB Output is correct
15 Correct 569 ms 8816 KB Output is correct
16 Correct 615 ms 10216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 335 ms 8040 KB Output is correct
30 Correct 602 ms 11536 KB Output is correct
31 Correct 244 ms 10728 KB Output is correct
32 Correct 325 ms 7788 KB Output is correct
33 Correct 351 ms 7836 KB Output is correct
34 Correct 399 ms 7912 KB Output is correct
35 Correct 431 ms 9192 KB Output is correct
36 Correct 555 ms 10420 KB Output is correct
37 Correct 387 ms 9196 KB Output is correct
38 Correct 399 ms 9704 KB Output is correct
39 Correct 385 ms 6632 KB Output is correct
40 Correct 394 ms 7912 KB Output is correct
41 Correct 569 ms 8816 KB Output is correct
42 Correct 615 ms 10216 KB Output is correct
43 Correct 335 ms 7788 KB Output is correct
44 Correct 621 ms 11616 KB Output is correct
45 Correct 475 ms 11696 KB Output is correct
46 Correct 307 ms 7784 KB Output is correct
47 Correct 368 ms 7912 KB Output is correct
48 Correct 508 ms 9192 KB Output is correct
49 Correct 710 ms 10472 KB Output is correct
50 Correct 386 ms 8552 KB Output is correct
51 Correct 415 ms 8808 KB Output is correct
52 Correct 511 ms 11688 KB Output is correct
53 Correct 389 ms 6632 KB Output is correct
54 Correct 501 ms 8552 KB Output is correct
55 Correct 536 ms 8808 KB Output is correct
56 Correct 579 ms 10216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 4 ms 512 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 4 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 4 ms 512 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 3 ms 512 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 4 ms 384 KB Output is correct
52 Correct 3 ms 384 KB Output is correct
53 Correct 3 ms 384 KB Output is correct
54 Correct 3 ms 512 KB Output is correct
55 Correct 301 ms 7156 KB Output is correct
56 Correct 548 ms 13288 KB Output is correct
57 Correct 191 ms 13416 KB Output is correct
58 Correct 253 ms 9396 KB Output is correct
59 Correct 435 ms 11496 KB Output is correct
60 Correct 541 ms 10984 KB Output is correct
61 Correct 370 ms 11624 KB Output is correct
62 Correct 345 ms 11508 KB Output is correct
63 Correct 327 ms 9320 KB Output is correct
64 Correct 449 ms 10088 KB Output is correct
65 Correct 519 ms 11496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 4 ms 512 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 4 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 4 ms 512 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 3 ms 512 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 4 ms 384 KB Output is correct
52 Correct 3 ms 384 KB Output is correct
53 Correct 3 ms 384 KB Output is correct
54 Correct 3 ms 512 KB Output is correct
55 Correct 335 ms 8040 KB Output is correct
56 Correct 602 ms 11536 KB Output is correct
57 Correct 244 ms 10728 KB Output is correct
58 Correct 325 ms 7788 KB Output is correct
59 Correct 351 ms 7836 KB Output is correct
60 Correct 399 ms 7912 KB Output is correct
61 Correct 431 ms 9192 KB Output is correct
62 Correct 555 ms 10420 KB Output is correct
63 Correct 387 ms 9196 KB Output is correct
64 Correct 399 ms 9704 KB Output is correct
65 Correct 385 ms 6632 KB Output is correct
66 Correct 394 ms 7912 KB Output is correct
67 Correct 569 ms 8816 KB Output is correct
68 Correct 615 ms 10216 KB Output is correct
69 Correct 335 ms 7788 KB Output is correct
70 Correct 621 ms 11616 KB Output is correct
71 Correct 475 ms 11696 KB Output is correct
72 Correct 307 ms 7784 KB Output is correct
73 Correct 368 ms 7912 KB Output is correct
74 Correct 508 ms 9192 KB Output is correct
75 Correct 710 ms 10472 KB Output is correct
76 Correct 386 ms 8552 KB Output is correct
77 Correct 415 ms 8808 KB Output is correct
78 Correct 511 ms 11688 KB Output is correct
79 Correct 389 ms 6632 KB Output is correct
80 Correct 501 ms 8552 KB Output is correct
81 Correct 536 ms 8808 KB Output is correct
82 Correct 579 ms 10216 KB Output is correct
83 Correct 301 ms 7156 KB Output is correct
84 Correct 548 ms 13288 KB Output is correct
85 Correct 191 ms 13416 KB Output is correct
86 Correct 253 ms 9396 KB Output is correct
87 Correct 435 ms 11496 KB Output is correct
88 Correct 541 ms 10984 KB Output is correct
89 Correct 370 ms 11624 KB Output is correct
90 Correct 345 ms 11508 KB Output is correct
91 Correct 327 ms 9320 KB Output is correct
92 Correct 449 ms 10088 KB Output is correct
93 Correct 519 ms 11496 KB Output is correct
94 Correct 348 ms 12648 KB Output is correct
95 Correct 400 ms 16544 KB Output is correct
96 Correct 250 ms 10728 KB Output is correct
97 Correct 302 ms 7844 KB Output is correct
98 Correct 350 ms 7912 KB Output is correct
99 Correct 455 ms 7912 KB Output is correct
100 Correct 495 ms 10344 KB Output is correct
101 Correct 399 ms 8660 KB Output is correct
102 Correct 463 ms 8936 KB Output is correct
103 Correct 562 ms 10856 KB Output is correct
104 Correct 461 ms 7156 KB Output is correct
105 Correct 552 ms 8680 KB Output is correct
106 Correct 622 ms 9964 KB Output is correct
107 Correct 194 ms 11232 KB Output is correct
108 Correct 343 ms 7788 KB Output is correct
109 Correct 359 ms 7760 KB Output is correct
110 Correct 342 ms 7788 KB Output is correct
111 Correct 363 ms 7784 KB Output is correct
112 Correct 343 ms 7784 KB Output is correct
113 Correct 377 ms 7820 KB Output is correct
114 Correct 343 ms 7752 KB Output is correct
115 Correct 352 ms 7784 KB Output is correct
116 Correct 356 ms 8040 KB Output is correct