QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#689337#9528. New Energy VehicleSwd146296#WA 1ms5612kbC++141.7kb2024-10-30 16:26:092024-10-30 16:26:10

Judging History

This is the latest submission verdict.

  • [2024-10-30 16:26:10]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5612kb
  • [2024-10-30 16:26:09]
  • Submitted

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define int long long
using namespace std;
typedef pair<int,int> PII;
const int MX=100020;
const int inf=1e18;


int N, M, T;
int ar[MX], now[MX];
int read()
{
    int r=0, f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
    return r*f;
}
struct node
{
    int x, t, c;
    bool operator < (const node &a)const {return x<a.x;}
}pos[MX];
struct node2
{
    int l, r;
    bool operator < (const node2 &a)const {return r<a.r;}
};
priority_queue<node2> q;
signed main()
{
    // freopen("testdata.in","r",stdin);
    T=read();
    while(T--)
    {
        N=read(); M=read();
        int ans=0;
        for(int i=1;i<=N;i++) ar[i]=read(), ans+=ar[i];
        for(int i=1;i<=N;i++) now[i]=0;
        while(!q.empty()) q.pop();
        for(int i=1;i<=M;i++)
        {
            pos[i].x=read();
            pos[i].t=read();
            pos[i].c=min(ar[pos[i].t],pos[i].x-now[pos[i].t]);
            int l=pos[i].x-pos[i].c, r=pos[i].x; //[l,r] inclusive
            while(!q.empty())
            {
                auto [lq,rq]=q.top();
                if(rq<=l) break;
                else if(lq<l&&rq>l) {pos[i].c-=rq-l; l=lq; q.pop();}
                else if(lq>=l) {pos[i].c-=(rq-lq); q.pop();} 
            }
            q.push({l,r});
            now[pos[i].t]=pos[i].x;
        }
        sort(pos+1,pos+1+M);
        for(int i=1;i<=M;i++)
        {
            if(ans>pos[i].x) ans+=pos[i].c;
        }
        cout << ans << '\n';
    }
    return (0-0);
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5612kb

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

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
11
4
11
999999999
1000000000

result:

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