Submission #886725

#TimeUsernameProblemLanguageResultExecution timeMemory
886725dwuyPlahte (COCI17_plahte)C++14
128 / 160
262 ms24212 KiB
/// dwuy: _,\,,,_\,__,\,,_ #include <bits/stdc++.h> #define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL) #define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout) #define fi first #define se second #define endl "\n" #define len(s) int32_t(s.length()) #define MASK(k)(1LL<<(k)) #define TASK "test" using namespace std; typedef tuple<int, int, int> tpiii; typedef pair<double, double> pdd; typedef pair<int, int> pii; typedef long long ll; const long long OO = 1e18; const int MOD = 1e9 + 7; const int INF = 1e9; const int MX = 80005; struct BIT{ int n; vector<int> tree; BIT(int n=0){ this->n = n; this->tree.assign(n+5, 0); } void update(int idx, int val){ for(; idx<=n; idx+=-idx&idx) tree[idx] += val; } int get(int idx){ int res = 0; for(; idx; idx-=-idx&idx) res += tree[idx]; return res; } int get(int l, int r){ return get(r) - get(l-1); } }; struct SMT{ int n; vector<int> tree; SMT(int n=0){ this->n = n; this->tree.assign(n<<2|1, 0); } void down(int id){ if(tree[id] == -1) return; tree[id<<1] = tree[id<<1|1] = tree[id]; tree[id] = -1; } void update(int l, int r, int id, const int &u, const int &v, const int &val){ if(l>v || r<u) return; if(l>=u && r<=v){ tree[id] = val; return; } down(id); int mid = (l+r)>>1; update(l, mid, id<<1, u, v, val); update(mid+1, r, id<<1|1, u, v, val); } void update(int l, int r, int val){ update(1, n, 1, l, r, val); } int get(int pos){ int id = 1; for(int l=1, r=n; l<r; ){ down(id); int mid = (l+r)>>1; if(pos<=mid) r = mid, id = id<<1; else l = mid+1, id = id<<1|1; } return tree[id]; } }; struct Rect{ int x, y, u, v, id; Rect(int x=0, int y=0, int u=0, int v=0, int id=0){ this->x = x; this->y = y; this->u = u; this->v = v; this->id = id; } bool operator < (const Rect &other){ return x < other.x; } }; int n, m; int rid[MX]; Rect rect[MX]; pair<pii, int> pball[MX]; vector<int> color[MX]; void nhap(){ cin >> n >> m; vector<int> X, Y, F; for(int i=1; i<=n; i++){ int x, y, u, v; cin >> x >> y >> u >> v; rect[i] = Rect(x, y, u, v, i); X.push_back(x); X.push_back(u); Y.push_back(y); Y.push_back(v); } for(int i=1; i<=m; i++){ int x, y, k; cin >> x >> y >> k; pball[i] = {{x, y}, k}; X.push_back(x); Y.push_back(y); F.push_back(k); } #define all(x) (x).begin(),(x).end() sort(all(X)); sort(all(Y)); sort(all(F)); X.erase(unique(all(X)), X.end()); Y.erase(unique(all(Y)), Y.end()); F.erase(unique(all(F)), F.end()); for(int i=1; i<=n; i++){ rect[i].x = lower_bound(all(X), rect[i].x) - X.begin() + 1; rect[i].u = lower_bound(all(X), rect[i].u) - X.begin() + 1; rect[i].y = lower_bound(all(Y), rect[i].y) - Y.begin() + 1; rect[i].v = lower_bound(all(Y), rect[i].v) - Y.begin() + 1; } for(int i=1; i<=m; i++){ pball[i].fi.fi = lower_bound(all(X), pball[i].fi.fi) - X.begin() + 1; pball[i].fi.se = lower_bound(all(Y), pball[i].fi.se) - Y.begin() + 1; pball[i].se = lower_bound(all(F), pball[i].se) - F.begin() + 1; } } int dfsID = -1; int p[MX]; int num[MX]; int rnum[MX]; int clo[MX]; int ans[MX]; vector<int> G[MX]; void dfs(int u){ num[u] = ++dfsID; rnum[num[u]] = u; for(int v: G[u]) dfs(v); clo[u] = dfsID; } void solve(){ SMT smt(n+n+m); vector<pair<pii, pii>> line; for(int i=1; i<=n; i++){ line.push_back({{rect[i].x, i}, {rect[i].y, rect[i].v}}); line.push_back({{rect[i].u+1, -i}, {rect[i].y, rect[i].v}}); } sort(line.begin(), line.end()); sort(pball+1, pball+1+m); for(int i=0, j=1; i<(int)line.size(); i++){ int pos, id; tie(pos, id) = line[i].fi; int l, r; tie(l, r) = line[i].se; bool f = id<0; id = abs(id); if(f) smt.update(l, r, p[id]); else{ p[id] = smt.get(l); G[p[id]].push_back(id); smt.update(l, r, id); } if(i+1!=(int)line.size() && line[i+1].fi.fi!=line[i].fi.fi){ while(j<=m && pball[j].fi.fi < line[i+1].fi.fi){ int id = smt.get(pball[j].fi.se); if(id!=0) color[id].push_back(pball[j].se); j++; } } } dfs(0); vector<pair<pii, int>> query; for(int i=1; i<=n; i++){ query.push_back({{clo[i], num[i]}, i}); } vector<int> pre(m+5, 0); sort(query.begin(), query.end()); BIT bit(n+n); int i = 1; for(pair<pii, int> tmp: query){ int l, r; tie(r, l) = tmp.fi; int id = tmp.se; while(i<=r){ for(int &x: color[rnum[i]]){ if(pre[x]) bit.update(pre[x], -1); bit.update(i, 1); pre[x] = i; } i++; } ans[id] = bit.get(l, r); } for(int i=1; i<=n; i++) cout << ans[i] << '\n'; } int32_t main(){ fastIO; //file(TASK); nhap(); 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...