QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#697790#9528. New Energy VehiclelamkappaWA 0ms3644kbC++202.0kb2024-11-01 15:47:152024-11-01 15:47:17

Judging History

This is the latest submission verdict.

  • [2024-11-01 15:47:17]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3644kb
  • [2024-11-01 15:47:15]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
using i64 = long long;

int lowbit(int x){return x&-x;}
struct BIT{
    int n;
    std::vector<i64> node;
    BIT(int n=0){init(n);}
    void init(int n){
        this->n = n;
        node.assign(n+1, 0ll);
    }
    void add(int k, i64 v){
        if(!k){
            node[k] += v;
        }else{
            for(;k<=n;k+=lowbit(k))node[k]+=v;
        }
    }
    i64 ask(int k){
        i64 ret = node[0];
        for(;k>0;k-=lowbit(k))ret+=node[k];
        return ret;
    }
    i64 ask(int l, int r){
        if(l>r)std::swap(l,r);
        return ask(r) - ask(l-1);
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T; cin >> T;
    while(T--){
        int n, m; cin >> n >> m;
        vector<i64> a(n);
        for(auto&x : a) cin >> x;
        vector<pair<int, int>> b(m);
        for(auto&[x, t] : b){
            cin >> x >> t; t--;
        }
        // sort(b.begin(), b.end());

        BIT usage(m), storage(m);
        storage.add(0, accumulate(a.begin(), a.end(), 0ll));

        i64 ans = 0;
        unordered_map<int, int> last;
        for(int i=0, y=0; i<m; i++){
            auto[x, t] = b[i];
            auto d = x - y;
            if(usage.ask(i + 1) + d > storage.ask(i + 1)){
                ans += storage.ask(i + 1) - usage.ask(i + 1);
                break;
            }
            usage.add(i + 1, d);
            ans += d;
            auto last_usage = usage.ask(last[t] + 1, i + 1) - storage.ask(last[t] + 1, i + 1);
            auto restore = min(last_usage, a[t]);
            storage.add(i + 1, restore);
            last[t] = i + 1;
            y = x;

            // cout << format("[{}] ans:{}\n", i, ans);
            // cout << format("[{}] usage:{}, storage:{}\n", i, usage.ask(i + 1), storage.ask(i + 1));
        }
        ans += max(0ll, storage.ask(m) - usage.ask(m));
        cout << ans << '\n';
    }

    return 0;
}

详细

Test #1:

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

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: 0ms
memory: 3644kb

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'