Submission #914092

# Submission time Handle Problem Language Result Execution time Memory
914092 2024-01-21T02:41:16 Z 8pete8 Plahte (COCI17_plahte) C++17
160 / 160
554 ms 77892 KB
#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 ll mod=998244353,mxn=3*8e4+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],del[mxn+10];
struct seg{
	ll 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;
ll 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){
				ll 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';
}
# Verdict Execution time Memory Grader output
1 Correct 135 ms 47560 KB Output is correct
2 Correct 163 ms 48316 KB Output is correct
3 Correct 10 ms 34904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 50368 KB Output is correct
2 Correct 155 ms 50532 KB Output is correct
3 Correct 11 ms 34904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 256 ms 60908 KB Output is correct
2 Correct 263 ms 60376 KB Output is correct
3 Correct 11 ms 34904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 409 ms 71860 KB Output is correct
2 Correct 554 ms 77892 KB Output is correct
3 Correct 11 ms 34908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 439 ms 72120 KB Output is correct
2 Correct 459 ms 76728 KB Output is correct
3 Correct 11 ms 34908 KB Output is correct