QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#678261 | #9528. New Energy Vehicle | ucup-team045# | WA | 1ms | 3796kb | C++20 | 2.9kb | 2024-10-26 14:28:32 | 2024-10-26 14:28:33 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<set>
using namespace std;
using LL = long long;
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int T;
cin >> T;
while(T--){
int n, m;
cin >> n >> m;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
vector<LL> x(m + 1);
vector<int> t(m + 1);
for(int i = 1; i <= m; i++){
cin >> x[i] >> t[i];
}
auto check = [&](LL mid){
vector<int> last(n + 1, n + 1);
int pos = m;
while(mid <= a[pos]) pos--;
LL remain = 0;
set<pair<int, LL> > s;
for(int i = pos; i >= 0; i--){
LL len = mid - x[i];
remain += len;
s.insert({i, len});
if (i == 0){
for(int j = 1; j <= n; j++){
LL k = a[j];
while(k and !s.empty()){
auto it = s.upper_bound({last[j], 0});
if (it == s.begin()) break;
auto [x, y] = *--it;
if (y > k){
s.erase({x, y});
s.insert({x, y - k});
remain -= k;
k = 0;
}
else{
remain -= y;
k -= y;
s.erase({x, y});
}
}
}
}
else{
LL k = a[t[i]];
while(k and !s.empty()){
auto it = s.upper_bound({last[t[i]], 0});
if (it == s.begin()) break;
auto [x, y] = *--it;
if (y > k){
s.erase({x, y});
s.insert({x, y - k});
remain -= k;
k = 0;
}
else{
remain -= y;
k -= y;
s.erase({x, y});
}
}
}
last[t[i]] = i;
mid = x[i];
}
return remain == 0;
};
LL l = 0, r = 1e15;
while(l < r){
LL mid = (l + r + 1) / 2;
if (check(mid)) l = mid;
else r = mid - 1;
}
cout << r << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 3796kb
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 0 11 999999999 2000000000
result:
wrong answer 3rd lines differ - expected: '4', found: '0'