QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#581894#7904. Rainbow SubarraygggggggWA 130ms6156kbC++141.1kb2024-09-22 14:31:422024-09-22 14:31:45

Judging History

你现在查看的是最新测评结果

  • [2024-09-22 14:31:45]
  • 评测
  • 测评结果:WA
  • 用时:130ms
  • 内存:6156kb
  • [2024-09-22 14:31:42]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=500005;
int n,a[N];
ll k,sm1,sm2;
multiset<int> s1,s2;
void mt(){
    int l=s1.size()+s2.size();
    while(s1.size()>(l+1)/2) s2.insert(*s1.rbegin()),sm2+=(*s1.rbegin()),sm1-=(*s1.rbegin()),s1.erase(prev(s1.end()));
    while(s1.size()<(l+1)/2) s1.insert(*s2.begin()),sm1+=(*s2.begin()),sm2-=(*s2.begin()),s2.erase(s2.begin());
}
void add(int x){
    if(x>=(*s2.begin())) s2.insert(x),sm2+=x;
    else s1.insert(x),sm1+=x;
    mt();
}
void del(int x){
    if(s1.count(x)) s1.erase(s1.find(x)),sm1-=x;
    else s2.erase(s2.find(x)),sm2-=x;
    mt();
}
bool chk(){
    int v=(*s1.rbegin());
    return (1ll*(s1.size())*v-sm1+sm2-1ll*(s2.size())*v)<=k;
}
void solve(){
    scanf("%d%lld",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),a[i]-=i;
    s1.clear(),s2.clear(),sm1=sm2=0;
    int l=1,as=0;
    for(int i=1;i<=n;i++){
        add(a[i]);
        while(!chk()) 
            del(a[l]),l++;
        as=max(i-l+1,as);
    }
    printf("%d\n",as);
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3788kb

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: 130ms
memory: 6156kb

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
3
3
2
4
5
7
1
4
1
2
1
1
2
2
2
7
8
6
7
1
7
6
2
3
2
1
6
7
6
1
4
3
9
3
8
6
5
3
1
6
3
1
2
2
6
4
6
3
1
4
7
1
6
3
4
5
6
1
7
4
2
1
5
4
4
3
2
1
6
2
2
8
1
4
3
1
4
5
1
7
5
4
5
7
5
3
5
3
4
5
7
3
3
5
2
1
5
1
3
3
4
7
1
3
1
1
1
8
3
1
6
7
1
7
4
4
6
5
8
4
6
2
2
8
4
3
6
1
6
1
4
1
4
2
4
3
2
3
1
1
1
4
5
8
3
7
3
3
3
...

result:

wrong answer 2nd lines differ - expected: '4', found: '3'