QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#702122 | #9528. New Energy Vehicle | sea_bird# | WA | 1ms | 3664kb | C++20 | 2.5kb | 2024-11-02 15:21:01 | 2024-11-02 15:21:02 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
using pll = std::pair<ll,ll>;
const int maxn = 1e5 + 1000;
ll a[maxn];
std::vector<int>pos[maxn];
pll b[maxn];
int nxt[maxn];
struct info{
ll next;
ll val;
ll id;
bool operator<(const info&oth)const{
if(next != oth.next)return next < oth.next;
if(val != oth.val)return val < oth.val;
return id < oth.id;
}
};
void solve(){
ll n,m;
std::cin >> n >> m;
for(int i = 1;i <= n;i++){
pos[i].clear();
nxt[i] = 0;
}
for(int i = 1;i<=n;i++){
std::cin >> a[i];
}
for(int i = 1;i <= m;i++){
std::cin >> b[i].first >> b[i].second;
pos[b[i].second].push_back(i);
}
for(int i = 1;i <= m;i++){
for(int j = (int)pos[i].size() - 1;j >= 0;j--){
if((j + 1) != pos[i].size()){
nxt[pos[i][j]] = pos[i][j + 1];
}
else{
nxt[pos[i][j]] = 1e9;
}
}
}
std::set<info>s;
for(int i = 1;i <= n;i++){
if(pos[i].empty()){
s.insert(info{n + 1,a[i],i});
}
else{
s.insert(info{pos[i][0],a[i],i});
}
}
ll ans = 0LL;
for(int i = 1;i <= n;i++){
if(s.empty())break;
ll use = b[i].first - b[i-1].first;
while(use > 0 and !s.empty()){
auto iter = s.begin();
auto [next,val,id] = *iter;
if(use >= val){
use -= val;
ans += val;
s.erase(s.find(*iter));
continue;
}
s.erase(s.find(*iter));
val -= use;
ans += use;
use = 0;
s.insert(info{next,val,id});
}
if(use > 0 and !s.empty())break;
auto iter = s.lower_bound(info{i,0,0});
if(iter->id != b[i].second){
s.insert(info{nxt[i],a[b[i].second],b[i].second});
}
else{
auto item = *iter;
s.erase(s.find(item));
item.val = a[b[i].second];
item.next = nxt[i];
s.insert(item);
}
}
while(!s.empty()){
auto item = *s.begin();
s.erase(s.find(item));
ans += item.val;
}
std::cout << ans << "\n";
}
int main(){
std::ios::sync_with_stdio(0);
std::cin.tie(0),std::cout.tie(0);
int t;
std::cin >> t;
while(t--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3652kb
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: 3664kb
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 8 11 1999999998 2000000000
result:
wrong answer 3rd lines differ - expected: '4', found: '8'