QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#678248#9528. New Energy Vehicleucup-team4504#WA 1ms5640kbC++142.5kb2024-10-26 14:26:072024-10-26 14:26:07

Judging History

This is the latest submission verdict.

  • [2024-10-26 14:26:07]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5640kb
  • [2024-10-26 14:26:07]
  • Submitted

answer

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int Mod = 998244353;
inline void uadd(int &a, const int &b){ a += b - Mod; a += (a>>31) & Mod; }
inline int add(int a, const int &b){ a += b - Mod; a += (a>>31) & Mod; return a; }
inline void usub(int &a, const int &b){ a -= b; a += (a>>31) & Mod; }
inline int sub(int a, const int &b){ a -= b, a += (a>>31) & Mod; return a; }
inline void umul(int &a, const int &b){ a = (int)(1ll * a * b % Mod); }
inline int mul(const int &a, const int &b){ return (int)(1ll * a * b % Mod); }
int qpow(int b, ll p){ int ret = 1; while(p){ if(p & 1) umul(ret, b); umul(b, b), p >>= 1; } return ret; }
const int fN = 10010;
int fact[fN], invfact[fN], inv[fN];
void initfact(int n){
	fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = mul(fact[i - 1], i);
	invfact[n] = qpow(fact[n], Mod - 2); for(int i = n; i > 0; --i) invfact[i - 1] = mul(invfact[i], i);
	for(int i = 1; i <= n; ++i) inv[i] = mul(invfact[i], fact[i - 1]);
}
inline int binom(int n, int m){ return mul(fact[n], mul(invfact[m], invfact[n - m])); }

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
template<typename T> inline void chmax(T &_a, const T &_b){ (_b>_a) ? (_a=_b) : _a; }
template<typename T> inline void chmin(T &_a, const T &_b){ (_b<_a) ? (_a=_b) : _a; }

int n, m;
int a[100100], t[100100];
ll x[100100], cur[100100];
int lst[100100], nxt[100100];

void solve(){
	cin >> n >> m;
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> x[i] >> t[i], --t[i];
	x[m] = INF;
	rep(i, n) lst[i] = m;
	for(int i = m - 1; i >= 0; --i){
		nxt[i] = lst[t[i]], lst[t[i]] = i;
	}
	priority_queue< pii, vector<pii>, greater<pii> > pq;
	rep(i, n){
		cur[i] = a[i];
		pq.push(make_pair(lst[i], i));
	}
	int p = -1; ll d = 0;
	while(!pq.empty()){
		int tt = pq.top().first, id = pq.top().second;
		//cout << ": " << tt << " " << id << "\n";
		if(lst[id] != tt){
			pq.pop();
			continue;
		}
		if(d + cur[id] > x[p + 1]){
			//cout << " ??-= " << x[p + 1] - d << " " << d << "\n";
			cur[id] -= x[p + 1] - d;
			d = x[p + 1];
			++p;
			lst[t[p]] = nxt[p];
			cur[t[p]] = a[t[p]];
			pq.push(make_pair(lst[t[p]], t[p]));
		} else {
			//cout << " ::-= " << cur[id] << " " << d << "\n";
			d += cur[id];
			cur[id] = 0;
			pq.pop();
		}
	}
	cout << d << "\n";
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int T;
	cin >> T;
	while(T--) solve();

	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5532kb

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

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:

6
11
4
11
999999999
1000000000

result:

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