QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691315#9528. New Energy VehicleWillisWA 89ms13604kbC++202.8kb2024-10-31 10:56:112024-10-31 10:56:11

Judging History

This is the latest submission verdict.

  • [2024-10-31 10:56:11]
  • Judged
  • Verdict: WA
  • Time: 89ms
  • Memory: 13604kb
  • [2024-10-31 10:56:11]
  • 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{m + 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;
			a[pos2] -= canrun;
			if (ans == x[flg])
			{
				int chongdian = t[flg];
				a[chongdian] = mx[chongdian]; // chongdian
				if (a[pos2] != 0 && pos2 != chongdian)
				{
					if (pos[pos2] == vec[pos2].size())
						q.push(P{m + pos2, pos2});
					else
						q.push(P{vec[pos2][pos[pos2]], pos2});
				}
				if (pos[chongdian] == vec[chongdian].size())
					q.push(P{m + chongdian, chongdian});
				else
					q.push(P{vec[chongdian][pos[chongdian]], chongdian}), pos[chongdian]++;
				flg++;
			}
		}
		cout << ans << endl;
	}
	__();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 5740kb

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: 89ms
memory: 13604kb

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:

1516953
1569027
1310905
1517414
1507111
1551635
929794
1539161
1024304
982089

result:

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