QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#698002#9528. New Energy VehiclelamkappaWA 18ms5644kbC++202.8kb2024-11-01 16:47:332024-11-01 16:47:34

Judging History

This is the latest submission verdict.

  • [2024-11-01 16:47:34]
  • Judged
  • Verdict: WA
  • Time: 18ms
  • Memory: 5644kb
  • [2024-11-01 16:47:33]
  • 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);
    }
    int kth(i64 v) {
        int now = 0;
        for(int i=19;i>=0;i--) {
            now += 1<<i;
            if(now > n || node[now] >= v) now -= 1<<i;
            else v -= node[now];
        }
        return now + 1;
    }
};

struct maxBIT{
    int n;
    std::vector<int> node;
    maxBIT(int n=0){init(n);}
    void init(int n){
        this->n = n;
        node.assign(n+1, 0ll);
    }
    void set(int k, int v){
        if(!k){
            node[k] = max(node[k], v);
        }else{
            for(;k<=n;k+=lowbit(k)) node[k] = max(node[k], v);
        }
    }
    int ask(int k){
        int ret = node[0];
        for(;k>0;k-=lowbit(k)) ret = max(ret, node[k]);
        return ret;
    }
};

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

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

        BIT usage(m);
        maxBIT maxi(m);
        usage.add(0, -sum);

        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 > 0){
                break;
            }
            usage.add(i + 1, d);
            ans += d;
            last[t] = max(last[t], maxi.ask(last[t]));
            auto last_usage = usage.ask(last[t] + 1, i + 1);
            auto restore = min<i64>(last_usage, a[t]);
            auto pos = usage.kth(usage.ask(last[t]) + restore);
            auto prev = usage.ask(last[t] + 1, pos - 1); 
            usage.add(pos, prev - restore);
            usage.add(last[t] + 1, -prev);
            maxi.set(last[t], pos - 1);
            last[t] = i + 1;
            y = x;

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

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 18ms
memory: 5644kb

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:

-141615
-332899
-1401468
2785
-321765
-1430824
205597
-93134
-351129
-92130

result:

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