QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#696380#9528. New Energy VehiclewirepullerWA 0ms3848kbC++143.4kb2024-10-31 22:20:272024-10-31 22:20:27

Judging History

This is the latest submission verdict.

  • [2024-10-31 22:20:27]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3848kb
  • [2024-10-31 22:20:27]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define mp make_pair
#define endl '\n'
#define dbug() cout << '||||||debug|||||' << endl;
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
const int N = 1e5+10;
const int mod = 1e9+7;
const int INF = 1e18;
struct node{
    int pos, xi;
};
void solve()
{
    int n, m, k;
    cin >> n >> m;
    vi a(n+1);
    int res = 0;
    vi now(n+1);
    for (int i = 1; i<=n; i++){
        cin >> a[i];
        now[i] = a[i];
    }
    vector<node> v(m+1);
    vector<int> vis(n+1, 0);
    map<int, int> mp;
    int pre = 0;
    for (int i = 1; i<=m; i++){
        int o;
        cin >> o >> v[i].xi;
        v[i].pos = o-pre;
        pre = o;
        vis[v[i].xi] = 1;    
        // cout << v[i].pos << endl;  
    }
    
    // sort(v.begin(), v.end(), [](node a, node b){
    //     return a.pos < b.pos;
    // });
    queue<int> q;
    
    for (int i = 1; i<=m; i++){
        q.push(v[i].xi);
        mp[v[i].xi]++;
    }
    for (int i = 1; i<=n; i++){
        if (!vis[i]){
            q.push(i);
            mp[i]++;
        }
    }
    
    // cout << "()" << q.size() << endl;
    // while (q.size() > 0){
    //     int top = q.front();
    //     cout << "(" << top << ",";
    //     q.pop();
    // }
    // return ;
    // while (q.size()>0){
    //     cout << q.front() << " ";
    //     q.pop();
    // }
    // int top = q.front();
    // q.pop();
    int top;
    int num = 0;
    for (int i = 1; i<=m; i++){
        // cout << v[i].pos << endl;
        if (i > num){
            // q.push(top);
            top = q.front();
            mp[top]--;
            q.pop();
            num++;
        }
        // cout << q.size() << endl;
        // cout << "top=" << top << endl;
        while (v[i].pos > 0){
            // cout << "top=" << top << endl;
            int mi = min(now[top], v[i].pos);
            now[top] -= mi;
            res += mi;
            v[i].pos -= mi;
            if (now[top] == 0 && q.size() > 0){
                top = q.front();
                // cout << "top=" << top << endl;
                mp[top]--;
                q.pop();
                num++;
            }
            if (q.size()==0 && v[i].pos-now[top] > 0){
                cout << res+now[top] << endl;
                cout << "----" << endl;
                return ; 
            }
            // cout << "===" << q.size() << endl;
            // cout << v[i].pos << endl;
        }
        now[v[i].xi] = a[v[i].xi];
        mp[v[i].xi]++;
        // cout <<"q.size()="<< q.size() << endl;
        // cout <<"v[i].xi=" << v[i].xi << endl;
        q.push(v[i].xi);
        // cout << res << endl;
    }
    // cout << "........" << q.size() << endl;
    // cout << top << endl;
    if (!mp[top]){
        res += now[top];
    }
    // cout << top << endl;
    // cout << res << endl;
    while (q.size() > 0){
        top = q.front();
        // cout << top << " ";
        q.pop();
        res = res + now[top];
        now[top] = 0;
        // cout << res << endl;
    }
    cout << res << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    
    return 0;
}

详细

Test #1:

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

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

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:

wrong answer 4th lines differ - expected: '11', found: '----'