#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
#include<stack>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define pppiiii pair<pii,pii>
#define ppii pair<int,pii>
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long
const int mod=998244353,mxn=2e5+5,lg=30,inf=1e18,minf=-1e18,Mxn=100000;
int n,m,szx,szy;
struct rec{
int x1,y1,x2,y2,sz,id;
bool operator<(rec c)const{return sz<c.sz;}
};
vector<rec>v;
vector<pair<pii,int>>point;
vector<int>on[mxn+10];
set<int>ans[mxn+10];
vector<int>add[mxn+10];
vector<int>del[mxn+10];
struct seg{
int v[4*mxn+10],add[4*mxn+10];
void init(){for(int i=0;i<=4*szx;i++)v[i]=inf,add[i]=-1;}
void push(int l,int r,int pos){
if(add[pos]==-1)return;
v[pos]=add[pos];
if(l!=r)add[pos*2]=add[pos*2+1]=add[pos];
add[pos]=-1;
}
void update(int l,int r,int ql,int qr,int pos,int val){
push(l,r,pos);
if(l>qr||r<ql)return;
if(l>=ql&&r<=qr){
add[pos]=val;
push(l,r,pos);
return;
}
int mid=l+(r-l)/2;
update(l,mid,ql,qr,pos*2,val);
update(mid+1,r,ql,qr,pos*2+1,val);
}
int qry(int l,int r,int ql,int qr,int pos){
push(l,r,pos);
if(l>qr||r<ql)return inf;
if(l>=ql&&r<=qr)return v[pos];
int mid=l+(r-l)/2;
return min(qry(l,mid,ql,qr,pos*2),qry(mid+1,r,ql,qr,pos*2+1));
}
}t2;
int realans[mxn+10],pa[mxn+10];
//bool cm(pair<pii,int>a,pair<pii,int>b){return a.f.s<b.f.s;}
int32_t main(){
cin>>n>>m;
vector<int>comx,comy;
v.resize(n);
for(int i=0;i<n;i++){
cin>>v[i].x1>>v[i].y1>>v[i].x2>>v[i].y2;
comx.pb(v[i].x1);
comx.pb(v[i].x2);
comy.pb(v[i].y1);
comy.pb(v[i].y2);
v[i].sz=(abs(v[i].x1-v[i].x2)*(abs(v[i].y1-v[i].y2)));
v[i].id=i;
}
sort(all(v));
point.resize(m);
for(int i=0;i<m;i++){
cin>>point[i].f.f>>point[i].f.s>>point[i].s;
comx.pb(point[i].f.f);
comy.pb(point[i].f.s);
}
unique(all(comx));
unique(all(comy));
sort(all(comx));
sort(all(comy));
szx=comx.size();
szy=comy.size();
for(auto &i:v){
i.x1=lb(all(comx),i.x1)-comx.begin();
i.x2=lb(all(comx),i.x2)-comx.begin();
i.y1=lb(all(comy),i.y1)-comy.begin();
i.y2=lb(all(comy),i.y2)-comy.begin();
}
for(auto &i:point){
i.f.f=lb(all(comx),i.f.f)-comx.begin();
i.f.s=lb(all(comy),i.f.s)-comy.begin();
}
for(int i=0;i<n;i++){
add[v[i].y1].pb(i);
del[v[i].y2+1].pb(i);
}
t2.init();
for(int i=0;i<m;i++)add[point[i].f.s].pb(i+n);
for(int i=0;i<szy;i++){
for(auto j:del[i]){
t2.update(0,szx,v[j].x1,v[j].x2,1,pa[j]);
}
for(auto j:add[i]){
if(j>=n){
int k=t2.qry(0,szx,point[j-n].f.f,point[j-n].f.f,1);
if(k!=inf)on[k].pb(j);
}
else{
pa[j]=t2.qry(0,szx,v[j].x1,v[j].x2,1);
if(pa[j]!=inf)on[pa[j]].pb(j);
t2.update(0,szx,v[j].x1,v[j].x2,1,j);
}
}
}
for(int i=0;i<n;i++){
for(auto j:on[i]){
if(j>=n)ans[i].insert(point[j-n].s);
else{
if(ans[i].size()>ans[j].size())swap(ans[j],ans[i]);
for(auto k:ans[j])ans[i].insert(k);
}
}
realans[v[i].id]=ans[i].size();
}
for(int i=0;i<n;i++)cout<<realans[i]<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1166 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1154 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1283 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
255 ms |
69948 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
251 ms |
69800 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |