QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#430588 | #7279. Tricks of the Trade | ItamarN | 0 | 801ms | 14000kb | C++14 | 2.9kb | 2024-06-04 00:55:01 | 2024-06-04 00:55:02 |
Judging History
answer
#include <iostream>
using namespace std;
#include <vector>
#define vi vector<int>
#define ll long long
#include <algorithm>
#include <set>
#include <string>
#include <bitset>
#include <cmath>
#include <math.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define pi pair<int,int>
#include <map>
#include <queue>
#define x first
#define y second
#define pd pair<double,double>
const int siz = 3e5;
ll c[siz];
ll s[siz];
int n,k;
multiset<int>::iterator kth;
ll sum = 0;
multiset<int> mul;
ll ans = -1e18;
ll cost = 0;
void er(ll i) {
cost -= c[i];
ll val = s[i];
if (mul.size() <= k) {
mul.erase(mul.find(val));
sum -= val;
kth = mul.begin();
}
else {
auto it = mul.find(val);
if (val < *kth || (val == *kth && it != kth)) {
mul.erase(it);
return;
}
else {
kth--;
sum += *kth - val;
mul.erase(it);
return;
}
}
}
void in(ll i) {
ll val = s[i];
cost += c[i];
if (mul.size() < k) {
mul.insert(val);
sum += val;
kth = mul.begin();
}
else {
mul.insert(val);
if (*kth > val)return;
sum += val - *kth;
kth++;
}
}
void rec(int l, int r, int a, int b) {
if (l > r)return;
int mid = (l + r) / 2;
b = min(mid , b);
pll opt={-1e18,a};
for (int i = a; i <= b; i++) {
if (mid - i + 1 >= k) {
opt = max(opt, { sum - cost,i });
}
er(i);
}
ans = max(ans, opt.x);
if (l == r) {
for (int i = a; i <= b; i++) {
in(i);
}
return;
}
for (int i = mid; i > max(b,(l+mid-1)/2); i--)er(i);
for (int i = a; i <=min(b, (l + mid-1) / 2);i++)in(i);
rec(l, mid - 1, a, opt.y);
for (int i = mid; i > max(b, (l + mid - 1) / 2); i--)in(i);
for (int i = a; i <= min(b, (l + mid - 1) / 2); i++)er(i);
for (int i = mid+1; i <= (r+ mid+1) / 2; i++)in(i);
for (int i = opt.y; i <=b; i++)in(i);
rec(mid+1, r, opt.y, b);
for (int i = mid + 1; i <= (r + mid + 1) / 2; i++)er(i);
for (int i = opt.y; i <= b; i++)er(i);
for (int i = a; i <= b; i++) {
in(i);
}
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> k;
for (int i = 0; i < n; i++)cin >> c[i];
for (int i = 0; i < n; i++)cin >> s[i];
for (int i = 0; i <= (n-1)/2; i++)in(i);
rec(0, n - 1, 0, n - 1);
cout << ans << "\n";
for (int i = 0; i < n; i++)cout << '0';
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Acceptable Answer
time: 0ms
memory: 5632kb
input:
5 3 3 5 2 3 6 2 1 5 2 3
output:
-1 00000
result:
points 0.50 first question correct
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 5660kb
input:
200 40 81 50 87 91 54 1 77 68 19 84 28 81 45 64 4 13 25 89 12808135 86 40 73 47 18 82 79 11 96 16 34 80 36 8 5 60 76 86 84 36 37 96 55 68 12807879 51 89 57 30 100 11 44 19 96 32 9 68 41 12808009 5 58 12807939 92 68 67 78 32 57 49 71 92 64 35 89 76 81 36 6 6 53 31 85 79 5 85 1 91 17 37 25 91 54 29 47...
output:
12807908 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
result:
wrong answer wrong answer on the first question
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #30:
score: 5
Acceptable Answer
time: 0ms
memory: 5572kb
input:
5 2 1 6 1 5 2 4 1 6 2 4
output:
2 00000
result:
points 0.50 first question correct
Test #31:
score: 5
Acceptable Answer
time: 740ms
memory: 13692kb
input:
250000 2 18 35 29 35 18 610084694 18 35 29 35 18 448867144 18 35 29 35 18 971272498 18 35 29 35 18 890430190 18 35 29 35 18 655685684 18 35 29 35 18 234608237 18 35 29 35 18 894586749 18 35 29 35 18 442195168 18 35 29 35 18 341564617 18 35 29 35 18 985069087 18 35 29 35 18 967546483 18 35 29 35 18 5...
output:
33391 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 0.50 first question correct
Test #32:
score: 5
Acceptable Answer
time: 567ms
memory: 13764kb
input:
250000 2 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1...
output:
7 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 0.50 first question correct
Test #33:
score: 0
Wrong Answer
time: 801ms
memory: 14000kb
input:
250000 2 296095839 339724373 965973329 196477261 344160630 150756369 190174474 470255817 512937857 249988555 752486830 474766981 101796731 563280029 312834955 720810905 619379033 324109033 874523062 841728664 19232878 363302361 436792441 201047597 165902785 728305993 892140052 423772401 255303346 35...
output:
-124023776 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
wrong answer wrong answer on the first question
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%