QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#684904#9528. New Energy VehiclelonelywolfWA 0ms3548kbC++201.8kb2024-10-28 16:28:412024-10-28 16:28:43

Judging History

This is the latest submission verdict.

  • [2024-10-28 16:28:43]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3548kb
  • [2024-10-28 16:28:41]
  • Submitted

answer

#include <bits/stdc++.h>  
using namespace std;  

#define int long long  

constexpr int inf = 1e18;

void solve() {
	int n, m;
	cin >> n >> m;

	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	vector<int> x(m + 1), t(m + 1);
	vector<vector<int>> l(n + 1);
	for (int i = 1; i <= m; i++) {
		cin >> x[i] >> t[i];
		l[t[i]].push_back(x[i]);
	}

	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
	for (int i = 1; i <= n; i++) {
		if (l[i].size()) {
			q.push({l[i][0], i});
		} else {
			q.push({inf, i});
		}
	}

	auto now = a;
	int ans = 0;
	for (int i = 1; i <= m; i++) {
		int d = x[i] - x[i - 1];
		while (q.size() && q.top().first <= x[i - 1]) {
			q.pop();
		}
		while (q.size() && d > 0) {
			auto [tx, id] = q.top();
			// cerr << tx << " " << id << "\n";
			if (now[id] > d) {
				ans += d;
				now[id] -= d;
				d = 0;
			} else {
				ans += now[id];
				d -= now[id];
				now[id] = 0;
				q.pop();

				int lo = -1, hi = l[id].size();
				while (lo + 1 != hi) {
					int mid = (lo + hi) / 2;
					if (l[id][mid] > tx) {
						hi = mid;
					} else {
						lo = mid;
					}
				}
				if (hi != l[id].size()) {
					q.push({l[id][hi], id});
				}
			}
		}

		if (d == 0) {
			now[t[i]] = a[t[i]];
			int lo = -1, hi = l[t[i]].size();
			while (lo + 1 != hi) {
				int mid = (lo + hi) / 2;
				if (l[t[i]][mid] > x[i]) {
					hi = mid;
				} else {
					lo = mid;
				}
			}
			if (hi != l[i].size()) {
				q.push({l[t[i]][hi], t[i]});
			}
		} else {
			break;
		}
	}

	for (int i = 1; i <= n; i++) {
		ans += now[i];
	}

	cout << ans << "\n";
}

signed main() {  
    ios::sync_with_stdio(false);
    cin.tie(nullptr);  

    int t;
    cin >> t;
    while (t--) {
    	solve();
    }

    return 0;
}  
  

详细

Test #1:

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

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: 3532kb

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
8
4
8
999999999
2000000000

result:

wrong answer 2nd lines differ - expected: '11', found: '8'