QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#880993#9528. New Energy Vehiclejmyszka#WA 96ms15004kbC++173.1kb2025-02-04 07:08:022025-02-04 07:08:02

Judging History

This is the latest submission verdict.

  • [2025-02-04 07:08:02]
  • Judged
  • Verdict: WA
  • Time: 96ms
  • Memory: 15004kb
  • [2025-02-04 07:08:02]
  • Submitted

answer

#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class A, class B>
ostream& operator<<(ostream& o, const pair<A, B>& p) {return o << '(' << p.first << ", " << p.second << ')';}
template<size_t Index = 0, typename... Types>
ostream& printTupleElements(ostream& o, const tuple<Types...>& t) {if constexpr (Index < sizeof...(Types)){if(Index > 0){o << ", ";}o << get<Index>(t);printTupleElements<Index + 1>(o, t);}return o;}
template<typename... Types>
ostream& operator<<(ostream& o, const tuple<Types...>& t){o << "(";printTupleElements(o, t);return o << ")";}
template<class T>
auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o){o << '{';bool first = true;for (const auto& e : x){if (!first){o << ", ";}o << e;first = false;} return o << '}';}
struct custom_hash {static uint64_t splitmix64(uint64_t x) {x += 0x9e3779b97f4a7c15;x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;x = (x ^ (x >> 27)) * 0x94d049bb133111eb;return x ^ (x >> 31);}
size_t operator()(uint64_t x) const {static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();return splitmix64(x + FIXED_RANDOM);}};
//#define DEBUG
#ifdef DEBUG
#define fastio()
#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
#else
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0);
#define debug(...)
#endif
typedef long long ll;
#define pi pair<int, int>
#define pll pair<ll, ll>
#define st first
#define nd second
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
void solve() {
	//ifstream cin("nazwa.in");
	//ofstream cout("nazwa.out");
	int n, m;
	cin >> n >> m;
	vi A(n + 1);
	ll sum = 0;
	vll S(n + 1);
	for(int i = 1; i <= n; i++) {
		cin >> A[i];
		S[i] = A[i];
		sum += A[i];
	}
	vll X(m + 2, 0), tp(m + 1);
	X[m + 1] = 1e18;
	vector<vi>kt(n + 1);
	for(int i = 1; i <= m; i++) {
		cin >> X[i] >> tp[i];
		kt[tp[i]].eb(i);
	}
	for(int i = 1; i <= n; i++) {
		kt[i].eb(n + 1);
	}
	auto nxt = [&](int akt, int pos) {
		auto it = upper_bound(all(kt[akt]), pos);
		return (*it);
	};
	set<pi>s;
	for(int i = 1; i <= n; i++) {
		s.insert(make_pair(nxt(i, 0), i));
	}
	for(int i = 1; i <= m + 1; i++) {
		if(X[i] - X[i - 1] > sum) {
			cout << X[i - 1] + sum << '\n';
			return;
		}
		else {
			ll akt = X[i - 1];
			while(akt < X[i]) {
				auto it = s.begin();
				auto [nas, ind] = (*it);
				if(A[ind] + akt > X[i]) {
					A[ind] -= X[i] - akt;
					sum -= X[i] - akt;
					akt = X[i];
					break;
				}
				else {
					akt += A[ind];
					sum -= A[ind];
					A[ind] = 0;
					s.erase(it);
				}
			}
			s.erase(make_pair(nxt(tp[i], i - 1), tp[i]));
			sum += S[tp[i]] - A[tp[i]];
			A[tp[i]] = S[tp[i]];
			s.insert(make_pair(nxt(tp[i], i), tp[i]));
		}
	}
}
int main() {
	fastio();
	int t = 1;
	cin >> t;
	while(t--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 96ms
memory: 15004kb

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:

1450555
1545732
1252551
1496276
1468120
1525797
1016494
1533962
1114634
1072253

result:

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