QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#693616#9528. New Energy VehicleLmR308WA 0ms3700kbC++172.2kb2024-10-31 16:28:052024-10-31 16:28:08

Judging History

This is the latest submission verdict.

  • [2024-10-31 16:28:08]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3700kb
  • [2024-10-31 16:28:05]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define int128 __int128_t
#define int long long
#define PII pair<int, int>
#define PDD pair<double, double>
#define fi first    
#define se second
#define lowbit(x) x & -x
#define all(x) x.begin(), x.end()
#define INF 0x3f3f3f3f3f3f3f3f
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define ull unsigned long long
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 10, M = 5e6 + 10, mod = 998244353;
const double eps = 1e-8;

int t, n, m, k;	
string sr;

void solve() {
	cin >> n >> m;
	vector<int> a(n + 1), left(n + 1, 0);
	map<int, vector<int>> mp;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		left[i] = a[i];
	}
	vector<PII> b(m + 1);
	for (int i = 0; i < m; i++) {
		cin >> b[i].fi >> b[i].se;
		b[i].se -= 1;
	}
	b[m].fi = INF, b[m].se = 0;
	sort(all(b));
	priority_queue<PII, vector<PII>, greater<PII>> less;
	for (int i = 0; i < m; i++) {
		less.push({i, b[i].se});
		mp[b[i].se].push_back(i);
	}
	for (int i = 0; i < n; i++) mp[i].push_back(m + 1);
	for (int i = 0; i < n; i++) less.push({m + 1, i});
	int res = 0, pos = 0, last = 0;
	for (int i = 0; i < n; i++)
		res += a[i];
	int npos = 0;
	while (pos <= m) {
		int dist = b[pos].fi - last;
		int sum = 0;
		npos = max(npos, pos);
		while (less.size()) {
			auto [dis, idx] = less.top();
			less.pop();
			if (dis <= pos) continue;
			if (sum + left[idx] >= dist) {
				left[idx] -= (dist - sum);
				if (left[idx] > 0) {
					int nid = upper_bound(all(mp[idx]), pos) - mp[idx].begin();
					less.push({mp[idx][nid], idx});
				}
				sum = dist;
				break;
			}
			else {
				sum += left[idx];
				left[idx] = 0;
			}
		}
		if (sum == dist) {
			res += (a[b[pos].se] - left[b[pos].se]);
			left[b[pos].se] = a[b[pos].se];
			last = b[pos].fi;
			int idx = upper_bound(all(mp[b[pos].se]), pos) - mp[b[pos].se].begin();
			less.push({mp[b[pos].se][idx], b[pos].se});
			pos++;
		}
		else break;
	}
	cout << res << "\n";
}

signed main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	cout.setf(ios::fixed), cout.precision(10);
	t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}	

详细

Test #1:

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

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
Wrong Answer
time: 0ms
memory: 3664kb

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:

8
9
4
9
999999999
2000000000

result:

wrong answer 1st lines differ - expected: '9', found: '8'