QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#687528 | #9528. New Energy Vehicle | MENDAX# | WA | 2ms | 25856kb | C++20 | 1.8kb | 2024-10-29 19:30:18 | 2024-10-29 19:30:18 |
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 it=pos.begin();it!=pos.end();it++){
auto zz=sh[*it];
// cout<<zz<<" "<<dis<<endl;
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++){//t[i]==1
if(*it<=i)val.push_back(*it);
else {
pos.insert(*it);
if(*it!=m+1)sh[*it]=a[t[i]];
else sh[*it]+=a[t[i]];
}
}
// cout<<sh[m+1]<<endl;
for(auto zz:val)se[t[i]].erase(zz);
}
cout<<x[m]+sh[m+1]<<endl;
}
/*
2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1
*/
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int T=1;cin>>T;
while(T--) slove();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 25856kb
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: 24264kb
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 15 4 21 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '10'