QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#702122#9528. New Energy Vehiclesea_bird#WA 1ms3664kbC++202.5kb2024-11-02 15:21:012024-11-02 15:21:02

Judging History

This is the latest submission verdict.

  • [2024-11-02 15:21:02]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3664kb
  • [2024-11-02 15:21:01]
  • Submitted

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'