QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#647266 | #7279. Tricks of the Trade | chenxinyang2006# | 0 | 551ms | 16588kb | C++20 | 2.7kb | 2024-10-17 13:06:40 | 2024-10-17 13:06:43 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int n,K;
int a[250005],b[250005];
ll ssum[250005];
set <pii> C,D;
ll cur;
void dbg(){
printf("cur=%lld\n",cur);
for(pii I:C) printf("(%d,%d) ",I.first,I.second);
printf("\n");
for(pii I:D) printf("(%d,%d) ",I.first,I.second);
printf("\n");
}
void add(int p){
// printf("add %d\n",p);
if(SZ(C) < K){
cur += b[p];
C.insert(mkp(b[p],p));
return;
}else{
auto it = prev(C.end());
if(it->first < b[p]){
cur -= it->first;
cur += b[p];
D.insert(mkp(it->first,it->second));
C.erase(it);
C.insert(mkp(b[p],p));
}else{
D.insert(mkp(b[p],p));
}
}
}
void del(int p){
if(!p) return;
// printf("del %d\n",p);
auto it = D.find(mkp(b[p],p));
if(it != D.end()){
D.erase(it);
return;
}
it = C.find(mkp(b[p],p));
assert(it != C.end());
cur -= b[p];
C.erase(it);
if(D.empty()) return;
it = D.begin();
cur += it->first;
C.insert(mkp(it->first,it->second));
D.erase(it);
}
int pl,pr;
ll eval(int l,int r){
if(l > r) return -linf;
// printf("eval [%d,%d]\n",l,r);
while(l < pl) add(--pl);
while(r > pr) add(++pr);
while(pl < l) del(pl++);
while(pr > r) del(pr--);
// dbg();
if(SZ(C) < K) return -linf;
return cur - (ssum[r] - ssum[l - 1]);
}
ll ans[250005];
int opt[250005];
void solve(int l,int r,int L,int R){
if(l > r) return;
int mid = (l + r) >> 1;
ans[mid] = -linf;
rep(i,L,R){
if(eval(i,mid) >= ans[mid]){
ans[mid] = eval(i,mid);
opt[mid] = i;
}
}
solve(l,mid - 1,L,opt[mid]);
solve(mid + 1,r,opt[mid],R);
}
int main(){
// freopen("test.in","r",stdin);
scanf("%d%d",&n,&K);
rep(i,1,n){
scanf("%d",&a[i]);
ssum[i] = ssum[i - 1] + a[i];
}
rep(i,1,n) scanf("%d",&b[i]);
pl = 1;pr = 0;
solve(1,n,1,n);
ll answer = -linf;
rep(i,1,n) chkmax(answer,ans[i]);
printf("%lld\n",answer);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Acceptable Answer
time: 1ms
memory: 7912kb
input:
5 3 3 5 2 3 6 2 1 5 2 3
output:
-1
result:
points 0.50 first question correct
Test #2:
score: 5
Acceptable Answer
time: 1ms
memory: 8012kb
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:
12807909
result:
points 0.50 first question correct
Test #3:
score: 5
Acceptable Answer
time: 1ms
memory: 10044kb
input:
200 41 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
81
result:
points 0.50 first question correct
Test #4:
score: 5
Acceptable Answer
time: 0ms
memory: 10036kb
input:
5 2 1 6 1 5 2 4 1 6 2 4
output:
2
result:
points 0.50 first question correct
Test #5:
score: 5
Acceptable Answer
time: 0ms
memory: 7928kb
input:
7 3 5 1 1 1 1 1 5 1 1 1 1 1 1 1
output:
0
result:
points 0.50 first question correct
Test #6:
score: 0
Wrong Answer
time: 1ms
memory: 8012kb
input:
200 100 142654162 64490063 513345044 219974445 84112685 711899650 33120992 176027514 802361343 2414916 941549932 786288853 94273368 829024564 352947721 355629698 903479794 326383768 720620114 271371691 786997028 138881060 711795174 536092340 290169962 938690480 710723910 231424065 468554799 44519400...
output:
-2461503020
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: 1ms
memory: 9972kb
input:
5 2 1 6 1 5 2 4 1 6 2 4
output:
2
result:
points 0.50 first question correct
Test #31:
score: 0
Wrong Answer
time: 551ms
memory: 16588kb
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:
16760
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%