QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#712142#9528. New Energy Vehicle2018haha#WA 2ms11900kbC++202.7kb2024-11-05 14:40:472024-11-05 14:40:47

Judging History

This is the latest submission verdict.

  • [2024-11-05 14:40:47]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 11900kb
  • [2024-11-05 14:40:47]
  • Submitted

answer

#include<bits/stdc++.h>

using namespace std;

const int N=500010;

int n,m;
int a[N];
pair<int,int> b[N];
int now[N];
int t[N];
vector<int> p[N];
int ls(int u)
{
    return u<<1;
}
int rs(int u)
{
    return u<<1|1;
}
void Pushup(int u)
{
    t[u]=min(t[ls(u)],t[rs(u)]);
}
void Build(int u,int l,int r)
{
    if(l==r)
    {
        t[u]=1000000010;
        return;
    }
    int mid=(l+r)/2;
    Build(ls(u),l,mid);
    Build(rs(u),mid+1,r);
    Pushup(u);
}
void Modify(int u,int l,int r,int p,int k)
{
    if(l==r)
    {
        t[u]=k;return;
    }
    int mid=(l+r)/2;
    if(p<=mid) Modify(ls(u),l,mid,p,k);
    else Modify(rs(u),mid+1,r,p,k);
    Pushup(u);
}

void Solve()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        p[i].clear();
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=m;i++)
    {
        auto &[pos,col]=b[i];
        cin>>pos>>col;
        p[col].push_back(i);
    }
    Build(1,1,n);
    for(int i=1;i<=n;i++)
        now[i]=a[i];
    for(int i=1;i<=n;i++)
        if(p[i].size())
        {
            reverse(p[i].begin(),p[i].end());
            Modify(1,1,n,i,p[i].back());
            // cerr<<"Col: "<<i<<" "<<p[i].back()<<"\n";
        }
    int cur=0,pid=1;
    while(1)
    {
        // cerr<<cur<<" "<<pid<<"========\n";
        while(pid<=m && cur>=b[pid].first)
        {
            auto [pos,col]=b[pid];
            if(cur==pos)// get b[pid]
            {
                now[col]=a[col];
            }
            pid++;
        }
        //b[pid] is the next station
        if(pid>m) break;
        while(t[1]<=m && b[t[1]].first<=cur)
        {
            // cerr<<t[1]<<"#\n";
            auto [_,col]=b[t[1]];
            if(p[col].size())
            {
                Modify(1,1,n,col,p[col].back());
                p[col].pop_back();
            }
            else
            {
                Modify(1,1,n,col,1000000000);
            }
        }
        int id=t[1];
        // use col of the id station
        if(id>m) break;
        auto [_,col]=b[id];
        // cerr<<"col="<<col<<"\n";
        int go=min(now[col],b[pid].first-cur);
        // cerr<<"go=min:"<<now[col]<<" "<<b[pid].first-cur<<"\n";
        cur+=go;
        now[col]-=go;
        if(now[col]==0) Modify(1,1,n,col,1000000000);
    }
    for(int i=1;i<=n;i++)
        cur+=now[i];
    while(pid<=m)
    {
        auto [pos,col]=b[pid];
        if(cur>=pos) cur+=a[col],pid++;
        else break;
    }
    cout<<cur<<"\n";
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 11900kb

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:

10
11
4
11
999999999
2000000000

result:

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