답안 #421522

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421522 2021-06-09T08:40:25 Z 송준혁(#7507) Collapse (JOI18_collapse) C++17
0 / 100
15000 ms 17356 KB
#include "collapse.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define MOD 1000000007
#define INF (1ll<<62)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int M, P[101010], cnt;
vector<pii> E[404040], RB;
vector<int> Q[101010], ans;
map<pii, int> S;

int rt(int u){
	if (P[u] < 0) return u;
	return rt(P[u]);
}

void uni(int u, int v){
	u = rt(u), v = rt(v);
	if (u == v) return;
	if (P[u] > P[v]) swap(u, v);
	RB.pb(pii(u, P[u])), RB.pb(pii(v, P[v]));
	P[u] += P[v], P[v] = u;
	RB.pb(pii(-1,0)), cnt--;
}

void ins(int id, int s, int e, int ts, int te, pii t){
	if (e < ts || te < s) return;
	if (ts <= s && e <= te) {E[id].pb(t); return;}
	int m=s+e>>1;
	ins(id*2, s, m, ts, te, t);
	ins(id*2+1, m+1, e, ts, te, t);
}

void dnc(int id, int s, int e){
	int rb = RB.size();
	for (pii t : E[id]) uni(t.fi, t.se);
	if (s < e){
		int m=s+e>>1;
		dnc(id*2, s, m), dnc(id*2+1, m+1, e);
	}
	else for (int t : Q[s]) ans[t] = cnt;
	while (RB.size() > rb){
		pii t = RB.back(); RB.pop_back();
		if (t.fi >= 0) P[t.fi] = t.se;
		else cnt++;
	}
}

vector<int> simulateCollapse(int N, vector<int> T, vector<int> X, vector<int> Y, vector<int> W, vector<int> _P) {
	M = T.size();
	for (int i=0; i<W.size(); i++){
		for (int j=0; j<N; j++) P[j] = -1;
		cnt = N;
		RB.clear();
		for (int j=0; j<=W[i]; j++){
			if (X[j] > Y[j]) swap(X[j], Y[j]);
			if (X[j]<=_P[i] && _P[i]<Y[j]) continue;
			uni(X[j], Y[j]);
		}
		ans.pb(cnt);
	}
	/*
	for (int i=0; i<M; i++){
		if (X[i] > Y[i]) swap(X[i], Y[i]);
		if (X[i]<=_P[0] && _P[0]<Y[i]) continue;
		if (T[i] == 0) S[pii(X[i],Y[i])] = i;
		else{
			ins(1, 0, M-1, S[pii(X[i],Y[i])], i-1, pii(X[i],Y[i]));
			S[pii(X[i],Y[i])] = M;
		}
	}
	for (auto t : S) ins(1, 0, M-1, t.se, M-1, t.fi);
	ans.resize(W.size());
	for (int i=0; i<W.size(); i++) Q[W[i]].pb(i);
	for (int i=0; i<N; i++) P[i] = -1;
	cnt = N;
	dnc(1, 0, M-1);
	*/
	return ans;
}

Compilation message

collapse.cpp: In function 'void ins(int, int, int, int, int, pii)':
collapse.cpp:35:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |  int m=s+e>>1;
      |        ~^~
collapse.cpp: In function 'void dnc(int, int, int)':
collapse.cpp:44:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |   int m=s+e>>1;
      |         ~^~
collapse.cpp:48:19: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |  while (RB.size() > rb){
      |         ~~~~~~~~~~^~~~
collapse.cpp: In function 'std::vector<int> simulateCollapse(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
collapse.cpp:57:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for (int i=0; i<W.size(); i++){
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 12364 KB Output is correct
2 Incorrect 11 ms 12236 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 14588 KB Output is correct
2 Incorrect 43 ms 14600 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 14600 KB Output is correct
2 Correct 54 ms 14604 KB Output is correct
3 Correct 49 ms 14992 KB Output is correct
4 Correct 65 ms 15028 KB Output is correct
5 Correct 515 ms 15264 KB Output is correct
6 Correct 4901 ms 15568 KB Output is correct
7 Execution timed out 15016 ms 17356 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 12364 KB Output is correct
2 Incorrect 11 ms 12236 KB Output isn't correct
3 Halted 0 ms 0 KB -