QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#63714#4236. Triangular LogsDaBenZhongXiaSongKuaiDi#WA 2ms40172kbC++143.4kb2022-11-23 10:32:212022-11-23 10:32:22

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-23 10:32:22]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:40172kb
  • [2022-11-23 10:32:21]
  • 提交

answer

#include <bits/stdc++.h>
//#define int long long
#define ll long long
#define db double
#define fi first
#define se second
#define pii pair<int,int>
#define vi vector<int>
#define y1 heqiyouxing

using namespace std;

const int maxn=3e5,LOG=100,inf=1e9; 

int n,q,kx[maxn+5],ky[maxn+5],cntx,cnty,ans[maxn+5]; 
struct node {
	int x,y,h,id;
	node() {
		x=y=h=id=0; 
	}
	node(int a,int b,int c,int d) {
		x=a,y=b,h=c,id=d; 
	}
	bool operator < (const node &t) const {
		return x==t.x?id<t.id:x<t.x; 
	}
} a[maxn+5]; 
struct mat {
	int x1,y1,x2,y2,id; 
} M[maxn+5]; 
vector<node> addx[maxn+5]; 
set<node> S[maxn+5];
vector<mat> R[maxn+5]; 
int mx[maxn*4+5]; 
void upd(int p) {
	mx[p]=max(mx[p+p],mx[p+p+1]); 
}
void build(int p,int l,int r) {
	if (l==r) {
		mx[p]=-inf; 
		return ; 
	}
	int mid=(l+r)>>1;
	build(p+p,l,mid);
	build(p+p+1,mid+1,r);  
} 
void modify(int p,int l,int r,int pos,int d) {
	if (l==r) {
		mx[p]=d; return ; 
	}
	int mid=(l+r)>>1;
	if (pos<=mid) modify(p+p,l,mid,pos,d); 
	else modify(p+p+1,mid+1,r,pos,d); 
	upd(p); 
}
int query(int p,int l,int r,int pos,int d) {
	// >pos ��һ�� >=d
	if (pos>r) return -1;
	if (l==r) {
		if (mx[p]<d) return -1;
		return l; 
	}
	if (mx[p]<d) return -1; 
	int mid=(l+r)>>1;  
	if (pos>mid) return query(p+p+1,mid+1,r,pos,d); 
	else {
		int ret=query(p+p,l,mid,pos,d);
		if (ret==-1) return query(p+p+1,mid+1,r,pos,d);  
	}
} 
int main() {
	scanf("%d %d",&n,&q);
	for (int i=1;i<=n;i++) {
		scanf("%d %d %d",&a[i].x,&a[i].y,&a[i].h); 
		kx[++cntx]=a[i].x,ky[++cnty]=a[i].y; a[i].id=i; 
	}
	
	
	for (int i=1;i<=q;i++) {
		scanf("%d %d %d %d",&M[i].x1,&M[i].y1,&M[i].x2,&M[i].y2); 
		kx[++cntx]=M[i].x1,kx[++cntx]=M[i].x2;
		ky[++cnty]=M[i].y1,ky[++cnty]=M[i].y2; 
		M[i].id=i; 	
	}
	sort(kx+1,kx+cntx+1); cntx=unique(kx+1,kx+cntx+1)-kx-1;
	sort(ky+1,ky+cnty+1); cnty=unique(ky+1,ky+cnty+1)-ky-1;
	for (int i=1;i<=n;i++) {
		a[i].x=lower_bound(kx+1,kx+cntx+1,a[i].x)-kx;
		a[i].y=lower_bound(ky+1,ky+cnty+1,a[i].y)-ky;  
		addx[a[i].x].push_back(a[i]); 
		S[a[i].y].insert(a[i]); 
	}
	for (int i=1;i<=q;i++) {
	    M[i].x1=lower_bound(kx+1,kx+cntx+1,M[i].x1)-kx;
		M[i].x2=lower_bound(kx+1,kx+cntx+1,M[i].x2)-kx;
		M[i].y1=lower_bound(ky+1,ky+cnty+1,M[i].y1)-ky;
		M[i].y2=lower_bound(ky+1,ky+cnty+1,M[i].y2)-ky;
		R[M[i].x2].push_back(M[i]); 
	}
	build(1,1,cnty);
	for (int i=1;i<=cntx;i++) {
		for (auto t:addx[i]) {
			int y=t.y;
			modify(1,1,cnty,y,t.x); 
		}
		for (auto Q:R[i]) {
			int id=Q.id;
			int x1=Q.x1,y1=Q.y1,x2=Q.x2,y2=Q.y2;
			int lsty=y1-1;
			int num=0,flag=0;
			static vector<int> v; v.clear();  
			while (1) {
				int nwy=query(1,1,cnty,lsty+1,x1); 
				if (nwy>y2 || nwy==-1) break ;
				set<node>::iterator it=S[nwy].lower_bound(node(x1,0,0,0));
				for (;it!=S[nwy].end();it++) {
					node t=*it;
					if (t.x>x2) break ;
					num++;
					if (num>=LOG) {
						flag=1; break ; 
					}
					v.push_back(t.h); 
				}
				if (flag) break ; 
				lsty=nwy; 
		//		cerr<<nwy<<'\n'; 
			}
			sort(v.begin(),v.end()); 
		//	cout<<Q.id<<' '<<v.size()<<'\n'; 
			if (v.size()>=3) {
				for (int i=0;i<v.size()-2;i++) {
					if (v[i]+v[i+1]>v[i+2]) {
						flag=1; break ; 
					}
				}
			}
			ans[Q.id]=flag; 
		}
	}
	for (int i=1;i<=q;i++) {
		cout<<ans[i]<<'\n'; 
	}
	return 0;
}

/*
9 5
1 3 3
2 3 1
3 3 4
1 2 1
2 2 5
3 2 9
1 1 2
2 1 6
3 1 5
1 1 1 2
1 1 2 2
1 1 1 3
1 2 3 2
1 1 3 3
*/


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 40172kb

input:

9 5
1 3 3
2 3 1
3 3 4
1 2 1
2 2 5
3 2 9
1 1 2
2 1 6
3 1 5
1 1 1 2
1 1 2 2
1 1 1 3
1 2 3 2
1 1 3 3

output:

0
0
0
0
0

result:

wrong answer 2nd lines differ - expected: '1', found: '0'