QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#687663#9528. New Energy VehicleFyeausWA 109ms18752kbC++202.4kb2024-10-29 20:18:052024-10-29 20:18:06

Judging History

This is the latest submission verdict.

  • [2024-10-29 20:18:06]
  • Judged
  • Verdict: WA
  • Time: 109ms
  • Memory: 18752kb
  • [2024-10-29 20:18:05]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,f[1000005];
int b[1000005];
struct node
{
	int x,y;
}t[1000005];
int cmp(node a,node b)
{
	return a.x<b.x;
}
inline int read()
{
	int x=0,f=1;
	char v=getchar();
	while(!isdigit(v))
	{
        if(v=='-')
        f=-1;
        v=getchar();
	}
	while(isdigit(v))
	{
		x=x*10+v-'0';
		v=getchar();
	}
	return x*f;
}
signed main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int tot[100005]={0};
		int ans=0;
		vector<vector<int> >v{100005}; 
		priority_queue<pair<int,int> >q;
		cin>>n>>m;
		for(int i=1;i<=n;i++)
		{
			cin>>f[i];
			b[i]=f[i];
		}
		for(int i=1;i<=m;i++)
		{
			cin>>t[i].x>>t[i].y;
		}
		int sum=0;
		sort(t+1,t+m+1,cmp);
		for(int i=1;i<=m;i++)
		{
			if(!tot[t[i].y])
			{
				q.push(make_pair(-t[i].x,t[i].y));
				tot[t[i].y]=1;//下一个应该放的 
				
			}
			v[t[i].y].push_back(t[i].x);
		}
		for(int i=1;i<=n;i++)
		{
			if(tot[i]==0)
			sum+=f[i];
		}
//		cout<<sum<<endl;
		int now=0;//当前位置 
		for(int i=1;i<=m;i++)
		{
			int xx=0;//从pq中拿出的距离
			while(q.size()&&xx<t[i].x-now)
			{
//				cout<<i<<" "<<1<<endl;
				int numx=-q.top().first,numy=q.top().second;
				q.pop();
				if(t[i].x>numx)
				{
					if(tot[numy]==v[numy].size())
					{
						sum+=b[numy];
						continue;
					}
					else
					{
						q.push(make_pair(v[numy][tot[numy]],numy));
						tot[numy]++;
						continue;
					}
				}
				if(xx+b[numy]>t[i].x-now)
				{
//					cout<<1<<endl;
					b[numy]-=t[i].x-now-xx;
					q.push(make_pair(-numx,numy));
					xx=t[i].x-now;
					break;
				}
				else
				{
					xx+=b[numy];
					b[numy]=0;
					if(xx==t[i].x-now)
					break;
				}
			}
//			cout<<i<<" "<<xx<<" "<<t[i].x<<" "<<endl; 
//			cout<<sum<<" "<<xx<<endl;
			if(xx<t[i].x-now)
			{
				if(sum+xx>=t[i].x-now)
				{
//					cout<<1;
					sum-=t[i].x-now-xx;
					now=t[i].x;
//					ans=t[i].x;
				}
				else
				{
//					cout<<1<<endl;
					ans=now+xx+sum;
					break;
				}
			}
			else
			{
				now=t[i].x;
			}
			if(i==m)
			ans=now+sum+f[t[i].y];
			b[t[i].y]=f[t[i].y];
			if(q.size()&&-q.top().first==t[i].x)
			q.pop(); 
			if(tot[t[i].y]!=v[t[i].y].size())
			{
				q.push(make_pair(-v[t[i].y][tot[t[i].y]],t[i].y));
			}
			else
			{
				sum+=f[t[i].y];
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
/*
1
3 3
2 2 2
6 1
7 2
8 3
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

output:

12
9

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 11020kb

input:

6
3 2
2 2 2
6 1
7 1
2 2
3 3
2 1
6 2
2 3
2 2
5 1
7 2
9 1
2 2
3 3
2 1
6 2
1 1
999999999
1000000000 1
1 1
1000000000
1000000000 1

output:

9
11
4
11
999999999
2000000000

result:

ok 6 lines

Test #3:

score: -100
Wrong Answer
time: 109ms
memory: 18752kb

input:

10
230 8042
599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...

output:

18348720
37205134
2617263
46916660
15627764
48416531
1051729
58726622
1114655
1072415

result:

wrong answer 1st lines differ - expected: '1543020', found: '18348720'