#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define LL long long
#define ld long double
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define boost cin.tie(0), ios_base::sync_with_stdio(0);
using namespace std;
const int nax = 80111;
const int pod = (1 << 18);
int n, m;
int a[nax], b[nax], c[nax], d[nax];
int e[nax], f[nax], col[nax];
int par[nax];
struct pro {
int x, l, r, id, type, dod;
};
vector <pro> v;
vector <int> val;
vector <int> gao[nax];
vector <int> g[nax];
int daj(int x) {
return (int) (lower_bound(val.begin(), val.end(), x) - val.begin());
}
struct seg {
pair <int, int> t[2 * pod];
void init() {
for (int i = 1; i < 2 * pod; ++i)
t[i] = {0, 0};
}
void ustaw(int l, int r, int k, int czas) {
r++;
for (l += pod, r += pod; l < r; l /= 2, r /= 2) {
if (l & 1) t[l++] = {czas, k};
if (r & 1) t[--r] = {czas, k};
}
}
int query(int x) {
pair <int, int> best = {-1, -1};
x += pod;
while (x) {
best = max(best, t[x]);
x /= 2;
}
return best.se;
}
} ja;
set <int> *se[nax];
int ans[nax];
void dfs(int u, int p) {
pair <int, int> big = {-1, -1};
for (auto it : g[u]) {
dfs(it, u);
big = max(big, {se[it]->size(), it});
}
if (big.fi == -1) {
se[u] = new set <int> ();
}
else {
se[u] = se[big.se];
}
for (auto it : g[u])
if (it != big.se)
for (auto it : *se[it])
se[u]->insert(it);
for (auto it : gao[u])
se[u]->insert(it);
ans[u] = se[u]->size();
}
int main() {
ja.init();
scanf ("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf ("%d%d%d%d", a + i, b + i, c + i, d + i);
val.pb(b[i]);
val.pb(d[i]);
}
for (int i = 1; i <= m; ++i) {
scanf ("%d%d%d", e + i, f + i, col + i);
val.pb(f[i]);
}
sort(val.begin(), val.end());
val.erase(unique(val.begin(), val.end()), val.end());
for (int i = 1; i <= n; ++i) {
v.pb({a[i], daj(b[i]), daj(d[i]), i, 0, 1});
v.pb({c[i], daj(b[i]), daj(d[i]), i, 0, -1});
}
for (int i = 1; i <= m; ++i)
v.pb({e[i], daj(f[i]), daj(f[i]), i, 1, 0});
sort(v.begin(), v.end(), [](pro a, pro b) {
if (a.x != b.x) return a.x < b.x;
if (a.type == b.type) return false;
if (a.dod == -1 || b.dod == -1) return a.type > b.type;
return a.type < b.type;
});
int CZAS = 0;
for (auto it : v) {
CZAS++;
if (it.type == 1) {
int kto = ja.query(it.l);
gao[kto].pb(col[it.id]);
}
else {
if (it.dod == 1) {
par[it.id] = ja.query(it.l);
ja.ustaw(it.l, it.r, it.id, CZAS);
}
else {
ja.ustaw(it.l, it.r, par[it.id], CZAS);
}
}
}
for (int i = 1; i <= n; ++i)
g[par[i]].pb(i);
dfs(0, 0);
for (int i = 1; i <= n; ++i)
printf ("%d\n", ans[i]);
return 0;
}
Compilation message
plahte.cpp: In function 'int main()':
plahte.cpp:95:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d", &n, &m);
~~~~~~^~~~~~~~~~~~~~~~
plahte.cpp:97:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d%d%d", a + i, b + i, c + i, d + i);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plahte.cpp:103:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d%d", e + i, f + i, col + i);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
16740 KB |
Output is correct |
2 |
Correct |
103 ms |
17760 KB |
Output is correct |
3 |
Correct |
10 ms |
8312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
18660 KB |
Output is correct |
2 |
Correct |
118 ms |
18652 KB |
Output is correct |
3 |
Correct |
10 ms |
8312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
204 ms |
26876 KB |
Output is correct |
2 |
Correct |
209 ms |
25524 KB |
Output is correct |
3 |
Correct |
11 ms |
8316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
332 ms |
37844 KB |
Output is correct |
2 |
Correct |
342 ms |
34640 KB |
Output is correct |
3 |
Incorrect |
10 ms |
8184 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
323 ms |
36304 KB |
Output is correct |
2 |
Correct |
319 ms |
36188 KB |
Output is correct |
3 |
Correct |
10 ms |
8312 KB |
Output is correct |