QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#687301 | #9528. New Energy Vehicle | wjynb666 | Compile Error | / | / | C++17 | 1.9kb | 2024-10-29 18:07:12 | 2024-10-29 18:07:14 |
Judging History
This is the latest submission verdict.
- [2024-10-29 18:07:14]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-10-29 18:07:12]
- Submitted
answer
#include <bits/stdc++.h>
using namespace std;
#define read_fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using ll=long long;
class cmp{
public:
bool operator()(pair<int,int> a,pair<int,int> b){
if(a.first!=b.first)return a.first>b.first;
return a.second<b.second;
}
};
void solve(){
int n,m;
cin>>n>>m;
vector<int> a(n);
vector<int> ca(n);
set<pair<int,int>,cmp> s;
for(int i=0;i<n;i++) {
cin>>a[i];
ca[i]=a[i];
s.insert({ca[i],i});
}
vector<array<int,2>> b(m);
for(int i=0;i<m;i++) cin>>b[i][0]>>b[i][1];
sort(b.begin(),b.end());
int last=0;
ll ans=0;
for(int i=0;i<m;i++){
int dis=(b[i][0]-last);
// cerr<<dis<<"\n";
int id=b[i][1];
id--;
int d1=min(dis,ca[id]);
int d=dis-d1;//剩余的距离
s.erase({ca[id],id});
ca[id]-=d1;
//cerr<<s.size()<<"\n";
//cerr<<d<<"\n";
while(d>0 && !s.empty()){
int x=(*s.begin()).first,j=(*s.begin()).second;
//cerr<<d<<" "<<x<<"\n";
s.erase({x,j});
int res=min(d,x);
d-=res;
x-=res;
ca[j]=x;
if(x) s.insert({x,j});
}
//cerr<<d<<"\n";
//cerr<<"---------\n";
if(d==0) ans+=dis;
else {
ans+=dis-d;
break;
}
ca[id]=a[id];
s.insert({ca[id],id});
last=b[i][0];
}
//cerr<<ans<<"\n";
for(int i=0;i<n;i++) {
//cerr<<ca[i]<<' ';
ans+=ca[i];
}
cout<<ans<<'\n';
//cerr<<"----------\n";
}
int main()
{
read_fast;
int t;
cin>>t;
while(t--) solve();
return 0;
}
詳細信息
In file included from /usr/include/c++/13/map:62, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:152, from answer.code:1: /usr/include/c++/13/bits/stl_tree.h: In instantiation of ‘static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(_Const_Link_type) [with _Key = std::pair<int, int>; _Val = std::pair<int, int>; _KeyOfValue = std::_Identity<std::pair<int, int> >; _Compare = cmp; _Alloc = std::allocator<std::pair<int, int> >; _Const_Link_type = const std::_Rb_tree_node<std::pair<int, int> >*]’: /usr/include/c++/13/bits/stl_tree.h:2118:47: required from ‘std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = std::pair<int, int>; _Val = std::pair<int, int>; _KeyOfValue = std::_Identity<std::pair<int, int> >; _Compare = cmp; _Alloc = std::allocator<std::pair<int, int> >; key_type = std::pair<int, int>]’ /usr/include/c++/13/bits/stl_tree.h:2171:4: required from ‘std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = std::pair<int, int>; _Key = std::pair<int, int>; _Val = std::pair<int, int>; _KeyOfValue = std::_Identity<std::pair<int, int> >; _Compare = cmp; _Alloc = std::allocator<std::pair<int, int> >]’ /usr/include/c++/13/bits/stl_set.h:523:25: required from ‘std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(value_type&&) [with _Key = std::pair<int, int>; _Compare = cmp; _Alloc = std::allocator<std::pair<int, int> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, cmp, std::allocator<std::pair<int, int> > >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<std::pair<int, int> >; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::rebind<std::pair<int, int> >; typename _Alloc::value_type = std::pair<int, int>; value_type = std::pair<int, int>]’ answer.code:23:17: required from here /usr/include/c++/13/bits/stl_tree.h:772:15: error: static assertion failed: comparison object must be invocable as const 772 | is_invocable_v<const _Compare&, const _Key&, const _Key&>, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_tree.h:772:15: note: ‘std::is_invocable_v<const cmp&, const std::pair<int, int>&, const std::pair<int, int>&>’ evaluates to false