QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#177204#6873. King's RuinsNyansAC ✓926ms13172kbC++142.9kb2023-09-12 17:42:102023-09-12 17:42:10

Judging History

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

  • [2023-09-12 17:42:10]
  • 评测
  • 测评结果:AC
  • 用时:926ms
  • 内存:13172kb
  • [2023-09-12 17:42:10]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define Un unsigned
#define For1(i,a,b) for(i=(a);i<=(b);++i) 
#define For2(i,a,b) for(i=(a);i<(b);++i) 
#define FoR1(i,a,b) for(i=(a);i>=(b);--i) 
#define FoR2(i,a,b) for(i=(a);i>(b);--i) 
#define For_L(i,x) for(int i=ft[x];i;i=nt[i])
#define fir first
#define sec second
#define mkp std::make_pair 
#define pii std::pair<int,int>
#define pb emplace_back
#define il inline
template<class T1>
il void cmax(T1&x,T1 y){if(x<y)x=y;}
template<class T1>
il void cmin(T1&x,T1 y){if(x>y)x=y;}
#define dbg(x...) fprintf(stderr,x)
#define FI using std::cin;std::ios::sync_with_stdio(0),cin.tie(0)
const int N=50011;
struct pnt{
	int x[5]={0};
	int w;
};
struct pnt_{
	pnt x;int id;
};
struct Cmp{
	int num;
	bool operator()(const pnt_ &x,const pnt_ &y)const{
		return x.x.x[num]<y.x.x[num];
	}
};
bool is(const pnt &x,const pnt &y){
	return x.x[0]<=y.x[0]&&x.x[1]<=y.x[1]&&x.x[2]<=y.x[2]&&x.x[3]<=y.x[3]&&x.x[4]<=y.x[4];
}
struct kdtnd{
	pnt mx,mn;
	int w;
};
template<class T1>
il T1 max(T1 x,T1 y){return(x<y)?y:x;}
template<class T1>
il T1 min(T1 x,T1 y){return(x>y)?y:x;}
Cmp cmp[5];
int id[N];
struct KDT{
	#define lsn o<<1,lt,mid
	#define rsn o<<1|1,mid+1,rt
	static const int SZ=1<<(int)log2(N)+2|5;
	pnt_ a[N];
	kdtnd tr[SZ];
	pnt L;int R,V,res;
	void B(int o,int lt,int rt,int di=0){
		if(lt==rt){
			tr[o].mx=tr[o].mn=a[lt].x;
			id[a[lt].id]=o;
			//printf("ID%d %d\n",a[lt].id,lt);
			return;
		}
		int mid=lt+rt>>1;
		std::nth_element(a+lt,a+mid,a+rt+1,cmp[di]);
		B(lsn,(di==4)?0:di+1);
		B(rsn,(di==4)?0:di+1);
		int i;
		For1(i,0,4){
			tr[o].mx.x[i]=max(tr[o<<1].mx.x[i],tr[o<<1|1].mx.x[i]);
			tr[o].mn.x[i]=min(tr[o<<1].mn.x[i],tr[o<<1|1].mn.x[i]);
		}
	}
	void M(int o){
		tr[o].w=V;
		while(o){
			o>>=1;
			tr[o].w=max(tr[o<<1].w,tr[o<<1|1].w);
		}
	}
	void Q(int o,int lt,int rt){
		//dbg("Q%d [%d,%d]\n",o,lt,rt);
		if(is(tr[o].mx,L)){
			//dbg("OK%d\n",tr[o].w);
			cmax(res,tr[o].w);
			return;
		}
		if(!is(tr[o].mn,L)){
			//dbg("G%d %d;%d %d;%d %d;%d %d;%d %d",tr[o].mn.x[0],L.x[0],tr[o].mn.x[1],L.x[1],tr[o].mn.x[2],L.x[2],tr[o].mn.x[3],L.x[3],tr[o].mn.x[4],L.x[4]);
			//dbg("G%d\n",tr[o].w);
			return;
		}
		int mid=lt+rt>>1;
		if(tr[o<<1].w>tr[o<<1|1].w){
			if(res<tr[o<<1].w)Q(lsn);
			if(res<tr[o<<1|1].w)Q(rsn);
		}
		else{
			if(res<tr[o<<1|1].w)Q(rsn);
			if(res<tr[o<<1].w)Q(lsn);
		}
	}
};
pnt a[N];
KDT kdt;
int T, n;
int main(){FI;int i,j,t1; 
	cin>>T;
	while (T--) {
		kdt = {};
		For1(i,0,4)cmp[i].num=i;
		cin>>n;
		For1(i,1,n){
			For1(j,0,4)cin>>a[i].x[j];
			cin>>a[i].w;
		}
		For1(i,1,n)kdt.a[i].x=a[i],kdt.a[i].id=i;
		kdt.B(1,1,n);
		For1(i,1,n){
			t1=a[i].w;
			kdt.L=a[i];
			//For1(j,0,4)dbg("%d%c",a[i].x[j]," \n"[j==4]);
			kdt.res=0;
			kdt.Q(1,1,n);
			printf("%d\n",t1+=kdt.res);
			kdt.V=t1;
			kdt.M(id[i]);
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 926ms
memory: 13172kb

input:

5
50000
29954 49457 38367 14274 40054 329
30630 36548 13832 4639 22667 5831
30320 36380 15092 40037 34720 1641
14924 15618 6335 10644 6739 3669
12197 42170 43527 35301 9465 7322
14180 40399 20609 10068 44940 3818
6559 16341 18973 46831 15552 7395
14667 37690 12809 49774 22576 7592
11896 6627 17112 3...

output:

329
5831
1641
3669
7322
3818
7395
7592
6690
17239
7847
10337
6491
14257
1471
4580
8556
14283
384
3097
9283
2194
9873
8868
12118
1145
13105
18371
4614
1654
392
9880
5823
1961
4369
3903
14903
12887
560
17986
6210
11958
4822
7419
2563
17549
15663
5192
5807
7684
15124
7256
8513
5565
4386
5607
2479
16837...

result:

ok 250000 lines