#include <bits/stdc++.h>
#define N 80005
#define M 1000000005
#define INF 2000000000000000005ll
using namespace std;
int dep[N];
int ans[N];
int par[N];
int pr[N];
set<int> col[N];
vector<int> de[N];
map<int,multiset<pair<long long,pair<long long,long long>>>> t;
struct Node{
int a,b,c,d,pos;
bool operator < (const Node other)const{
if(a == other.a){
return 1ll*(c-a)*(d-b) < 1ll*(other.c-other.a)*(other.d-other.b);
}
return a < other.a;
}
};
void upd(int v,int tl,int tr,int l,int r,long long val1,long long val2,long long val3,int ok){
if(tr < l || r < tl){
return;
}
if(l <= tl && tr <= r){
if(ok){
assert(t[v].count({val1,{val2,val3}}));
t[v].erase(t[v].find({val1,{val2,val3}}));
}
else{
t[v].insert({val1,{val2,val3}});
}
return;
}
int tm = (tl+tr)/2;
upd(v*2,tl,tm,l,r,val1,val2,val3,ok);
upd(v*2+1,tm+1,tr,l,r,val1,val2,val3,ok);
}
pair<long long,pair<long long,long long>> get(int v,int l,int r,int pos){
int m = (l+r)/2;
if(l == r){
if(t[v].empty()){
return make_pair(INF,make_pair(INF,INF));
}
return *t[v].begin();
}
if(pos<=m){
if(t[v].empty()){
return min(make_pair(INF,make_pair(INF,INF)),get(v*2,l,m,pos));
}
return min(*t[v].begin(),get(v*2,l,m,pos));
}
else{
if(t[v].empty()){
return min(make_pair(INF,make_pair(INF,INF)),get(v*2+1,m+1,r,pos));
}
return min(*t[v].begin(),get(v*2+1,m+1,r,pos));
}
}
void go_par(int v){
ans[v] = col[pr[v]].size();
if(par[v] == -1){
return;
}
if(col[pr[v]].size() > col[pr[par[v]]].size()){
for(auto u:col[pr[par[v]]]){
col[pr[v]].insert(u);
}
pr[par[v]] = pr[v];
}
else{
for(auto u:col[pr[v]]){
col[pr[par[v]]].insert(u);
}
}
}
void solve(){
int n,m;
cin >> n >> m;
vector<Node> v;
for(int i = 0;i<n;i++){
int a,b,c,d;
cin >> a >> b >> c >> d;
v.push_back({a,b,c,d,i});
}
sort(v.begin(),v.end());
set<pair<int,Node>> s;
for(auto u:v){
while(s.size() && s.begin()->first < u.a){
auto k = s.begin()->second;
s.erase(s.begin());
upd(1,1,M,k.b,k.d,1ll*(k.c-k.a)*(k.d-k.b) ,dep[k.pos],k.pos,1);
}
auto k = get(1,1,M,u.b);
if(k.first == INF){
par[u.pos] = -1;
}
else{
dep[u.pos] = dep[k.second.second] - 1;
par[u.pos] = k.second.second;
}
s.insert({u.c,u});
upd(1,1,M,u.b,u.d,1ll*(u.c-u.a)*(u.d-u.b) ,dep[u.pos],u.pos,0);
}
/*
for(int i=0;i<n;i++){
cout << par[i] << endl;
}*/
vector<pair<int,pair<int,int>>> v2;
for(int i=0;i<m;i++){
int a,b,c;
cin >> a >> b >> c;
v2.push_back({a,{b,c}});
}
sort(v2.begin(),v2.end());
t.clear();
s.clear();
int cnt = 0;
for(auto u:v2){
while(cnt != n && v[cnt].a <= u.first){
auto k = v[cnt];
upd(1,1,M,k.b,k.d,1ll*(k.c-k.a)*(k.d-k.b) ,dep[k.pos],k.pos,0);
s.insert({k.c,k});
cnt++;
}
while(s.size() && s.begin()->first < u.first){
auto k = s.begin()->second;
s.erase(s.begin());
upd(1,1,M,k.b,k.d,1ll*(k.c-k.a)*(k.d-k.b) ,dep[k.pos],k.pos,1);
}
auto k = get(1,1,M,u.second.first);
if(k.first == INF){
continue;
}
else{
col[k.second.second].insert(u.second.second);
}
}
assert(clock() < 1500);
/*
for(int i=0;i<n;i++){
for(auto u:col[i])cout << u << " ";
cout << endl;
}*/
for(int i=0;i<n;i++){
dep[i] = -1*dep[i];
pr[i] = i;
de[dep[i]].push_back(i);
}
for(int i=n-1;i>=0;i--){
for(auto u:de[i]){
go_par(u);
}
}
for(int i=0;i<n;i++){
cout << ans[i] << endl;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2088 ms |
88064 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2048 ms |
93276 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2085 ms |
135264 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2103 ms |
197084 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2097 ms |
181068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |