답안 #382299

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382299 2021-03-27T02:24:23 Z couplefire Plahte (COCI17_plahte) C++17
160 / 160
385 ms 43628 KB
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <set>
#include <vector>
using namespace std;
const int maxn = 5e5;
inline int read(){
	int x = 0;char c = getchar();
	while(!isdigit(c))c = getchar();
	while(isdigit(c))x = x * 10 + c - '0',c = getchar();
	return x;
}
vector<int> G[maxn];
inline void addedge(int u,int v){G[u].push_back(v);}
struct node{
	int l,r;
	mutable int v;
	node(int a,int b,int c):l(a),r(b),v(c){}
	bool operator < (const node &rhs)const{
		return l < rhs.l;
	}
};
set<node> s;
typedef set<node>::iterator iter;
inline iter split(int l){
	iter it = --s.upper_bound(node(l,0,0));
	if(it->l == l)return it;
	int L = it->l,R = it->r,V = it->v;
	s.insert(node(L,l - 1,V));
	return s.insert(node(l,R,V)).first;
}
inline void assign(int l,int r,int v){
	iter itr = split(r + 1),itl = split(l);
	s.erase(itl,itr);
	s.insert(node(l,r,v));
}
inline int query(int pos){
	iter it = --s.upper_bound(node(pos,0,0));
	return it->v;
}
struct Seg{
	int x,l,r,opt,id;
	bool operator < (const Seg &rhs)const{
		if(x != rhs.x)return x < rhs.x;
		return opt > rhs.opt;
	}
}seg[maxn];
int n,m,tot,col[maxn],ans[maxn],faz[maxn];
inline void merge(set<int> &a,set<int> &b){
	if(a.size() < b.size())swap(a,b);
	for(set<int>::iterator it = b.begin();it != b.end();it++)a.insert(*it);
}
inline set<int> dfs(int u){
	set<int> res;
	if(col[u])res.insert(col[u]);
	set<int> tmp;
	for(unsigned int i = 0;i < G[u].size();i++){
		int v = G[u][i];
		tmp = dfs(v);
		merge(res,tmp);
	}
	ans[u] = res.size();
	return res;
}
int main(){
//	freopen("plahte.in","r",stdin);
//	freopen("plahte.out","w",stdout);
	n = read(),m = read();
	for(int a,b,c,d,i = 1;i <= n;i++){
		a = read(),b = read(),c = read(),d = read();
		seg[++tot] = Seg{a,b,d,3,i};
		seg[++tot] = Seg{c,b,d,1,-i};
	}
	for(int x,y,i = 1;i <= m;i++){
		x = read(),y = read(),col[n + i] = read();
		seg[++tot] = Seg{x,y,y,2,n + i};
	}
	s.insert(node(-1e9,1e9,0));
	sort(seg + 1,seg + 1 + tot);
	for(int i = 1;i <= tot;i++){
		if(seg[i].id > 0){
			faz[seg[i].id] = query(seg[i].l);
			assign(seg[i].l,seg[i].r,seg[i].id);
		}else assign(seg[i].l,seg[i].r,faz[-seg[i].id]);
	}
	for(int i = 1;i <= tot;i++)addedge(faz[i],i);
	dfs(0);
	for(int i = 1;i <= n;i++)printf("%d\n",ans[i]);
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 17644 KB Output is correct
2 Correct 121 ms 17548 KB Output is correct
3 Correct 8 ms 12012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 22892 KB Output is correct
2 Correct 157 ms 19436 KB Output is correct
3 Correct 8 ms 12140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 31568 KB Output is correct
2 Correct 244 ms 22892 KB Output is correct
3 Correct 9 ms 12108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 385 ms 43628 KB Output is correct
2 Correct 372 ms 28268 KB Output is correct
3 Correct 9 ms 12140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 360 ms 39692 KB Output is correct
2 Correct 338 ms 28556 KB Output is correct
3 Correct 9 ms 12140 KB Output is correct