QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#693668 | #7904. Rainbow Subarray | IRT | WA | 76ms | 6396kb | C++20 | 2.1kb | 2024-10-31 16:32:28 | 2024-10-31 16:32:31 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define MAXN 500000
using namespace std;
int T;
int N,K;
int A[MAXN+5];
priority_queue<pair<int,int> > q1;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q2;
int l=1,r=0;
int cnt1=0,cnt2=0,tmp=0,sum1=0,sum2=0,num1=0,num2=0,ans=0;
int calc(){
return (tmp*num1-sum1)+(sum2-tmp*num2);
}
void adjust(){
while(num1<num2){
while(q2.top().second<l){
q2.pop();
}
pair<int,int> t=q2.top();q2.pop();
q1.push(t);
num1++;
num2--;
sum1+=t.first;
sum2-=t.first;
}
while(num1>num2+1){
while(q1.top().second<l){
q1.pop();
}
pair<int,int> t=q1.top();q1.pop();
q2.push(t);
num1--;
num2++;
sum1-=t.first;
sum2+=t.first;
}
tmp=q1.top().first;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>T;
while(T--){
while(!q1.empty())q1.pop();
while(!q2.empty())q2.pop();
cnt1=0,cnt2=0,tmp=0,sum1=0,sum2=0,num1=0,num2=0,ans=0;
l=1,r=0;
cin>>N>>K;
for(int i=1;i<=N;i++){
cin>>A[i];
A[i]-=i;
}
for(int i=1;i<=N;i++){
while(l<=r && calc()>K){
if(A[l]>tmp){
num2--;
sum2-=A[l];
}
else{
num1--;
sum1-=A[l];
}
l++;
adjust();
}
ans=max(ans,num1+num2);
if(A[i]>tmp){
q2.push(pair<int,int>{A[i],i});
sum2+=A[i];
num2++;
}
else{
q1.push(pair<int,int>{A[i],i});
sum1+=A[i];
num1++;
}
r++;
adjust();
if(calc()<=K){
ans=max(ans,num1+num2);
}
}
cout<<ans<<"\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
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: 76ms
memory: 6396kb
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 5 7 2 4 1 4 1 1 3 2 2 7 8 7 7 1 7 6 2 4 3 1 6 7 7 3 4 3 9 3 8 6 6 3 1 6 3 1 2 4 6 4 6 4 1 4 7 1 6 3 5 6 6 1 7 5 3 1 6 4 5 3 2 2 6 2 3 10 1 4 3 2 4 5 1 7 5 5 5 8 5 3 6 3 5 5 8 5 3 5 2 1 5 2 3 3 4 8 1 3 1 2 2 8 3 1 6 8 1 8 4 5 6 6 8 4 8 3 2 8 4 5 6 2 6 2 4 1 5 4 5 3 2 4 1 2 1 4 5 8 3 7 3 3 3...
result:
wrong answer 94th lines differ - expected: '4', found: '3'