QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#683444#9528. New Energy VehicleHHAZ#TL 0ms3528kbC++201.9kb2024-10-27 21:09:012024-10-27 21:09:02

Judging History

This is the latest submission verdict.

  • [2024-10-27 21:09:02]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 3528kb
  • [2024-10-27 21:09:01]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
#define endl '\n'
#define sz(x) (int)(x).size()
#define all(t) (t).begin(), (t).end()
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for(ll i = (a); i >= (b); --i)
#define debug(x) cout<<#x<<": "<<x<<endl
const int N=2e5+10,M=1e6+10;


pair<int,int> b[N];
int a[N];
int c[N];
void solve() 
{
	ll n,m;
	cin>>n>>m;
	stack<int> st[n+1];
	
	map<int,int>ma;
	rep(i,1,n)
	{
		cin>>a[i];
		c[i]=a[i];
	}
	rep(i,1,m)
	{
		cin>>b[i].first>>b[i].second;
	}
	per(i,m,1)
	st[b[i].second].push(b[i].first);
	int op=1;
	rep(i,1,n)
	{	
		if(st[i].size())
		{
			ma[st[i].top()]=i;
			st[i].pop();
		}
		else
		ma[1e9+(op++)]=i;
	}	
	int p=1;
	int now=0;
	while(p<=m)
	{
		auto [x,y]=*ma.begin();
		if(x<now)
		{
			ma.erase(x);
			continue;
		}
		int su=min(b[p].first-now,c[y]);

		c[y]-=su;
		now+=su;
		if(now==b[p].first)
		{
			c[b[p].second]=a[b[p].second];

			if(b[p].second==y)
			ma.erase(x);
		
			
		
			if(st[b[p].second].size())
			{
				ma[st[b[p].second].top()]=b[p].second;
				st[b[p].second].pop();
			}
			else
			{
				ma[1e9+(op++)]=b[p].second;
			}
			p++;
		}
		if(c[y]==0)
		{
			ma.erase(x);
		}
	}
	
	rep(i,1,n)
	{
		now+=c[i];
		c[i]=0;
	}
	
	cout<<now<<endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
	 cin >> T;
	//	cout.flush();
	//		ofstream outfile("C:\\Users\\86187\\OneDrive\\桌面\\1.txt");
	//		outfile << "a[1]=0;a[2]=1;";
	//		ll l = 1e7 + 1;
	//		rep(i, 3, 1e9) {
	//			printf("%lld\n", i);
	//			ll x = (i - 1) * ((a[i - 1] + a[i - 2]) % mod);
	//			x %= mod;
	//			if(i == l) {
	//				outfile << "a[" << i << "]=" << x << ";";
	//			}
	//			if(i == l + 1) {
	//				outfile << "a[" << i << "]=" << x << ";";
	//				l += 1e7;
	//			}
	//		}
	while(T--) {
		solve();
	}
	return 0;
}

详细

Test #1:

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

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: -100
Time Limit Exceeded

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:


result: