QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#687254 | #9528. New Energy Vehicle | asui_ | WA | 2ms | 11808kb | C++20 | 2.1kb | 2024-10-29 17:50:47 | 2024-10-29 17:50:54 |
Judging History
answer
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<unordered_map>
#include<map>
#include<set>
#include<unordered_set>
#include<cmath>
#include<vector>
#include<deque>
#include<bitset>
#include<stack>
#include<cassert>
#include<ctime>
#define int long long
using namespace std;
typedef long long LL;
typedef pair<int,int>PII;
typedef pair<double,double>PDD;
typedef unsigned long long ULL;
int n,m;
int a[200010],bka[200010];
int x[200010],t[200010];
int sum[200010],sum2[200010];
bool vis[200010];
signed main()
{
cin.tie(0);cout.tie(0);
ios::sync_with_stdio(false);
int T;
cin>>T;
while(T--){
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i],bka[i]=a[i],sum[i]=vis[i]=0;
a[n+2]=1e18;
for(int i=1;i<=m;i++)cin>>x[i]>>t[i];
a[n+1]=0;
for(int i=1;i<=m;i++){
vis[t[i]]=true;
}
for(int i=1;i<=n;i++){
if(!vis[i])a[n+1]+=a[i];
}
// cout<<"a[n+1]="<<a[n+1]<<endl;
vector<int>q;
q.push_back(n+2);
q.push_back(n+1);
for(int i=m;i>=1;i--)q.push_back(t[i]),sum2[t[i]]++;
int ed=0;
bool flag=false;
for(int i=1;i<=m;i++){
int d=x[i]-x[i-1];
while(d){
int top=q.back();
q.pop_back();
if(top==n+2){
//cout<<"top="<<top<<endl;
ed=x[i]-d;
flag=true;
break;
}
if(a[top]<=d){
// cout<<"top="<<top<<endl;
// if(a[top]==0&&sum2[top]==0)continue;
d-=a[top];
a[top]=0;
sum[top]++;
// sum2[top]--;
}
else{
// cout<<"top="<<top<<endl;
a[top]-=d;
d=0;
q.push_back(top);
}
}
//cout<<endl;
if(flag)break;
ed=x[i];
//cout<<"sum="<<sum[t[i]]<<" "<<sum2[t[i]]<<endl;
if(sum[t[i]]>1){
q.push_back(t[i]);
sum[t[i]]=1;
}
else{
a[n+1]+=bka[t[i]];
if(q.size()==1)q.push_back(n+1);
}
a[t[i]]=bka[t[i]];
sum[t[i]]--;
}
//cout<<"n+1======="<<a[n+1]<<endl;
cout<<ed+a[n+1]<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11784kb
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: 11808kb
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 12 4 12 999999999 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '12'