제출 #1124758

#제출 시각아이디문제언어결과실행 시간메모리
1124758dwuyPlahte (COCI17_plahte)C++17
160 / 160
553 ms51784 KiB
#include <bits/stdc++.h> #define debug(x) cout << #x << " = " << x << '\n' #define int long long #define fi first #define se second #define pb push_back #define eb emplace_back #define ALL(x) x.begin(), x.end() #define MASK(i) (1ll << (i)) #define FOR(i,a,b) for (int i = (a); i <= (b); ++i) #define REV(i,a,b) for (int i = (a); i >= (b); --i) using namespace std; int n, m; #define MAXN 80008 struct rect{ int x, y, x2, y2; }; vector<rect> R; struct event{ int op, x, y, y2, i; }; vector<event> E; struct point{ int x,y,c; }; vector<point> P; vector<int> G[MAXN]; int par[MAXN]; vector<int> a[MAXN]; set<int> s[MAXN]; int res[MAXN]; vector<int> root; struct SMT{ int n; vector<int> st, lz; SMT(const int &V) : n(V) { st.assign((n << 2) + 5, 0); lz.assign((n << 2) + 5, -1); } void push(const int &id){ st[id << 1] = lz[id]; st[id << 1 | 1] = lz[id]; lz[id << 1] = lz[id]; lz[id << 1 | 1] = lz[id]; lz[id] = -1; } void up(int id, int l, int r, int u, int v, int val){ if (v < l || r < u) return; if (u <= l && r <= v){ st[id] = val; lz[id] = val; return; } int mid = (l + r) >> 1; if (lz[id] != -1) push(id); up(id << 1, l, mid, u, v, val); up(id << 1 | 1, mid + 1, r, u, v, val); } void up(int u, int v, int val){ up(1, 1, n, u, v, val); } int get(int id, int l, int r, int p){ if (l == r) return st[id]; int mid = (l + r) >> 1; if (lz[id] != -1) push(id); if (p <= mid) return get(id << 1, l, mid, p); return get(id << 1 | 1, mid + 1, r, p); } int get(int p){ return get(1, 1, n, p); } }; void compress(){ vector<int> compX, compY; FOR(i,1,n){ compX.pb(R[i-1].x); compX.pb(R[i-1].x2); compY.pb(R[i-1].y); compY.pb(R[i-1].y2); } FOR(i,1,m){ compX.pb(P[i-1].x); compY.pb(P[i-1].y); } sort(ALL(compX)); sort(ALL(compY)); int cur = compX[0], cnt = 1; map<int,int> mpX, mpY; for (int &x : compX){ if (x != cur) cur = x, cnt++; mpX[cur] = cnt; } cur = compY[0], cnt = 1; for (int &y : compY){ if (y != cur) cur = y, cnt++; mpY[cur] = cnt; } FOR(i,1,n){ R[i-1].x = mpX[R[i-1].x]; R[i-1].y = mpY[R[i-1].y]; R[i-1].x2 = mpX[R[i-1].x2]; R[i-1].y2 = mpY[R[i-1].y2]; } FOR(i,1,m){ P[i-1].x = mpX[P[i-1].x]; P[i-1].y = mpY[P[i-1].y]; } } void dfs(int u, int p){ for (int &x : a[u]) s[u].insert(x); for (int &v : G[u]){ if (v == p) continue; dfs(v, u); if (s[u].size() < s[v].size()) swap(s[u], s[v]); for (const int &x : s[v]) s[u].insert(x); } res[u] = s[u].size(); } void solve(){ cin >> n >> m; FOR(i,1,n){ int x,y,x2,y2;cin>>x>>y>>x2>>y2; R.pb({x,y,x2,y2}); } FOR(i,1,m){ int x,y,c; cin >> x >> y >> c; P.pb({x,y,c}); } compress(); FOR(i,1,n){ E.pb({0,R[i-1].x,R[i-1].y,R[i-1].y2,i}); E.pb({2,R[i-1].x2,R[i-1].y,R[i-1].y2,i}); } FOR(i,1,m){ E.pb({1,P[i-1].x,P[i-1].y,0,P[i-1].c}); } sort(ALL(E),[&](const event &A, const event &B){ if (A.x == B.x) return A.op < B.op; return A.x < B.x; }); SMT tree(n + n + m); for (event &x : E){ if (x.op == 0){ /// add a rectangle to segment tree par[x.i] = tree.get(x.y); if (par[x.i] == 0) root.push_back(x.i); if (par[x.i] > 0) G[tree.get(x.y)].push_back(x.i); tree.up(x.y, x.y2, x.i); } else if (x.op == 1){ /// find point's parent a[tree.get(x.y)].push_back(x.i); } else if (x.op == 2){ tree.up(x.y, x.y2, par[x.i]); } } for (int &x : root) dfs(x, 0); FOR(i,1,n){ cout << res[i] << '\n'; } } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(__null); cout.tie(__null); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...