Submission #234633

#TimeUsernameProblemLanguageResultExecution timeMemory
234633VEGAnnPlahte (COCI17_plahte)C++14
0 / 160
328 ms34296 KiB
#include <bits/stdc++.h> #define all(x) x.begin(),x.end() #define sz(x) ((int)x.size()) #define a2 array<int,2> #define a3 array<int,3> #define PB push_back using namespace std; typedef long long ll; const int N = 200100; const int PW = 20; const int oo = 2e9; unordered_map<int, vector<int> > ver; vector<int> cols[N], g[N]; set<a3> st; set<a3>::iterator iter; vector<a3> vf; int a[N], b[N], c[N], d[N], n, m, nm[N], id, pre[N], tin[N], tout[N], tt = 0, up[N][PW]; int ans[N], ad[N], del[N]; bool cmp1(int _x, int _y){ return tin[_x] < tin[_y]; } int get_pre(int vl){ iter = st.lower_bound({vl, -1, 0}); if (iter == st.end()) return -1; if ((*iter)[1] == -1) return pre[(*iter)[2]]; else return (*iter)[2]; } void dfs(int v){ tin[v] = ++tt; if (v != 0) { for (int po = 1; po < PW; po++) up[v][po] = up[up[v][po - 1]][po - 1]; } for (int u : g[v]) dfs(u); tout[v] = ++tt; } bool upper(int a, int b){ return (tin[a] <= tin[b] && tout[a] >= tout[b]); } int lca(int a, int b){ if (upper(a, b)) return a; if (upper(b, a)) return b; for (int po = PW - 1; po >= 0; po--) if (!upper(up[a][po], b)) a = up[a][po]; return up[a][0]; } void last_dfs(int v){ ans[v] = ad[v]; if (v > 0) ans[up[v][0]] -= del[v]; for (int u : g[v]){ last_dfs(u); ans[v] += ans[u]; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef _LOCAL freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); #endif // _LOCAL cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; vf.PB({a[i], -1, i}); vf.PB({c[i], +1, i}); } for (int i = n; i < n + m; i++){ cin >> a[i] >> b[i] >> c[i]; vf.PB({a[i], 0, i}); } sort(all(vf)); st.clear(); for (a3 cr : vf){ int i = cr[2]; if (cr[1] == -1){ pre[i] = get_pre(d[i]); st.insert({b[i], -1, i}); st.insert({d[i], +1, i}); } else if (cr[1] == 0){ int id = get_pre(b[i]); if (id >= 0) cols[id].PB(c[i]); } else { st.erase({b[i], -1, i}); st.erase({d[i], +1, i}); } } for (int i = 0; i < n; i++){ g[pre[i] + 1].PB(i + 1); up[i + 1][0] = pre[i] + 1; if (sz(cols[i]) == 0) continue; for (int cl : cols[i]) if (sz(ver[cl]) == 0 || ver[cl].back() != i + 1) ver[cl].PB(i + 1); } dfs(0); for (auto EL : ver){ vector<int> &vc = EL.second; sort(all(vc), cmp1); int glc = vc[0]; ad[vc[0]]++; del[vc[0]]++; for (int it = 1; it < sz(vc); it++){ int v = vc[it]; int pr = vc[it - 1]; int lc = lca(v, pr); if (!upper(glc, lc)){ ad[up[glc][0]]++; del[lc]++; glc = lc; } ad[lc]--; ad[v]++; } ad[up[glc][0]]++; del[0]++; } last_dfs(0); for (int i = 1; i <= n; i++) cout << ans[i] << '\n'; 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...