QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#723425#9528. New Energy VehicleSTASISZHYWA 89ms23876kbC++142.2kb2024-11-07 22:13:162024-11-07 22:13:16

Judging History

This is the latest submission verdict.

  • [2024-11-07 22:13:16]
  • Judged
  • Verdict: WA
  • Time: 89ms
  • Memory: 23876kb
  • [2024-11-07 22:13:16]
  • Submitted

answer

// Problem: A - New Energy Vehicle
// Contest: Virtual Judge - 思维
// URL: https://vjudge.net/contest/670080#problem/A
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

// #pragma GCC optmize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PII pair<int, int>

using namespace std;

const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;

int n, m, q, ans;
int s[N], dp[N], cy[N], lst[N], nxt[N];
bool vis[N];
PII p[N];

vector<int> e[N];
list<PII> v;

signed main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T; cin >> T;
	while(T --)
	{
		priority_queue<PII, vector<PII>, greater<> > pq;
		cin >> n >> m; int sum = 0, tag = 0; bool flag = false;
		for(int i = 1; i <= n; i ++) lst[i] = -1, nxt[i] = -1;
		// for(int i = 1; i <= n; i ++) vis[i] = false;
		for(int i = 1; i <= n; i ++) {cin >> s[i]; cy[i] = s[i];}
		for(int i = 1; i <= m; i ++) cin >> p[i].fi >> p[i].se; 
		for(int i = m; i; i --)
		{
			if(~lst[p[i].se]) nxt[i] = lst[p[i].se], lst[p[i].se] = i;
			else lst[p[i].se] = i;
			pq.push({i, p[i].se});
		}
		for(int i = 1; i <= n; i ++) pq.push({INF, i});
		for(int i = 1; i <= m; i ++)
		{
			int dis = p[i].fi - p[i - 1].fi;
			while(!pq.empty() && dis)
			{
				while(pq.top().fi < i) {pq.pop(); continue;}
				int now = pq.top().se, id = pq.top().fi;
				// cout << "dis = " << dis << " now = " << now << " left = " << s[now] << '\n';
				if(s[now] > dis) s[now] -= dis, dis = 0;
				else 
				{
					dis -= s[now], s[now] = 0; pq.pop();
					if(id == INF) continue;
					// cout << "id = " << id << " nxt = " << nxt[id] << '\n'; 
					if(~nxt[id]) v.push_back({nxt[id], now});
					else v.push_back({INF, now});
				}	
			}
			// cout << "dis = " << dis << '\n';
			if(dis) 
			{
				cout << p[i].fi - dis << '\n'; 
				flag = true; 
				break;
			}
			s[p[i].se] = cy[p[i].se];
			for(auto j : v) pq.push(j); 
			v.clear();
		}
		if(flag) continue;
		for(int i = 1; i <= n; i ++) sum += s[i];
		cout << p[m].fi + sum << '\n';
		// if(!flag) cout << p[m].fi + (sum - tag) << '\n';
	}	
	return 0;
}

详细

Test #1:

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

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: 0ms
memory: 16548kb

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

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:

1543020
1578939
1497370
1527381
1546550
1564623
797096
1548114
876935
826061

result:

wrong answer 3rd lines differ - expected: '1526016', found: '1497370'