2 条题解
-
0
空间限制不能支持我们直接模拟,所以做了一点小小的优化
#include<bits/stdc++.h> #define int long long using namespace std; deque<pair<int,int> > d; signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); int Q; cin>>Q; while(Q--){ int op; cin>>op; if(op==1){ int x,c; cin>>x>>c; if(c!=0)d.push_back({x,c}); }else{ int c; cin>>c; int x=0; while(c){ int t=min(d.front().second,c); auto pr=d.front(); d.pop_front(); c-=t; pr.second-=t; x+=t*pr.first; if(pr.second!=0) d.push_front(pr); } cout<<x<<"\n"; } } } -
0
#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); queue<long long>shu; queue<long long>qiu; int n; cin>>n; while(n--){ int x; cin>>x; if(x==1){ long long c,y; cin>>y>>c; shu.push(y); qiu.push(c); }else{ long long c; cin>>c; long long sum=0; while(c>0){ long long w=shu.front(); long long num=qiu.front(); if(num<c){ sum+=num*w; c-=num; shu.pop(); qiu.pop(); }else{ sum+=c*w; qiu.front()-=c; c=0; } } cout<<sum<<endl; } } return 0; }
- 1
信息
- ID
- 12449
- 时间
- 2000ms
- 内存
- 1024MiB
- 难度
- 5
- 标签
- 递交数
- 52
- 已通过
- 22
- 上传者