QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#576534 | #7279. Tricks of the Trade | Crying | 0 | 234ms | 125864kb | C++14 | 2.1kb | 2024-09-19 20:51:39 | 2024-09-19 20:51:39 |
Judging History
answer
#include<bits/stdc++.h>
#define lc(x) (t[x].lc)
#define rc(x) (t[x].rc)
#define mid ((l+r)>>1)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
const ll N = 2.5e5+10,M = 8e6,INF = 1e18;
template<typename T>void tomin(T& x,T y){x = min(x,y);}
template<typename T>void tomax(T& x,T y){x = max(x,y);}
int n,k,a[N],b[N];
int arr[N],rk[N];
ll sa[N];
struct Node{
int lc,rc,cnt; ll sum;
}t[M]; int tot;
void pu(int x){
t[x].cnt = t[lc(x)].cnt + t[rc(x)].cnt;
t[x].sum = t[lc(x)].sum + t[rc(x)].sum;
}
int mdf(int p,int l,int r,int pos,int w){
int x = ++tot; t[x] = t[p];
if(l==r){
t[x].cnt = 1; t[x].sum = w;
return x;
}
(pos<=mid) ? (lc(x) = mdf(lc(x),l,mid,pos,w)) : (rc(x) = mdf(rc(x),mid+1,r,pos,w));
pu(x);
return x;
}
ll qry(int x,int y,int l,int r,int cnt){
if(t[y].cnt - t[x].cnt <= cnt)return t[y].sum - t[x].sum;
int cR = t[rc(y)].cnt - t[rc(x)].cnt;
if(cR >= cnt)return qry(rc(x),rc(y),mid+1,r,cnt);
else return (t[rc(y)].sum - t[rc(x)].sum) + qry(lc(x),lc(y),l,mid,cnt-cR);
}
#undef mid
int rt[N];
ll ans = -INF; int res[N];
int pos[N]; ll val[N];
ll calc(int L,int R){
int len = R-L+1; assert(len >= k);
ll suma = sa[R] - sa[L-1],sumb = qry(rt[L-1],rt[R],1,n,k);
return sumb - suma;
}
void solve(int l,int r,int L,int R){
if(l>r || L>R)return;
int mid = (l+r)>>1;
val[mid] = -INF;
for(int j=R;j>=L;j--)if(j>=mid+k-1){
ll w = calc(mid,j);
if(w > val[mid])val[mid] = w,pos[mid] = j;
}
solve(l,mid-1,L,pos[mid]); solve(mid+1,r,pos[mid],R);
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i],sa[i] = sa[i-1] + a[i];
for(int i=1;i<=n;i++)cin>>b[i],arr[i] = i;
sort(arr+1,arr+1+n,[&](int x,int y){return b[x] > b[y];});
for(int i=1;i<=n;i++)rk[arr[i]] = i;
for(int i=1;i<=n;i++)rt[i] = mdf(rt[i-1],1,n,rk[i],b[i]);
solve(1,n-k+1,1,n);
for(int i=1;i<=n-k+1;i++)tomax(ans,val[i]);
cout<<ans<<"\n";
for(int i=1;i<=n;i++)cout<<res[i];
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: 0ms
memory: 9776kb
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: 5
Acceptable Answer
time: 1ms
memory: 9824kb
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 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
result:
points 0.50 first question correct
Test #3:
score: 5
Acceptable Answer
time: 0ms
memory: 9796kb
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 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
result:
points 0.50 first question correct
Test #4:
score: 5
Acceptable Answer
time: 1ms
memory: 9768kb
input:
5 2 1 6 1 5 2 4 1 6 2 4
output:
2 00000
result:
points 0.50 first question correct
Test #5:
score: 5
Acceptable Answer
time: 1ms
memory: 9840kb
input:
7 3 5 1 1 1 1 1 5 1 1 1 1 1 1 1
output:
0 0000000
result:
points 0.50 first question correct
Test #6:
score: 0
Wrong Answer
time: 1ms
memory: 9832kb
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 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: 1ms
memory: 9852kb
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: 0
Wrong Answer
time: 234ms
memory: 125864kb
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 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
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%