QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#687005#9528. New Energy VehicleWillisRE 0ms0kbC++202.8kb2024-10-29 16:43:072024-10-29 16:43:07

Judging History

This is the latest submission verdict.

  • [2024-10-29 16:43:07]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-10-29 16:43:07]
  • Submitted

answer

#ifdef local
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#endif
// #pragma comment(linker, "/STACK:102400000,102400000")

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#ifndef local
#define endl '\n'
#endif

#define pb emplace_back
#define fi first
#define se second
#define rep(i, l, r) for (long long i = l; i <= r; i++)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mem(a, x) memset(a, x, sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
const double pi = acos(-1);
typedef __int128_t int128;
const db eps = 1e-9;
std::mt19937_64 rng(time(0));
ll my_random(ll l, ll r)
{

	uniform_int_distribution<int> range(l, r);
	return range(rng);
}
void __()
{
#ifdef local
	system("pause");
#endif
}
ll qp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while (b)
	{
		if (b & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}

const int maxn = 1e5 + 10;
int n, m;
ll a[maxn];
ll x[maxn], t[maxn];
ll mx[maxn];
vector<int> vec[maxn];
ll pos[maxn];
int main()
{
	IOS;
	int _;
	cin >> _;
	while (_--)
	{
		cin >> n >> m;
		for (int i = 1; i <= n + 5; i++)
			vec[i].clear(), pos[i] = 0;
		for (int i = 1; i <= n; i++)
		{
			cin >> a[i];
			mx[i] = a[i];
		}
		for (int i = 1; i <= m; i++)
		{
			cin >> x[i] >> t[i];
			vec[t[i]].pb(i);
		}
		x[m + 1] = 2e18;
		priority_queue<P, vector<P>, greater<P>> q;
		for (int i = 1; i <= n; i++)
		{
			if (vec[i].size() == 0)
				q.push(P{n + i, i});
			else
				q.push(P{vec[i][pos[i]], i}), pos[i]++;
		}
		ll ans = 0;
		int flg = 1;
		while (q.size())
		{
			P p = q.top();
			q.pop();
			int pos2 = p.se; // use dianping
			ll length = a[pos2];
			ll canrun = min(x[flg] - ans, length);
			ans += canrun;
			if (ans == x[flg])
			{
				a[pos2] -= canrun;
				int chongdian = t[flg];
				a[chongdian] = mx[chongdian]; // chongdian
				if (a[pos2] != 0 && pos2 != chongdian)
				{
					q.push(P{vec[p.fi][pos[p.fi]], pos2});
				}
				if (pos[chongdian] == vec[chongdian].size())
					q.push(P{n + chongdian, chongdian});
				else
					q.push(P{vec[chongdian][pos[chongdian]], chongdian}), pos[chongdian]++;
				flg++;
			}
			else
			{
				a[pos2] -= canrun;
			}
		}
		cout << ans << endl;
	}
	__();
	return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

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

output:


result: