QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#436039#8793. Toiletsucup-team3586#TL 2ms9980kbC++232.3kb2024-06-08 23:04:102024-06-08 23:04:11

Judging History

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

  • [2024-06-08 23:04:11]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:9980kb
  • [2024-06-08 23:04:10]
  • 提交

answer

//泥の分際で私だけの大切を奪おうだなん
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
#define int long long
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
pair<int,int> ans[1<<18];
int a[1<<18],lst[1<<18];
struct node{int t,p,s,d;}b[1<<18];
bool vis[1<<18];
int n=read(),m=read(),L=read();
int calc(int pid,int tid)
{
	int dist=(a[tid]+L-b[pid].p)%L;
	if(!b[pid].s) dist=(L-dist)%L;
	int sdt=b[pid].t+dist;
	int require=max(0ll,lst[tid]-sdt);
	return sdt+((require+L-1)/L)*L;
}
int best_match_toliet(int x)
{
	int MN=1e18;
	int o=lower_bound(a+1,a+m+1,x)-a;
	if(a[o]==x&&b[x].s==0) ++o;
	if(b[x].s) for(int i=o; i<o+m; ++i) MN=min(MN,lst[i]-a[i]+b[x].p);
	else for(int i=o; i<o+m; ++i) MN=min(MN,lst[i]+a[i]-b[x].p-L);
	int require=max(0ll,MN-b[x].t);
	int Z=b[x].t+((require+L-1)/L)*L;
	if(b[x].s)
	{
		for(int i=o; i<o+m; ++i)
			if(-b[x].p+Z>=lst[i]-a[i])
				return (i-1)%m+1;
	}
	else
	{
		for(int i=o+m-1; i>=o; --i)
			if(b[x].p+L+Z>=lst[i]+a[i])
				return (i-1)%m+1;
	}
	assert(0);
	return -1;
}
int best_match_person(int x)
{
	int mn=1e18,id=-1;
	for(int i=1; i<=n; ++i) if(!vis[i])
	{
		int tmp=calc(i,x);
		if(tmp<mn) mn=tmp,id=i;
	}
	// assert(id!=-1);
	return id;
}
void Match(int pid,int tid)
{
	int dist=(a[tid]+L-b[pid].p)%L;
	if(!b[pid].s) dist=(L-dist)%L;
	int sdt=b[pid].t+dist;
	int require=max(0ll,lst[tid]-sdt);
	ans[pid]={a[tid],sdt+((require+L-1)/L)*L};
	lst[tid]=lst[tid+m]=
	sdt+((require+L-1)/L)*L+b[pid].d;
	vis[pid]=1;
}
signed main()
{
	for(int i=1; i<=m; ++i) a[i]=read(),a[m+i]=a[i]+L,lst[i]=-1e18;
	sort(a+1,a+m+1);
	for(int i=1; i<=n; ++i)
		b[i].t=read(),b[i].p=read(),
		b[i].s=(getchar()=='+'),b[i].d=read();
	for(int T=n; T--;)
	{
		int A=best_match_person(1);
		int B=best_match_toliet(A);
		int C=best_match_person(B);
		while(A!=C)
		{
			A=C;
			B=best_match_toliet(A),
			C=best_match_person(B);
		}
		Match(C,B);
	}
	for(int i=1; i<=n; ++i)
		printf("%lld %lld\n",ans[i].first,ans[i].second);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 9980kb

input:

5 3 45
10 20 30
0 0 + 200
2 5 + 10
20 40 - 100
21 16 + 10
50 0 + 22

output:

20 20
10 7
30 30
10 60
10 105

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 2ms
memory: 9916kb

input:

1 1 1
0
0 0 - 1

output:

0 0

result:

ok 2 number(s): "0 0"

Test #3:

score: -100
Time Limit Exceeded

input:

5 3 33
3 24 23
12 24 - 9
16 28 - 1
17 27 - 9
19 26 - 5
32 22 - 2

output:


result: