QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#303623#7904. Rainbow Subarraypengpeng_fudanWA 330ms14940kbC++141.8kb2024-01-12 20:25:512024-01-12 20:25:51

Judging History

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

  • [2024-06-09 00:00:26]
  • hack成功,自动添加数据
  • (/hack/652)
  • [2024-01-12 20:25:51]
  • 评测
  • 测评结果:WA
  • 用时:330ms
  • 内存:14940kb
  • [2024-01-12 20:25:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
using ll=long long;
ll tr[500010][2];
int n,k;
vector<int> ve;
int get(int x){
    return lower_bound(ve.begin(),ve.end(),x)-ve.begin()+1;
}
int sz;
void add(int x,int t,int num){
    for(;x<=sz;x+=x&-x) tr[x][t]+=num;
}
ll get_pre_sum(int len){
    ll sum=0;int p=0;
    for(int i=20;i>=0;i--){
        if(p+(1<<i)>sz) continue;
        if(len>tr[p+(1<<i)][0]){
            len-=tr[p+(1<<i)][0];
            sum+=tr[p+(1<<i)][1];
            p+=(1<<i);
        }
    }
    if(len>0)   sum+=1ll*ve[p]*len;
    return sum;
}
ll get_ope(int len){
    if(len&1){
        ll sum_1=get_pre_sum(len/2);
        ll sum_2=get_pre_sum(len/2+1);
        //cout<<sum_1<<' '<<sum_2<<'\n';
        return get_pre_sum(len)-sum_2-sum_1;
    }
    else{
        ll sum_1=get_pre_sum(len/2);
        ll sum_2=get_pre_sum(len);
        return sum_2-2*sum_1;   
    }
}
int a[500010];
void solve() {
    cin>>n>>k;
    int num;
    ve.clear();
    for(int i=1;i<=n;i++){
        cin>>num;
        num-=i;
        a[i]=num;
        ve.push_back(num);
    }
    sort(ve.begin(),ve.end());
    ve.erase(unique(ve.begin(),ve.end()),ve.end());
    sz=ve.size();
    for(int i=0;i<=sz;i++)  tr[i][0]=tr[i][1]=0;
    int le=1,re=0;
    int ans=0;
    while(re<n){
        re++;
        int wei=get(a[re]);
        add(wei,0,1);
        add(wei,1,a[re]);
        while(get_ope(re-le+1)>k){
            //cout<<le<<' '<<re<<' '<<get_pre_sum(re-le+1)<<'\n';
            wei=get(a[le]);
            add(wei,0,-1);
            add(wei,1,-a[le]);
            le++;
        }
        ans=max(ans,re-le+1);
    }
    cout<<ans<<'\n';
}
int main() {
    ios::sync_with_stdio(0),cin.tie(0);
    int _ = 1;
    cin >> _;
    while(_--) solve();
    return 0;
}

详细

Test #1:

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

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: 0
Accepted
time: 168ms
memory: 5516kb

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
4
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:

ok 11102 lines

Test #3:

score: -100
Wrong Answer
time: 330ms
memory: 14940kb

input:

1
500000 17244641009859
54748096 75475634 204928248 276927808 84875072 103158867 27937890 322595515 186026685 45468307 69240390 139887597 188586447 373764525 121365644 310156469 185188306 60350786 211308832 384695957 370562147 208427221 35937909 267590963 126478310 275357775 55361535 335993561 36696...

output:

2579

result:

wrong answer 1st lines differ - expected: '172998', found: '2579'