蚯蚓之队列
作者:互联网
那么只要原来的蚯蚓具有单调性,每次只需要找这三个队列的最大值即可
至于每次都要增加的长度,我们可以先不加上,等到取出来的时候在加 (i - 1) * q(i−1)∗q, 放回去的时候注意要减去 i * qi∗q
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
queue<ll> q[3];
ll a[N];
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
ll n, m, u, v, qq, t; cin >> n >> m >> qq >> u >> v >> t;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n);
for (int i = n; i >= 1; i--) q[0].push(a[i]);
for (int i = 1; i <= m; i++) {
ll maxz = -1e18, pos = -1;
for (int j = 0; j < 3; j++) {
if (q[j].size() && q[j].front() > maxz) {
maxz = q[j].front();//找出三个队列中的最大
pos = j;//最大蚯蚓的队列
}
}
q[pos].pop();
maxz += (i - 1) * qq;
ll x = maxz * u / v, y = maxz - x;//切断的两条蚯蚓
if ((i % t == 0)) cout << maxz << ' ';
q[1].push(x - i * qq), q[2].push(y - i * qq);//入队,且被切的蚯蚓比别的的蚯蚓少长qq段
}
cout << "\n";
int cnt = 1;
while (q[0].size() || q[1].size() || q[2].size()) {
ll p = -1e18, pos = -1;
for (int j = 0; j < 3; j++) {
if (q[j].size() && q[j].front() > p) {
pos = j;
p = q[j].front();
}
}
q[pos].pop();
if (cnt % t == 0) {
cout << p + m * qq << ' ';
}
cnt++;
}
cout << "\n";
return 0;
}
标签:maxz,队列,ll,pos,int,front,蚯蚓 来源: https://blog.csdn.net/wuyvle/article/details/114380148