제출 #1345129

#제출 시각아이디문제언어결과실행 시간메모리
1345129WH8Card Collection (JOI24_collection)C++17
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define mt make_tuple
#define mp make_pair
#define pb push_back
#define int long long 
#define f first
#define s second
#define pll pair<long long, long long>
#define iii tuple<int,int,int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ld long double

struct node{
	int s,e,m,v;
	node *l, *r;
	node(int S, int E){
		s=S, e=E;
		m=(s+e)/2;
		v=0;
		if(s != e){
			l=new node(s, m);
			r=new node(m+1,e);
		}
	};
	void upd(int S, int DV){
		if(s==e){
			v+=DV;
			return;
		}
		if(S <= m)l->upd(S, DV);
		else r->upd(S, DV);
		v=l->v+r->v;
	}
	int qry(int S, int E){
		if(S > E) return 0;
		if(S<=s and e<=E){
			return v;
		}
		if(S > m) return r->qry(S, E);
		if(E <= m) return l->qry(S, E);
		return l->qry(S, m) + r->qry(m+1, E);
	}
}*up, *down;
signed main(){
	int n,m;cin>>n>>m;
	vector<pll> v(n);
	vector<int> discx, discy;
	for(int i=0;i<n;i++){
		cin>>v[i].f>>v[i].s;
		discx.pb(v[i].f);
		discy.pb(v[i].s);
	}
	sort(all(discx));
	sort(all(discy));
	discx.erase(unique(all(discx)),discx.end());
	discy.erase(unique(all(discy)),discy.end());
	vector<vector<int>> ys(n+5);
	for(int i=0;i<n;i++){
		v[i].f=lower_bound(all(discx), v[i].f)-discx.begin();
		v[i].s=lower_bound(all(discy), v[i].s)-discy.begin();
		ys[v[i].f].pb(v[i].s);
		//printf("point %lld, %lld\n", v[i].f, v[i].s);
	}
	for(int i=0;i<n;i++){
		sort(all(ys[i]));
	}
	sort(all(v));
	vector<int> ans(m, -1);
	vector<pair<pll,int>> qs(m);
	for(int i=0;i<m;i++){
		int x,y;cin>>x>>y;
		qs[i].s=i;
		vector<int>::iterator it;
		it = lower_bound(all(discx), x);
		if(it == discx.end()){
			ans[i]=0;
			continue;
		}
		else x = it-discx.begin();
		it = lower_bound(all(discy), y);
		if(it == discy.end()){
			ans[i]=0;
			continue;
		}
		else y= it-discy.begin();
		//printf("query %lld, %lld\n", x, y);
		qs[i].f=mp(x, y);
	}
	sort(all(qs));
	down=new node(0, n);
	up=new node(0, n);
	for(int i=0;i<n;i++){
		if(v[i].f != 0)up->upd(v[i].s, 1);
	}
	int xp=0;
	for(int i=0;i<m;i++){
		auto [coord, qind] = qs[i];
		if(ans[qind]==0)continue;
		auto [x, y] = coord;
		while(xp < x){
			for(auto dy : ys[xp+1]){
				up->upd(dy, -1);
			}
			for(auto dy : ys[xp]){
				down->upd(dy, 1);
			}
			xp++;
		}
		int p0,p1,p2,p3,p4,p5,p6,p7,p8;
		p0=upper_bound(all(ys[x]), y)-lower_bound(all(ys[x]), y);
		p1=up->qry(y+1, n);
		p2=ys[x].end() - upper_bound(all(ys[x]), y);
		p3=down->qry(y+1, n);
		p4=down->qry(y, y);
		p5=down->qry(0, y-1);
		p6=lower_bound(all(ys[x]), y)-ys[x].begin();
		p7=up->qry(0, y-1);
		p8=up->qry(y, y);
		int win=0;
		if(p0 >= 2)win=1;
		if(p0 and n-p0-p3-p7 > 0)win=2;
		if(p4 and p6)win=3;
		if(p2 and p8)win=4;
		if(p2 and p4){
			if(p7) win=5;
			//if(p1 and p5)win=6;
		}
		if(p6 and p8){
			if(p3) win=7;
			//if(p1 and p5)win=8;
		}
		//printf("query ind %lld, x %lld, y %lld, win %lld\n", qind, x, y, win);
		if(win)ans[qind]=1;
		else ans[qind]=0;
	}
	for(int i=0;i<m;i++){
		if(ans[i])cout<<i+1<<" ";
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...