QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#666289#9450. Balloon Robotucup-team4975#AC ✓128ms7432kbC++232.4kb2024-10-22 17:35:102024-10-22 17:35:10

Judging History

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

  • [2024-10-22 17:35:10]
  • 评测
  • 测评结果:AC
  • 用时:128ms
  • 内存:7432kb
  • [2024-10-22 17:35:10]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
using namespace std;

const int N=100010;
typedef long long ll;
const ll inf=1000000000000000000ll;
int n,m,p,a[N],b[N];
struct Node{
	int id,t;
}c[N];

struct Ele{
	int id,aid,tim; //队伍编号 入队时的等待时间
	Ele(int _id,int _aid,int _tim):id(_id),aid(_aid),tim(_tim){}
	inline bool operator<(const Ele that){
		return tim<that.tim;
	}
};
deque<Ele>q;
vector<Ele>init;

//获得x位置 + val 的位置 (下标1..m)
inline int getpos(int x,int val)
{
	val=(val%m+m)%m;
	x+=val;
	if(x>m)x-=m;
	return x;
}

//y是机器人位置 x是队伍 
inline int dis(int x,int y)
{
	if(x>=y)return x-y;
	else return m-y+x-1+1;
}

int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d%d",&n,&m,&p);
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]);
		
		for(int i=1;i<=p;i++)
			scanf("%d%d",&c[i].id,&c[i].t),c[i].t%=m,b[i]=getpos(a[c[i].id],-c[i].t);
		sort(b+1,b+1+p);
		int tot=unique(b+1,b+1+p)-b-1;
		//cout<<"b ";
		//for(int i=1;i<=tot;i++)
		//	cout<<b[i]<<" ";
		//cout<<endl;

		while(q.size())q.pop_back();
		init.clear();
		int st=b[1];    //机器人第一个开始的位置是 位置最小的队伍的位置-1
		ll posans=0,q1sum=0,q2sum=0,cnt=0;   //cnt是q2里元素的个数
		ll ans=inf;
		for(int i=1;i<=p;i++)
		{
			int d=dis(a[c[i].id],getpos(st,c[i].t));
			//cout<<"i "<<d<<endl;
			posans+=1ll*d;
			init.push_back(Ele(i,c[i].id,d));
		}
		
		ans=min(ans,posans);
		q1sum=posans;
		//cout<<q1sum<<" "<<q2sum<<" "<<cnt<<" "<<posans<<endl;
		sort(init.begin(),init.end());
		for(auto pos:init)
			q.push_back(pos);
		int lstst=b[1];
		for(int i=2;i<=tot;i++)
		{
			int posst=b[i];
			q2sum-=cnt*(1ll*posst-lstst);
			while(q.size()&&q.front().tim<posst-st)
			{
				Ele pos=q.front();
				q1sum-=pos.tim;
				//cout<<"while "<<pos.id<<" "<<c[pos.id].t<<" "<<getpos(b[i],c[pos.id].t)<<\
					" "<<dis(a[pos.aid],getpos(b[i],c[pos.id].t))<<endl;

				q2sum+=dis(a[pos.aid],getpos(b[i],c[pos.id].t));
				cnt++;
				q.pop_front();
			}
			
			int siz=q.size();
			posans=q1sum-1ll*siz*(1ll*posst-st)+q2sum;
			//cout<<q1sum<<" "<<q2sum<<" "<<cnt<<" "<<posans<<endl;
			ans=min(ans,posans);
			lstst=b[i];
		}
		printf("%lld\n",ans);
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

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

input:

4
2 3 3
1 2
1 1
2 1
1 4
2 3 5
1 2
1 1
2 1
1 2
1 3
1 4
3 7 5
3 5 7
1 5
2 1
3 3
1 5
2 5
2 100 2
1 51
1 500
2 1000

output:

1
4
5
50

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 128ms
memory: 7432kb

input:

1004
22 9426 26
1165 5248 8331 9055 1161 7381 2188 7489 5131 8434 2166 3981 6302 7188 4858 856 7797 9129 7839 1676 25 9053
20 6
22 68
12 16
11 63
17 49
5 10
21 68
17 80
18 18
10 28
15 55
14 80
1 45
21 67
5 74
13 4
3 34
7 80
9 95
5 52
8 31
2 53
7 22
5 99
20 66
12 2
33 9526 92
558 7460 280 7952 5186 9...

output:

94067
360219
223074
30971
171844
312753
0
158169
294738
291604
115632
59327
221328
287851
30518
337118
181724
249419
66367
10347
208411
180496
287130
40736
264604
278208
33792
191523
111583
31867
21143
232153
149868
191831
238832
63626
258936
133059
105618
237774
53942
342921
275883
110295
149350
20...

result:

ok 1004 lines

Extra Test:

score: 0
Extra Test Passed