QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#696992#9528. New Energy VehicleranxiTL 0ms3540kbC++232.4kb2024-11-01 09:28:002024-11-01 09:28:00

Judging History

This is the latest submission verdict.

  • [2024-11-01 09:28:00]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 3540kb
  • [2024-11-01 09:28:00]
  • Submitted

answer

#include<bits/stdc++.h>
#define ll long long
#define alls(x) x.begin(),x.end()
#define ull unsigned long long
#define lowbit(x) x&-x
#define lc p<<1
#define rc p<<1|1
#define PII pair<int,int>
#define vi vector<int>
// #define int long long

using namespace std;
const ll inf = 2e18;
const int mod = 998244353;
const int N = 2e5+10;
struct node{
    int x;
    int id;
};
void solve()
{
    int n,m;
    cin >> n >> m;
    vi a(n+1),b(n+1);
    for(int i = 1;i<=n;i++)
    {
        cin >> a[i];
        b[i] = a[i];
    }
    vector<queue<int>>q(n+1);
    vector<node>info(m+1);
    for(int i = 1;i<=m;i++)
    {
        cin >> info[i].x >> info[i].id;
        q[info[i].id].push(info[i].x);
    }
    priority_queue<PII,vector<PII>,greater<PII>>pq;//充电站位置,编号
    for(int i = 1;i<=n;i++)
    {
        if(q[i].size())
        {
            pq.push({q[i].front(),i});
            q[i].pop();
        }
        else
        {
            pq.push({2e9,i});
        }
    }
    bool f = true;
    ll ans = 0;//现在的位置
    for(int i = 1;i<=m;i++){
        int dis = info[i].x - ans;
        int leng = 0;
        while (!q.empty()) {
            if (leng + b[pq.top().second] < dis) {
                leng += b[pq.top().second];
                b[pq.top().second] = 0;
                pq.pop();
            } else {
                b[pq.top().second] -= (dis - leng);
                if (b[pq.top().second] == 0)
                    pq.pop();
                leng = dis;
                break;
            }
        }

        // 没走到加油站
        if (leng < dis) {
            f = false;
            ans += leng;
            break;
        }
        if(!pq.empty() && pq.top().second==info[i].id)pq.pop();
        if(q[info[i].id].size())
        {
            pq.push({q[info[i].id].front(),info[i].id});
            q[info[i].id].pop();
        }
        else
        {
            pq.push({2e9,info[i].id});
        }
        b[info[i].id] = a[info[i].id];
        ans = info[i].x;
    }
    if(f){
        while(pq.size())
        {
            ans += b[pq.top().second];
            pq.pop();
        }
    }
    cout<<ans<<'\n';
}
signed main()
{
    cout<<fixed<<setprecision(6);
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1;
     cin >> _;
    while(_--)solve();
}

詳細信息

Test #1:

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

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
Time Limit Exceeded

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:


result: