QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#759060 | #9528. New Energy Vehicle | W_Trace2# | WA | 1ms | 6056kb | C++14 | 2.8kb | 2024-11-17 21:24:18 | 2024-11-17 21:24:18 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
ll a=0,b=1;char c=getchar();
for(;c<'0'||c>'9';c=getchar())if(c=='-')b=-1;
for(;c>='0'&&c<='9';c=getchar())a=a*10+c-'0';
return a*b;
}
struct Charge
{
ll next_sta,rest,Kind,Rank;
friend bool operator< (Charge a,Charge b)
{
return a.next_sta>b.next_sta;
}
};
ll n,m,a[100001];
priority_queue<Charge> use,charge;
vector<ll> position[100001];
ll two_point(ll x,ll place)//第一个大于的位置
{
ll l=0,r=position[x].size()-1;
while(l<r)
{
ll mid=l+r>>1;
if(position[x][mid]<=place)
l=mid+1;
else
r=mid;
}
return l;
}
int main()
{
ll T=read();
while(T--)
{
n=read(),m=read();
while(use.size()!=0)use.pop();
while(charge.size()!=0)charge.pop();
for(ll i=1;i<=n;i++)
{
a[i]=read();
position[i].clear();
}
for(ll i=1;i<=m;i++)
{
ll x=read(),y=read();
position[y].push_back(x);
}
for(ll i=1;i<=n;i++)
{
sort(position[i].begin(),position[i].end());
position[i].push_back((1LL<<60));
}
for(ll i=1;i<=n;i++)
{
Charge x;
x.Kind=i;
x.next_sta=position[i][0];
x.Rank=0;
x.rest=a[i];
use.push(x);
}
ll nowp=0;
// cout<<"?\n";
Charge tmp;
tmp.next_sta=(1LL<<60);
charge.push(tmp);
while(use.size()!=0)
{
if(use.top().rest+nowp<=min(use.top().next_sta,(charge.top().next_sta)))
{
Charge x=use.top();
use.pop();
nowp+=x.rest;
x.rest=0;
charge.push(x);
}
else
{
Charge x=use.top();
Charge y=charge.top();
if(x.next_sta<=y.next_sta)
{
use.pop();
nowp=x.next_sta;
x.rest=a[x.Kind];
x.next_sta=position[x.Kind][two_point(x.Kind,nowp)];
use.push(x);
}
else
{
use.pop();
charge.pop();
x.rest-=(y.next_sta-nowp);
nowp=(y.next_sta);
use.push(x);
y.next_sta=position[y.Kind][two_point(y.Kind,nowp)];
y.rest=a[y.Kind];
use.push(y);
}
}
}
cout<<nowp<<'\n';
}
return 0;
}
/*
1
3 1
3 3 3
8 1
1
2 2
5 2
1 2
2 1
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5928kb
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: 6056kb
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'