QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#770032#9528. New Energy VehiclezhishengWA 0ms3584kbC++231.6kb2024-11-21 20:22:182024-11-21 20:22:18

Judging History

This is the latest submission verdict.

  • [2024-11-21 20:22:18]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3584kb
  • [2024-11-21 20:22:18]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    ios::sync_with_stdio(false),cout.tie(nullptr),cin.tie(nullptr);
    auto solve=[&]() {
        int n,m;
        cin >> n >> m;
        vector <int> a(n + m + 10),now(n + m+ 10),pos(n + m + 10);
        vector <int> xi(m + n + 10),lst(n + m + 10),nxt(m + n + 10),fir(n + m+ 10);
        for(int i=1;i<=n;i++) cin >> a[i],now[i] = a[i];
        for(int i=1;i<=m;i++) cin >> pos[i] >> xi[i];
        for(int i=1;i<=n;i++) fir[i] = m + 1,lst[i] = 0;
        for(int i=1;i<=m;i++) {
            if( fir[xi[i]] > m ) fir[xi[i]] = i;
        }
        set <pair<int,int>> s;
        for(int i=1;i<=n;i++) {
            s.insert(pair<int,int>(fir[i],i));
        }
        int sum = 0;
        for(int i=1;i<=m;i++) {
            int r = pos[i] - pos[i-1];
            while(!s.empty() && now[s.begin()->second] <=r) {
                int k = s.begin()->second;
                sum += now[k];
                r -= now[k];
                now[k] = 0;
                s.erase(s.begin());
            }
            if(s.empty() && r > 0) {
                cout << sum << "\n";
                return;
            }
            now[s.begin()->second] -= r;
            sum += r;
            now[xi[i]] = a[xi[i]];
            if(s.find(pair<int,int>(i,xi[i]))!=s.end()) {
                s.erase(pair<int,int>(i,xi[i]));
            }
        }
        for(int i=1;i<=n;i++) sum += now[i];
        cout << sum << "\n";

    };
    int t = 1;
    cin>>t;
    while(t--) {
       solve();
    }
    return 0;
}

详细

Test #1:

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

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

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:

6
5
4
5
999999999
2000000000

result:

wrong answer 1st lines differ - expected: '9', found: '6'