题解:AT_abc413_c [ABC413C] Large Queue
这道题本人考场也磕了不少时间,但最后发现只是个双端队列暴力能解决的。
不难发现,整个数组是分为很多个相同整数块组成的,我们存储每个块的数量和对应的数,在进行第二种操作时,我们对应的去删除一些块,并记录当前删除数量的和,是个很简单的模拟。
CODE
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int n , op , c , x , cur;
deque<pair<int , int> >g;
signed main(){
cin >> n;
while(n--){
cin >> op >> c;
if(op == 1){
cin >> x;
g.push_back({c , x});
}else{
long long now = 0 , sum = 0;
while(!g.empty()){
auto t = g.front();
if(now + t.first > c){
sum += (c - now) * t.second;
t.first -= c - now;
g.pop_front();
g.push_front({t.first , t.second});
break;
}
now += t.first;
sum += t.second * t.first;
g.pop_front();
}
cout << sum << '\n';
}
}
return 0;
}