QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#687605 | #9528. New Energy Vehicle | MENDAX# | WA | 5ms | 24496kb | C++20 | 1.9kb | 2024-10-29 19:56:32 | 2024-10-29 19:56:33 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define endl '\n'
using namespace std;
const int N=3e5+10,INF=1e14,mod=1e9+7,M=2e5+10;
const double eps = 1e-8;
typedef pair<int,int> PII;
typedef pair<PII,int> PIII;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int qmi(int a,int k){int res=1;while(k){if(k&1) res=res*a%mod;a=a*a%mod;k>>=1;}return res;}
int a[N],x[N],t[N],sh[N];
set<int> pos;
set<int> se[N];//他的下标
void slove(){
int n,m;cin>>n>>m;
pos.clear();
for(int i=1;i<=n;i++) se[i].clear();
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=m;i++){
cin>>x[i]>>t[i];
if(!se[t[i]].size()){
sh[i]=a[t[i]],pos.insert(i);
}
se[t[i]].insert(i);
}
pos.insert(m+1);
for(int i=1;i<=n;i++){
if (se[i].empty()) {
sh[m+1]+=a[i];
}
se[i].insert(m+1);
}
// for(auto zz:pos) cout<<zz<<" "<<sh[zz]<<endl;
// cout<<">>>"<<endl;
for(int i=1;i<=m;i++){
int dis=x[i]-x[i-1];
vector<int> val;
// cout<<dis<<endl;
// for(auto zz:pos)cout<<zz<<" "<<sh[zz]<<endl;
for(auto it=pos.begin();it!=pos.end();it++){
auto zz=sh[*it];
int nowp = *it;
if(zz<dis)dis-=zz,sh[*it]=0,val.push_back(*it);
else {
sh[*it]-=dis;
dis=0;
}
}
if(dis>0){
cout<<x[i]-dis<<endl;
return ;
}
for(auto zz:val) pos.erase(zz);
//然后就是补充t[i]
val.clear();
for(auto it=se[t[i]].begin();it!=se[t[i]].end();it++){
//cout<<i<<" "<<t[i]<<" "<<*it<<endl;
if(*it<=i)val.push_back(*it);
else {
// cout<<*it<<endl;
pos.insert(*it);
if(*it!=m+1)sh[*it]=a[t[i]];
else sh[*it]+=a[t[i]];
break;
}
}
for(auto zz:val)se[t[i]].erase(zz);
}
cout<<x[m]+sh[m+1]<<endl;
}
/*
1
3 2
3 3 3
9 1
10 1
*/
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int T=1;cin>>T;
while(T--) slove();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 23924kb
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: 24496kb
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 14 4 20 999999999 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '14'