답안 #404098

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404098 2021-05-13T18:44:14 Z JerryLiu06 Plahte (COCI17_plahte) C++17
160 / 160
257 ms 31784 KB
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using db = long double;
using str = string;
 
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
 
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
 
#define mp make_pair
#define f first
#define s second

#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
 
#define lb lower_bound
#define ub upper_bound
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)

const int MOD = 1e9 + 7;
const int MX = 8e4 + 10;
const ll INF = 1e18;

using pp = pair<pi, int>;

int N, M; vector<pp> E; int B[MX], D[MX], Y[MX], C[MX]; // Bottom, Top

int par[MX]; set<pp> active; unordered_set<int> col[MX]; vi child[MX]; int ans[MX];

int getPar(int Y) {
    auto IT = active.lb({{Y, 0}, 0});

    if (IT == active.end()) return -1;

    if ((*IT).f.s == -1) return par[(*IT).s]; return (*IT).s;
}
void DFS(int X) {
    EACH(Y, child[X]) {
        DFS(Y); if (sz(col[X]) < sz(col[Y])) swap(col[X], col[Y]);

        EACH(C, col[Y]) col[X].insert(C); col[Y].clear();
    }
    ans[X] = sz(col[X]);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> N >> M; F0R(i, N) {
        int A, C; cin >> A >> B[i] >> C >> D[i];

        E.pb({{A, -1}, i}); E.pb({{C, 1}, i}); 
    }
    F0R(i, M) { int X; cin >> X >> Y[i] >> C[i]; E.pb({{X, 0}, i}); }

    sort(all(E)); EACH(P, E) {
        
        if (P.f.s == -1) { par[P.s] = getPar(D[P.s]);
            active.insert({{B[P.s], -1}, P.s}); active.insert({{D[P.s], 1}, P.s});
        }
        else if (P.f.s == 0) { int par = getPar(Y[P.s]); if (par != -1) col[par].insert(C[P.s]); }

        else { active.erase({{B[P.s], -1}, P.s}); active.erase({{D[P.s], 1}, P.s}); }
    }
    F0R(i, N) if (par[i] != -1) child[par[i]].pb(i);

    F0R(i, N) if (par[i] == -1) DFS(i); F0R(i, N) cout << ans[i] << "\n";
}

Compilation message

plahte.cpp: In function 'int getPar(int)':
plahte.cpp:59:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   59 |     if ((*IT).f.s == -1) return par[(*IT).s]; return (*IT).s;
      |     ^~
plahte.cpp:59:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   59 |     if ((*IT).f.s == -1) return par[(*IT).s]; return (*IT).s;
      |                                               ^~~~~~
plahte.cpp: In function 'void DFS(int)':
plahte.cpp:42:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   42 | #define EACH(a, x) for (auto& a : x)
      |                    ^~~
plahte.cpp:65:9: note: in expansion of macro 'EACH'
   65 |         EACH(C, col[Y]) col[X].insert(C); col[Y].clear();
      |         ^~~~
plahte.cpp:65:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   65 |         EACH(C, col[Y]) col[X].insert(C); col[Y].clear();
      |                                           ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 12268 KB Output is correct
2 Correct 70 ms 12212 KB Output is correct
3 Correct 4 ms 6604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 15280 KB Output is correct
2 Correct 82 ms 13496 KB Output is correct
3 Correct 6 ms 6592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 22604 KB Output is correct
2 Correct 153 ms 17196 KB Output is correct
3 Correct 5 ms 6588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 257 ms 31784 KB Output is correct
2 Correct 250 ms 22304 KB Output is correct
3 Correct 5 ms 6604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 244 ms 29368 KB Output is correct
2 Correct 229 ms 22064 KB Output is correct
3 Correct 5 ms 6592 KB Output is correct