#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N = 80000 + 5;
template<class T>
struct Point{
T x, y;
Point (const ll &x_ = 0, const ll &y_ = 0) : x(x_), y(y_) {};
bool operator<(const Point &p) const{
return x < p.x || (x == p.x && y < p.y);
}
bool operator==(const Point &p) const{
return x == p.x && y == p.y;
}
};
using Pt = Point<ll>;
struct Line {
ll x1, y1, x2, y2, ind;
Line (const ll &x1_ = 0, const ll &y1_ = 0, const ll &x2_ = 0, const ll &y2_ = 0, const ll &ind_ = 0) : x1(x1_), y1(y1_), x2(x2_), y2(y2_), ind(ind_) {};
};
struct SEGTREE {
ll INF = N - 1;
int n;
vector<ll> lazy;
SEGTREE(int n_) {
n = n_;
lazy.assign(4 * n + 1, 0);
lazy[1] = INF;
}
void prop(int node, int i, int j) {
if (lazy[node] == -1) return;
if (i != j) {
lazy[node << 1] = lazy[node];
lazy[node << 1 | 1] = lazy[node];
}
lazy[node] = -1;
}
void update(int node, int l, int r, int i, int j, int val) {
if (l > r || l > j || i > j || i > r) return;
prop(node, l, r);
if (i <= l && r <= j) {
lazy[node] = val;
return;
}
int mid = (l + r) / 2;
update(node << 1, l, mid, i, j, val);
update(node << 1 | 1, mid + 1, r, i, j, val);
}
void update(int i, int j, int val) {
update(1, 1, n, i, j, val);
}
int query(int node, int i, int j, int ind) {
if (i == j) return lazy[node];
prop(node, i, j);
int mid = (i + j) / 2;
if (ind <= mid) return query(node << 1, i, mid, ind);
else return query(node << 1 | 1, mid + 1, j, ind);
}
int query(int ind) {
return query(1, 1, n, ind);
}
} segtree(3 * N);
ll n, m;
vector<Line> recs;
vector<set<ll>> c_set(N);
vector<ll> c_ind(N), p(N, N - 1), ans(N, -1);
vector<pair<pair<ll, ll>, ll>> pts;
vector<vector<ll>> edges(N);
map<ll, ll> y_ind;
void merge(ll node, ll parent) {
if (c_set[c_ind[node]].size() > c_set[c_ind[parent]].size()) {
swap(c_ind[node], c_ind[parent]);
}
for (ll x : c_set[c_ind[node]]) c_set[c_ind[parent]].insert(x);
}
void sweep() {
set<pair<ll, ll>> s;
pair<ll, ll> pt;
ll ind, par = 0;
for (auto x : pts) {
pt = x.first, ind = x.second;
par = segtree.query(y_ind[pt.second]);
if (pt.first == 6 && pt.second == 6) return;
for (auto se : s) {
}
if (ind < 0) {
if (par != N - 1) c_set[c_ind[par]].insert(ind);
} else if (s.find(make_pair(recs[ind].x1, recs[ind].y1)) == s.end()) {
s.insert(pt);
edges[ind].push_back(par);
edges[par].push_back(ind);
segtree.update(y_ind[recs[ind].y1], y_ind[recs[ind].y2], ind);
p[ind] = par;
} else {
s.erase(make_pair(recs[ind].x1, recs[ind].y1));
segtree.update(1, 1, 3 * N, y_ind[recs[ind].y1], y_ind[recs[ind].y2], p[ind]);
}
}
}
void dfs(ll node, ll parent) {
for (ll child : edges[node]) {
if (child == parent) continue;
dfs(child, node);
if (node != N - 1) merge(child, node);
}
if (node != N - 1) ans[node] = c_set[c_ind[node]].size();
}
void solve() {
ll a, b, c, d;
cin >> n >> m;
vector<ll> ys;
for (ll i = 0; i < n; i++) {
cin >> a >> b >> c >> d;
recs.push_back(Line(a, b, c, d, i));
pts.push_back(make_pair(make_pair(a, b), i));
pts.push_back(make_pair(make_pair(c, d), i));
ys.push_back(b);
ys.push_back(d);
c_ind[i] = i;
}
for (ll i = 0; i < m; i++) {
cin >> a >> b >> c;
ys.push_back(b);
pts.push_back(make_pair(make_pair(a, b), -c));
}
sort(pts.begin(), pts.end());
sort(ys.begin(), ys.end());
for (ll i = 0; i < (ll)ys.size(); i++) {
y_ind[ys[i]] = i + 1;
}
sweep();
dfs(N - 1, -1);
for (ll i = 0; i < n; i++) cout << ans[i] << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t = 1;
// cin >> t;
while(t--) {
solve();
}
return 0;
}
Compilation message
plahte.cpp: In function 'void sweep()':
plahte.cpp:92:19: warning: variable 'se' set but not used [-Wunused-but-set-variable]
92 | for (auto se : s) {
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
26616 KB |
Output is correct |
2 |
Correct |
105 ms |
28908 KB |
Output is correct |
3 |
Correct |
7 ms |
15440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
30448 KB |
Output is correct |
2 |
Correct |
131 ms |
30192 KB |
Output is correct |
3 |
Incorrect |
9 ms |
15440 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
227 ms |
42916 KB |
Output is correct |
2 |
Correct |
222 ms |
40924 KB |
Output is correct |
3 |
Correct |
7 ms |
15440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
397 ms |
56992 KB |
Output is correct |
2 |
Correct |
447 ms |
56220 KB |
Output is correct |
3 |
Correct |
7 ms |
15440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
410 ms |
54996 KB |
Output is correct |
2 |
Correct |
392 ms |
54448 KB |
Output is correct |
3 |
Incorrect |
6 ms |
15440 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |