답안 #130691

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
130691 2019-07-15T21:16:42 Z claudy 다리 (APIO19_bridges) C++14
0 / 100
3000 ms 23160 KB
//# pragma GCC optimize("Ofast,no-stack-protector")
//# pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
/*
# include <ext/pb_ds/tree_policy.hpp>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/rope>
*/
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;

/*
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
Tree<int>tr;
*/

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# define LOCAL
# define sim template < class c
# define ris return * this
# define dor > debug & operator <<
# define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int gcd(int a, int b)
{
if(b) return gcd(b,a%b);
return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int n,m,u[1 << 17],v[1 << 17],d[1 << 17],a[1 << 17],b[1 << 17],c[1 << 17],q,sze[1 << 17],p[1 << 17],ans[1 << 17];
vector<int>vec[1 << 17];
int viz[1 << 17];
vector<int>qry[1 << 17];
int used[1 << 17];

const int L = 505;


int find(int x)
{
	if(x == p[x]) return x;
	return p[x] = find(p[x]);
}

void unite(int a,int b)
{
	a = find(a);
	b = find(b);
	if(sze[a] > sze[b]) swap(a,b);
	p[a] = b;
	sze[b] += sze[a];
}

int dfs(int nod)
{
	viz[nod] = 1;
	int x = sze[nod];
	for(auto it : vec[nod])
	{
		if(!viz[it]) x += dfs(it);
	}
	return x;
}

int32_t main(){_
	//freopen("input","r",stdin);
	cin >> n >> m;
	for(int i = 1;i <= m;i++)
	{
		cin >> u[i] >> v[i] >> d[i];
	}
	cin >> q;
	for(int i = 0;i < q;i++)
	{
		cin >> a[i] >> b[i] >> c[i];
	}
	set<pair<int,int>>st;
	for(int i = 1;i <= m;i++)
	{
		st.insert(mp(-d[i],i));
	}
	st.insert(mp(0,0));
	for(int i = 0;i < q;i += L)
	{
		for(int j = 1;j <= n;j++) p[j] = j,sze[j] = 1;
		for(int j = 0;j <= m;j++) qry[j].clear();
		for(int j = i;j < min(q,i + L);j++)
		{
			if(a[j] == 1)
			{
				auto it = st.find(mp(-d[b[j]],b[j]));
				if(it != st.end()) st.erase(it);
			}
		}
		for(int j = i;j < min(q,i + L);j++)
		{
			if(a[j] == 2)
			{
				auto it = st.upper_bound(mp(-c[j],2e9));
				qry[(*it).second].pb(j);
			}
		}
		for(auto IT : st)
		{
			int idx = IT.second;
			for(auto it : qry[idx])
			{
				vector<int>temp;
				vector<int>kek;
				for(int j = it - 1;j >= i;j--)
				{
					if(a[j] == 1 && !used[b[j]])
					{
						used[b[j]] = 1;
						kek.pb(b[j]);
						if(c[j] >= c[it])
						{
							int x = find(u[b[j]]);
							int y = find(v[b[j]]);
							if(x != y)
							{
								vec[x].push_back(y);
								vec[y].push_back(x);
								viz[x] = viz[y] = 0;
								temp.pb(x);
								temp.pb(y);
							}
						}
					}
				}
				for(int j = it + 1;j < min(q,i + L);j++)
				{
					if(a[j] == 1 && !used[b[j]])
					{
						used[b[j]] = 1;
						kek.pb(b[j]);
						if(d[b[j]] >= c[it])
						{
							int x = find(u[b[j]]);
							int y = find(v[b[j]]);
							if(x != y)
							{
								vec[x].pb(y);
								vec[y].pb(x);
								viz[x] = viz[y] = 0;
								temp.pb(x);
								temp.pb(y);
							}
						}
					}
				}
				ans[it] = dfs(find(b[it]));
				for(auto it : kek) used[it] = 0;
				while(sz(temp))
				{
					vec[temp.back()].clear();
					temp.pop_back();
				}				
			}
			unite(u[idx],v[idx]);
		}
		vector<int>kek;
		for(int j = min(q,i + L - 1);j >= i;j--)
		{
			if(a[j] == 1 && !used[b[j]])
			{
				d[b[j]] = c[j];
				used[b[j]] = 1;
				kek.pb(b[j]);
				st.insert(mp(-d[b[j]],c[j]));
			}
		}
		for(auto it : kek) used[it] = 0;
	}
	for(int i = 0;i < q;i++)
	{
		if(a[i] == 2) 
		{
			cout << max(1,ans[i]) << '\n';
		}
	}
	return 0;
}









Compilation message

bridges.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 # pragma GCC optimization ("unroll-loops")
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6524 KB Output is correct
2 Incorrect 8 ms 6520 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 101 ms 23160 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 84 ms 20556 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3035 ms 15808 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 101 ms 23160 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6524 KB Output is correct
2 Incorrect 8 ms 6520 KB Output isn't correct
3 Halted 0 ms 0 KB -