#include <bits/stdc++.h>
#define forr(_a,_b,_c) for(_a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(_a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(_a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define ll long long
#define ull unsigned long long
#define pii pair <int,int>
#define pll pair <ll,ll>
#define piii pair <pii,int>
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define file "test"
#define ld long double
using namespace std;
const int N = 5e5 + 5;
const ll oo = 1e9;
const ll mod = 1e9 + 7;
const ld eps = 1e-6;
pii tree[4 * N];
void update (int i, int l, int r, int u, pii val){
if (l > u || r < u)
return;
//cout << l << " " << r << " " << u << "\n";
if (l == r){
tree[i] = val;
return;
}
int mid = (l + r) >> 1;
update (i * 2, l, mid, u, val);
update (i * 2 + 1, mid + 1, r ,u, val);
tree[i] = min (tree[i * 2], tree[i * 2 + 1]);
}
pii get (int i, int l, int r, int u, int v){
if (l > v || r < u)
return {oo,oo};
if (l >= u && r <= v)
return tree[i];
int mid = (l + r) >> 1;
return min (get (i * 2, l, mid, u, v),
get (i * 2 + 1, mid + 1, r ,u, v));
}
vector <piii> ev;
vector <int> vx,vy;
pii a[N],b[N];
set <int> col[N];
int i,n,ans[N],m,nl[N];
vector <int> g[N];
piii c[N];
void dfs (int u){
int mx = -1, pos = -1;
for (int v : g[u]){
dfs(v);
// cout << u << " " << v << "\n";
if (col[v].size() > mx)
mx = col[v].size(), pos = v;
}
if (pos != -1)
col[u] = col[pos];
for (int v : g[u])
if (v != pos){
for (int x : col[v])
col[u].insert(x);
col[v].clear();
}
ans[u] = col[u].size();
// cout << u << ": ";
// for (int x : col[u])
// cout << x << " ";
// cout << "\n";
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
forr (i,1,(n * 2 + m) * 4)
tree[i] = {oo,oo};
forr (i,1,n){
cin >> a[i].st >> a[i].nd >> b[i].st >> b[i].nd;
vx.pb(a[i].st);
vx.pb(b[i].st);
vy.pb(a[i].nd);
vy.pb(b[i].nd);
}
forr (i,1,m){
cin >> c[i].st.st >> c[i].st.nd >> c[i].nd;
vx.pb(c[i].st.st);
vy.pb(c[i].st.nd);
}
sort(all(vx));
vx.erase(unique(all(vx)),vx.end());
sort(all(vy));
vy.erase(unique(all(vy)),vy.end());
forr (i,1,n){
a[i].st = lower_bound (all(vx),a[i].st) - vx.begin() + 1;
a[i].nd = lower_bound (all(vy),a[i].nd) - vy.begin() + 1;
b[i].st = lower_bound (all(vx),b[i].st) - vx.begin() + 1;
b[i].nd = lower_bound (all(vy),b[i].nd) - vy.begin() + 1;
swap(a[i].nd,b[i].nd);
ev.pb({{a[i].st,-a[i].nd},i});
ev.pb({{b[i].st,oo + a[i].nd},i + n});
// cout << a[i].st << " " << a[i].nd << " "<< b[i].st << " " << b[i].nd << "\n";
}
forr (i,1,m){
c[i].st.st = lower_bound (all(vx),c[i].st.st) - vx.begin() + 1;
c[i].st.nd = lower_bound (all(vy),c[i].st.nd) - vy.begin() + 1;
ev.pb({c[i].st,-i});
}
int lmt = n * 2 + m;
sort(all(ev));
forf (i,0,ev.size()){
piii u = ev[i];
// cout << u.st.st << " " << u.st.nd << " " << u.nd << "\n";
if (u.nd < 0){
int l = u.st.nd, r = lmt;
// cout << l << " " << r << ": \n";
while (l < r){
int mid = (l + r) >> 1;
// cout << mid << " " << get (1,1,lmt,u.st.nd,mid).st << "\n";
if (get(1,1,lmt,u.st.nd,mid).st <= u.st.nd)
r = mid;
else l = mid + 1;
}
pii v = get (1,1,lmt,u.st.nd,l);
// cout << l << " " << v.st << " ";
// pii v = get (1,1,lmt,u.st.nd,lmt);
if (v.st == oo)
continue;
if (v.st <= u.st.nd)
col[v.nd + n].insert(c[-u.nd].nd);
// cout << "paint: " << v.nd << " " << -u.nd << "\n";
}
else if (u.nd <= n){
// cout << -u.st.nd << "\n";
update(1,1,lmt,-u.st.nd,{b[u.nd].nd,u.nd});
}
else {
int f = u.st.nd - oo;
int l = f + 1, r = lmt;
// cout << l << " " << r << "\n";
while (l < r){
int mid = (l + r) / 2;
// cout << mid << " " << get(1,1,lmt,mid,lmt).st << "\n";
if (get(1,1,lmt,f + 1,mid).st <= b[u.nd - n].nd)
r = mid;
else l = mid + 1;
}
pii v = get (1,1,lmt,f + 1,l);
// cout << v.st << " " << v.nd << " " << b[u.nd - n].nd << "\n";
if (v.st < b[u.nd - n].nd)
g[v.nd].pb(u.nd - n),nl[u.nd - n] = 1;
update(1,1,lmt,f,{oo,oo});
// cout << get (1,1,lmt,f,lmt).st << "\n";
}
}
forr (i,1,n)
g[i].pb(i + n);
forr (i,1,n)
if (!nl[i])
dfs(i);
forr (i,1,n)
cout << ans[i] << "\n";
return 0;
}
/*
*/
Compilation message
plahte.cpp: In function 'void dfs(int)':
plahte.cpp:64:27: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
64 | if (col[v].size() > mx)
| ~~~~~~~~~~~~~~^~~~
plahte.cpp:71:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
71 | for (int x : col[v])
| ^~~
plahte.cpp:73:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
73 | col[v].clear();
| ^~~
plahte.cpp: In function 'int main()':
plahte.cpp:4:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forf(_a,_b,_c) for(_a = (_b); _a < (_c); ++_a)
| ^
plahte.cpp:119:5: note: in expansion of macro 'forf'
119 | forf (i,0,ev.size()){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1644 ms |
55288 KB |
Output is correct |
2 |
Correct |
420 ms |
55104 KB |
Output is correct |
3 |
Correct |
8 ms |
45404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2047 ms |
59656 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2041 ms |
68084 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2029 ms |
82912 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2025 ms |
80548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |