QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#275139#7904. Rainbow Subarray2468216537WA 188ms5520kbC++202.1kb2023-12-04 14:03:282023-12-04 14:03:28

Judging History

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

  • [2024-06-09 00:00:26]
  • hack成功,自动添加数据
  • (/hack/652)
  • [2023-12-04 14:03:28]
  • 评测
  • 测评结果:WA
  • 用时:188ms
  • 内存:5520kb
  • [2023-12-04 14:03:28]
  • 提交

answer

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)x.size())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using ll = long long;
using PII = pair<int,int>;
using pll = pair<ll,ll>;
using db = long double;
const int N = 2010,M = 31,mod = 998244353;
const int inf = 1 << 30;

void solve(){
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n + 1);
    rep(i,1,n + 1) {
        cin >> a[i];
        a[i] -= i;
    }
    int cnt = 0,ans = 0;
    ll s1 = 0,s2 = 0;
    multiset<int,greater<int>> h1;
    multiset<int> h2;
    auto ins = [&](int x){
        cnt++;
        int m = (cnt + 1) / 2;
        h2.insert(a[x]);
        s2 += a[x];
        while (SZ(h1) < m){
            int y = *h2.begin();
            s1 += y;
            h1.insert(y);
            s2 -= y;
            h2.extract(y);
        }
        while (SZ(h2) && *h1.begin() > *h2.begin()){
            int y = *h1.begin(), z = *h2.begin();
            h1.extract(y);
            s1 += z - y;
            h1.insert(z);
            h2.extract(z);
            h2.insert(y);
            s2 += y - z;
        }
        ll t = s2 - s1 + cnt % 2 * (*h1.begin());
        return t <= k;
    };
    auto era = [&](int x){
        cnt--;
        if (h1.count(a[x])) {
            s1 -= a[x];
            h1.extract(a[x]);
        }
        else {
            h2.extract(a[x]);
            s2 -= a[x];
        }
    };
    for (int i = 1,j = 1;i <= n;i++){
        while (j <= n && ins(j)){
            // cout << i <<  ' ' << j << ' ' << s1 << ' ' << s2 << endl;
            j++;
        }
        // cout << i << ' ' << j << ' ' << s1 << ' ' << s2 << endl;
        if (j <= n) era(j);
        ans = max(ans,cnt);
        era(i);
    }
    cout << ans << "\n";
}

int main(){
    // freopen("input.txt","r",stdin);
    // freopen("3.txt","w",stdout);
    IOS
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 188ms
memory: 5520kb

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:

wrong answer 11101st lines differ - expected: '40384', found: '40322'