Submission #913928

# Submission time Handle Problem Language Result Execution time Memory
913928 2024-01-20T13:59:42 Z 8pete8 Plahte (COCI17_plahte) C++17
96 / 160
2000 ms 233140 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 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<pii>on[mxn+10];
set<int>ans[mxn+10];
struct mst{
	set<pii>tree[2*mxn+10];
	void update(int x,int y,int id){
		x+=szx;
		for(int i=x;i>0;i>>=1)tree[i].insert({y,id});
	}
	void del(int x,int y,int id){
		x+=szx;
		for(int i=x;i>0;i>>=1){
			auto it=tree[i].find({y,id});
			if(it!=tree[i].end())tree[i].erase(it);
			else return;
		}
	}
	vector<pii> qry(int l,int r,int ly,int ry,int cid){
		vector<pii>all;
		for(l+=szx,r+=szx;l<=r;l>>=1,r>>=1){
			if(l&1){
				auto it=tree[l].lb({ly,0});
				while(it!=tree[l].end()&&(*it).f<=ry){
					if((*it).s!=cid)all.pb((*it));
					it++;
				}
				l++;
			}
			if(!(r&1)){
				auto it=tree[r].lb({ly,0});
				while(it!=tree[r].end()&&(*it).f<=ry){
					if((*it).s!=cid)all.pb((*it));
					it++;
				}
				r--;
			}
		}
		for(auto i:all){
			if(i.s>=n)del(point[i.s-n].f.f,i.f,i.s);
			else del(v[i.s].x1,i.f,i.s);
		}
		return all;
	}
}t;
int realans[mxn+10];
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();
	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++)t.update(v[i].x1,v[i].y1,i);
	for(int i=0;i<m;i++)t.update(point[i].f.f,point[i].f.s,i+n);
	for(int i=0;i<n;i++)on[i]=t.qry(v[i].x1,v[i].x2,v[i].y1,v[i].y2,i);	
	for(int i=0;i<n;i++){
		for(auto j:on[i]){
			if(j.s>=n)ans[i].insert(point[j.s-n].s);
			else{
				if(ans[j.s].size()>ans[i].size())swap(ans[j.s],ans[i]);
				for(auto k:ans[j.s])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 735 ms 97104 KB Output is correct
2 Correct 738 ms 98916 KB Output is correct
3 Correct 10 ms 34652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 630 ms 103612 KB Output is correct
2 Correct 771 ms 105516 KB Output is correct
3 Correct 11 ms 34652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1318 ms 154288 KB Output is correct
2 Correct 1527 ms 158132 KB Output is correct
3 Correct 10 ms 34652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2068 ms 233128 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2065 ms 233140 KB Time limit exceeded
2 Halted 0 ms 0 KB -