ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215355 | #2713. 8.2t2 | nodgd | 100 | 348ms | 5588kb | C++11 | 2.4kb | 2024-11-28 20:38:06 | 2024-11-28 23:12:09 |
answer
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 5;
int N, M;
int a[MAX_N], b[MAX_N], f[MAX_N];
long long sum, ans;
priority_queue<pair<int,int>> q1, q2, q3;
void push(int i) {
if (f[i] == 0) {
q1.push(make_pair(a[i], i));
q2.push(make_pair(a[i] + b[i], i));
} else if (f[i] == 1) {
q1.push(make_pair(b[i], i));
q2.push(make_pair(b[i] + a[i], i));
q3.push(make_pair(-a[i], i));
} else if (f[i] == 2) {
q1.push(make_pair(a[i], i));
q3.push(make_pair(-b[i], i));
} else {
q3.push(make_pair(-a[i], i));
}
}
int main() {
scanf("%d%d", &N, &M);
for (int i = 1; i <= N; i ++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= N; i ++) {
scanf("%d", &b[i]);
push(i);
}
for (int k = 1; k <= M; k ++) {
if (k <= N * 3) {
int i, j, t1, t2;
while (q1.size()) {
i = q1.top().second, t1 = q1.top().first;
if (f[i] == 3 || f[i] == 1 && b[i] != t1 || (f[i] != 1 && a[i] != t1)) {
q1.pop();
} else break;
}
while (q2.size()) {
i = q2.top().second, t1 = q2.top().first;
if (f[i] >= 2 || t1 != a[i] + b[i]) {
q2.pop();
} else break;
}
while (q3.size()) {
i = q3.top().second, t1 = q3.top().first;
if (f[i] == 0 || f[i] == 2 && -b[i] != t1 || f[i] != 2 && -a[i] != t1) {
q3.pop();
} else break;
}
t1 = -1e9, t2 = -1e9;
if (q1.size()) {
t1 = q1.top().first;
}
if (q2.size() && q3.size()) {
t2 = q2.top().first + q3.top().first;
}
if (t1 >= t2) {
i = q1.top().second;
q1.pop();
sum += t1;
f[i] ++;
push(i);
} else {
i = q2.top().second;
j = q3.top().second;
q2.pop(), q3.pop();
sum += t2;
f[i] += 2, f[j] -= 1;
push(i), push(j);
}
}
ans ^= sum;
}
printf("%lld\n", ans);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1244kb
input:
4 10 2 2 4 8 8 4 7 10
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 10
Accepted
time: 0ms
memory: 1244kb
input:
5 10 51072389 300657765 633439665 787090487 68456665 196385267 67864372 385977125 213928095 324494080
output:
3719844854
result:
ok 1 number(s): "3719844854"
Test #3:
score: 10
Accepted
time: 0ms
memory: 1240kb
input:
5 10 48720179 139181569 338164905 149648143 77222193 187724219 91625887 540142777 43334953 184586388
output:
215635088
result:
ok 1 number(s): "215635088"
Test #4:
score: 10
Accepted
time: 59ms
memory: 5588kb
input:
100000 102662 33421051 125633985 365251021 255717315 262377226 360896081 5951202 90071401 154444767 ...
output:
69628185742891
result:
ok 1 number(s): "69628185742891"
Test #5:
score: 10
Accepted
time: 60ms
memory: 5584kb
input:
100000 102838 588484254 69882126 151341881 500364775 68104321 134809939 50886121 98623841 274710921 ...
output:
2211168290969
result:
ok 1 number(s): "2211168290969"
Test #6:
score: 10
Accepted
time: 44ms
memory: 5588kb
input:
100000 102858 816229225 31491762 141788824 11587861 40202296 167103151 76959748 111706177 185028195 ...
output:
6040329651388
result:
ok 1 number(s): "6040329651388"
Test #7:
score: 10
Accepted
time: 22ms
memory: 4000kb
input:
100000 100 12830259 71768257 32489793 11032029 534815873 25056247 9333295 338811835 392555485 787185...
output:
4970387228
result:
ok 1 number(s): "4970387228"
Test #8:
score: 10
Accepted
time: 28ms
memory: 4004kb
input:
100000 100 72601214 53610670 93861411 367396001 45683503 4337367 98950041 888815737 409387861 106118...
output:
134182801545
result:
ok 1 number(s): "134182801545"
Test #9:
score: 10
Accepted
time: 69ms
memory: 5588kb
input:
100000 150000 667 605 113 157 314 281 1 234 801 121 561 414 25 953 434 233 421 601 993 969 209 695 7...
output:
33097015
result:
ok 1 number(s): "33097015"
Test #10:
score: 10
Accepted
time: 66ms
memory: 5584kb
input:
100000 150000 96 945 103 451 167 433 537 867 781 656 145 507 381 960 753 700 93 133 122 952 393 985 ...
output:
7610868
result:
ok 1 number(s): "7610868"