답안 #159440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
159440 2019-10-22T18:03:25 Z Atalasion Plahte (COCI17_plahte) C++14
0 / 160
547 ms 108988 KB
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 80000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;

int n, m, col[N], par[N], seg[N << 4], lazy[N << 4];
vi COL[N];
pair<pii, pii> rect[N];
pii poi[N];
vector<int> P;
vector<pair<pii, int>> vl[N << 2], vr[N << 2];
vector<pii> Ge[N << 2]; 
map<int, int> koj;

void modify(int id, ll x, int t){
	seg[id] += x;
	lazy[id] += x;
	return;
}

void shift(int id, int t){
	modify(id << 1, lazy[id], t);
	modify(id << 1 | 1, lazy[id], t);
	lazy[id] = 0;
	return;
}

void add(int id, int lq, int rq, int x, int l, int r){
	if (rq <= l || r <= lq) return;
	if (lq <= l && r <= rq){
		modify(id, x, 1);
		return;
	}
	int mid = (l + r) >> 1;
	shift(id, r - l);
	add(id << 1, lq, rq, x, l, mid);
	add(id << 1 | 1, lq, rq, x, mid, r);
	seg[id] = seg[id << 1] + seg[id << 1 | 1];
	return;
}

ll get(int id, int lq, int rq, int l, int r){
	if (rq <= l || r <= lq) return 0;
	if (lq <= l && r <= rq){
		return seg[id];
	}
	shift(id, r - l);
	int mid = (l + r) >> 1;
	return get(id << 1, lq, rq, l, mid) + get(id << 1 | 1, lq, rq, mid, r);
}

vi G[N], sub_t[N];
int child[N], cnt[N], ans[N];

void DFS_c(int v = 0, int p = 0){
	child[v] += COL[v].size();
	for (auto u:G[v]){
		if (u == p) continue;
		DFS_c(u, v);
		child[v] += child[u];
	}
	return;
}

void DFS(int v = 0, int p = 0, bool f = 1){
	int Mx = -1, ind = N - 1;
	for (auto u:G[v]){
		if (u == p) continue;
		if (Mx < child[u]) Mx = child[u], ind = u;
	}
	for (auto u:G[v]){
		if (u == p) continue;
		if (u == ind) DFS(u, v, 1);
		else DFS(u, v, 0);
	}
	ans[v] = ans[ind];
	sub_t[v].swap(sub_t[ind]);
	for (auto u:G[v]){
		if (u == p || u == ind){
			for (auto x:sub_t[u]){
				cnt[col[x]] ++;
				sub_t[v].pb(x);
				if (cnt[col[x]] == 1) ans[v]++;
			}
			sub_t[u].shrink_to_fit();
		}
	}
	for (auto u:COL[v]){
		cnt[col[u]]++;
		if (cnt[col[u]] == 1) ans[v]++;
		sub_t[v].pb(u);
	}
	if (f == 0){
		for (auto u:sub_t[v]){
			cnt[col[u]] --;
		}
	}
	return;
}

void solve(){
	DFS_c(0);
	DFS();
	return;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++){
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		rect[i] = {{x1, y1}, {x2, y2}};
		P.pb(x1), P.pb(x2), P.pb(y1), P.pb(y2);
	}
	for (int i = 1; i <= m; i++){
		cin >> poi[i].F >> poi[i].S >> col[i];
		P.pb(poi[i].F), P.pb(poi[i].S);
	}
	sort(all(P));
	P.resize(unique(all(P)) - P.begin());
	for (int i = 0; i < P.size(); i++) koj[P[i]] = i + 1;
	for (int i = 1; i <= n; i++){
		vl[koj[rect[i].F.F]].pb({{koj[rect[i].F.S], koj[rect[i].S.S]}, i});
		vr[koj[rect[i].S.F]].pb({{koj[rect[i].F.S], koj[rect[i].S.S]}, i});
	}
	for (int i = 1; i <= m; i++){
		Ge[koj[poi[i].F]].pb({koj[poi[i].S], i});
	}
	for (int i = 1; i < (N << 2); i++){
		for (auto u:vl[i]){
			//cout << u.S << '\n';
			//cout << u.F.F << ' ' << u.F.S << '\n';
			par[u.S] = get(1, u.F.F, u.F.F + 1, 1, (N << 2));
			add(1, u.F.F, u.F.S + 1, u.S - par[u.S], 1, (N << 2));
		}
		for (auto u:Ge[i]){
			ll dad = get(1, u.F, u.F + 1, 1, (N << 2));
			COL[dad].pb(u.S);
		}
		for (auto u:vr[i]){
			add(1, u.F.F, u.F.S + 1, par[u.S] - u.S, 1, (N << 2));
		}
	}
	//for (int i = 1; i <= n; i++) cout << par[i] << ' ';
	for (int i = 1; i <= m; i++){
		G[par[i]].pb(i);
		G[i].pb(par[i]);
	}
	solve();
	for (int i = 1; i <= n; i++) cout << ans[i] << '\n';




	return 0;
}

Compilation message

plahte.cpp:8:0: warning: ignoring #pragma GCC optimise [-Wunknown-pragmas]
 #pragma GCC optimise ("ofast")
 
plahte.cpp:9:0: warning: ignoring #pragma GCC optimise [-Wunknown-pragmas]
 #pragma GCC optimise("unroll-loops")
 
plahte.cpp: In function 'int main()':
plahte.cpp:138:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < P.size(); i++) koj[P[i]] = i + 1;
                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 261 ms 45040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 312 ms 49520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 547 ms 64496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 358 ms 108564 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 359 ms 108988 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -