QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#697765 | #9528. New Energy Vehicle | czrq# | Compile Error | / | / | C++17 | 1.5kb | 2024-11-01 15:39:44 | 2024-11-01 15:39:44 |
Judging History
This is the latest submission verdict.
- [2024-11-01 15:39:44]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-11-01 15:39:44]
- Submitted
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=1e5+5;
ll id[M],a[M],n,m,k;
ll b[M];
ll next[M];
bool vis[M]={0};
struct node{
ll x,t;
bool operator<(const node n) const
{
return x<n.x;
}
}no[M];
void solve(){
cin>>n>>m;
priority_queue<node> q;
for(int i=1;i<=n;i++){
cin>>a[i];
b[i]=a[i];
vis[i]=0;
next[i]=0;
id[i]=0;
}
for(int i=1;i<=m;i++){
cin>>no[i].x>>no[i].t;
vis[no[i].t]=1;
q.push(no[i]);
}
long long an=0;
for(int i=1;i<=n;i++){
if(vis[i]==0){
an+=a[i];
}
}
sort(no+1,no+1+m);
for(int i=m;i>=1;i--){
if(id[no[i].t]) next[i]=id[no[i].t];
id[no[i].t]=i;
}
int flag=0;
long long sum=0;
no[0].x=0;
no[0].t=0;
next[0]=0;
for(int i=0;i<m;i++){
if(i>=1){
if(next[i]){
q.push(no[next[i]]);
b[no[i].t]=a[no[i].t];
}
else{
an+=a[no[i].t];
}
}
while(q.size()&&no[i].x>=q.top().x)q.pop();
long long res=no[i+1].x-no[i].x;
while(res){
if(!q.size()){
an-=res;
res=0;
if(an<0){
flag=1;
}
}
int v=q.top().t;
ll ans=min(res,b[v]);
if(ans==b[v]){
q.pop();
}
res-=ans;
b[v]-=ans;
}
if(flag){
sum=no[i].x+an;
// cout<<i<<"#"<<an<<endl;
break;
}
}
if(flag==0){
sum=(no[m].x+an+a[no[m].t]);
}
cout<<sum<<endl;
}
int main(){
int t=1;
cin>>t;
while(t--){
solve();
}
}
详细
answer.code: In function ‘void solve()’: answer.code:23:17: error: reference to ‘next’ is ambiguous 23 | next[i]=0; | ^~~~ In file included from /usr/include/c++/13/bits/stl_algobase.h:66, from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from answer.code:1: /usr/include/c++/13/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: ‘template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)’ 232 | next(_InputIterator __x, typename | ^~~~ answer.code:7:4: note: ‘ll next [100005]’ 7 | ll next[M]; | ^~~~ answer.code:40:33: error: reference to ‘next’ is ambiguous 40 | if(id[no[i].t]) next[i]=id[no[i].t]; | ^~~~ /usr/include/c++/13/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: ‘template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)’ 232 | next(_InputIterator __x, typename | ^~~~ answer.code:7:4: note: ‘ll next [100005]’ 7 | ll next[M]; | ^~~~ answer.code:47:9: error: reference to ‘next’ is ambiguous 47 | next[0]=0; | ^~~~ /usr/include/c++/13/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: ‘template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)’ 232 | next(_InputIterator __x, typename | ^~~~ answer.code:7:4: note: ‘ll next [100005]’ 7 | ll next[M]; | ^~~~ answer.code:50:44: error: reference to ‘next’ is ambiguous 50 | if(next[i]){ | ^~~~ /usr/include/c++/13/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: ‘template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)’ 232 | next(_InputIterator __x, typename | ^~~~ answer.code:7:4: note: ‘ll next [100005]’ 7 | ll next[M]; | ^~~~ answer.code:51:35: error: reference to ‘next’ is ambiguous 51 | q.push(no[next[i]]); | ^~~~ /usr/include/c++/13/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: ‘template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)’ 232 | next(_InputIterator __x, typename | ^~~~ answer.code:7:4: note: ‘ll next [100005]’ 7 | ll next[M]; | ^~~~