This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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();
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |