QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#366799 | #7904. Rainbow Subarray | crsfaa# | WA | 1071ms | 9872kb | C++14 | 1.4kb | 2024-03-25 08:37:19 | 2024-03-25 08:37:20 |
Judging History
answer
#include<bits/stdc++.h>
#define Yukinoshita namespace
#define Yukino std
#define int long long
using Yukinoshita Yukino;
int read()
{
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9') w=ch=='-'?-1:1,ch=getchar();
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
const int mxn=5e5+5;
int a[mxn];
int n;
int check(int x)
{
static int b[mxn];
int i,j,s1=0,s2=0,ans,mid;
multiset<int> mn,mx;
for(i=1;i<=x;i++)
b[i]=a[i];
sort(b+1,b+1+x);
for(i=1;i<=x/2;i++)
mn.insert(b[i]),s1+=b[i];
for(;i<=x;i++)
mx.insert(b[i]),s2+=b[i];
mid=*mx.begin();
ans=mid*(int)mn.size()-s1+s2-(int)mx.size()*mid;
for(;i<=n;i++)
{
if(a[i]<=*mn.end()) mn.insert(a[i]),s1+=a[i];
else mx.insert(a[i]),s2+=a[i];
if(mn.find(a[i-x])!=mn.end()) mn.erase(mn.find(a[i-x])),s1-=a[i-x];
else mx.erase(mx.find(a[i-x])),s2-=a[i-x];
while(mn.size()<x/2) s1+=*mx.begin(),s2-=*mx.begin(),mn.insert(*mx.begin()),mx.erase(mx.begin());
while(mn.size()>x/2) s1-=*mn.begin(),s2+=*mn.begin(),mx.insert(*mn.begin()),mn.erase(mn.begin());
mid=*mx.begin();
ans=min(ans,mid*(int)mn.size()-s1+s2-(int)mx.size()*mid);
}
return ans;
}
signed main()
{
int T=read();
while(T--)
{
n=read();
int k=read(),i,w=1;
for(i=1;i<=n;i++)
a[i]=read()-i;
for(i=1<<20;i;i>>=1)
w+=(w+i<=n&&check(w+i)<=k)*i;
printf("%d\n",w);
}
}
/*
1
5 50
100 200 300 400 500
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3996kb
input:
5 7 5 7 2 5 5 4 11 7 6 0 100 3 4 5 99 100 5 6 1 1 1 1 1 5 50 100 200 300 400 500 1 100 3
output:
4 3 5 1 1
result:
ok 5 lines
Test #2:
score: -100
Wrong Answer
time: 1071ms
memory: 9872kb
input:
11102 2 167959139 336470888 134074578 5 642802746 273386884 79721198 396628655 3722503 471207868 6 202647942 268792718 46761498 443917727 16843338 125908043 191952768 2 717268783 150414369 193319712 6 519096230 356168102 262263554 174936674 407246545 274667941 279198849 9 527268921 421436316 3613460...
output:
1 4 3 2 6 6 7 2 4 1 4 1 1 4 2 2 7 8 7 7 1 7 6 2 4 3 1 6 7 7 3 4 3 9 4 8 6 6 3 1 7 3 1 2 4 6 4 6 4 2 4 7 1 6 3 5 6 6 1 7 5 4 1 6 4 6 3 2 2 6 2 3 10 1 5 4 2 4 5 1 8 5 5 5 8 5 3 6 3 5 5 8 5 4 5 2 1 6 2 4 5 4 8 1 4 1 2 2 8 3 1 6 8 1 8 4 5 6 6 8 6 8 3 2 8 4 5 6 2 6 2 6 1 5 4 6 4 2 4 1 2 1 4 5 8 3 8 3 3 4...
result:
wrong answer 6th lines differ - expected: '5', found: '6'