답안 #489413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
489413 2021-11-22T21:32:07 Z macktvz Plahte (COCI17_plahte) C++17
0 / 160
437 ms 29468 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 8e4 + 1;
vector<pair<int,pair<int,int>>> A;
int B[N];
int D[N];
int Y[N];
int col[N];
vector<int> adj[N];
int ans[N];
int par[N];
map<int,pair<int,int>> active;
set<int> hits[N];

void dfs(int u, int p) {
    for(int i : adj[u]) {
        dfs(i,u);
        if (hits[i].size() > hits[u].size()) swap(hits[i],hits[u]);
        for (int j : hits[i]) hits[u].insert(j);
    }
    ans[u] = hits[u].size();
}

int main() {
    int n,m; cin >> n >> m;
    int a,b,c,d;
    for(int i = 0; i < n; i++) {
        cin >> a >> b >> c >> d;
        B[i] = b;
        D[i] = d;
        A.push_back({a,{i,1}});
        A.push_back({c,{i,3}});
    }

    for(int i = 0; i < m; i++) {
        cin >> a >> b >> c;
        col[i] = c;
        Y[i] = b;
        A.push_back({a,{i,2}});
    }
    sort(begin(A),end(A),[&](auto i, auto j) {
        return i.first == j.first ? i.second.second < j.second.second : i.first < j.first; 
    });
    fill(par,par+n,-1);
    for(auto e : A) {
        if (e.second.second == 1) {
            auto f = active.upper_bound(D[e.second.first]);
            if (f != active.end()) { // there is a point here
                if (f->second.second == 1) {// this is the top of another guy - parent
                    adj[f->second.first].push_back(e.second.first);
                    par[e.second.first] = f->second.first;
                } else {//this is the bottom of another guy - if he has a parent then they must have the same parent
                    if (par[f->second.first] != -1) {
                        adj[par[f->second.first]].push_back(e.second.first);
                        par[e.second.first] = par[f->second.first];
                    }
                }
            }
            active[D[e.second.first]] = {e.second.first,1};
            active[B[e.second.first]] = {e.second.first,-1};
        } else if (e.second.second == 3) {
            active.erase(D[e.second.first]);active.erase(B[e.second.first]);
        } else {
            auto f = active.upper_bound(Y[e.second.first]-1);
            
            if (f!= active.end()) { // there might be a hit
                if (f->second.second == 1) {
                    hits[f->second.first].insert(col[e.second.first]);
                } else {
                    if (par[f->second.first] != -1) {
                        hits[par[f->second.first]].insert(col[e.second.first]);
                    }
                }
            }
        }
    }
    for(int i = 0; i < n; i++) {
        if (par[i] == -1) dfs(i,-1);
    }
    for(int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 118 ms 10540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 165 ms 13544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 291 ms 20684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 437 ms 29468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 417 ms 25900 KB Output isn't correct
2 Halted 0 ms 0 KB -