QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#588825#7904. Rainbow SubarrayAlumin1um#RE 0ms6940kbC++232.9kb2024-09-25 14:47:022024-09-25 14:47:03

Judging History

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

  • [2024-09-25 14:47:03]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:6940kb
  • [2024-09-25 14:47:02]
  • 提交

answer

#include <bits/stdc++.h>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pdd pair<double, double>
#define vi vector<int>
#define vll vector<long long>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long, long long>>
#define vpdd vector<pair<double, double>>
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pb push_back
#define endl "\n"
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>

using namespace std;
using LL = long long;
using ULL = unsigned long long;
const int N = 5e5 + 10, INF = 0x3f3f3f3f, mod = 998244353;
const LL bigINF = ((ULL)(1) << 63) - 1;
const double eps = 1e-6;
LL n, k;
vll a(N);

void Sol()
{

    cin >> n >> k;
    for (int i(1); i <= n; ++i)
    {
        cin >> a[i];
        a[i] -= i;
    }

    multiset<int> lo, hi;
    LL minus = 0, plus = 0, l = 1, r = 1, ans = 0;
    while (l <= n && r <= n)
    {
        while (lo.size() > hi.size())
        {
            int mid = *--lo.end();
            minus -= mid;
            plus += mid;
            hi.insert(mid);
            lo.erase(--lo.end());
        }
        while (hi.size() > lo.size() + 1)
        {
            int mid = *hi.begin();
            plus -= mid;
            minus += mid;
            hi.erase(hi.begin());
            lo.insert(mid);
        }
        while (!lo.size() || lo.size() * *--lo.end() - minus + plus - hi.size() * *--lo.end() <= k)
        {
            if (lo.size() <= hi.size())
            {
                plus += a[r];
                hi.insert(a[r]);
                int mid = *hi.begin();
                hi.erase(hi.begin());
                lo.insert(mid);
                plus -= mid;
                minus += mid;
            }
            else
            {
                minus += a[r];
                lo.insert(a[r]);
                int mid = *--lo.end();
                lo.erase(--lo.end());
                hi.insert(mid);
                minus -= mid;
                plus += mid;
            }
            if (lo.size() * *--lo.end() - minus + plus - hi.size() * *--lo.end() <= k)
                ans = max(ans, r - l + 1);
            else
                break;
            r++;
            if (r > n)
                break;
        }
        if (r > n)
            break;
        int old = a[l];
        if (old <= *--lo.end())
        {
            minus -= old;
            lo.erase(lo.lower_bound(old));
        }
        else
        {
            plus -= old;
            hi.erase(hi.lower_bound(old));
        }
        l++;
        r = max(r, l);
    }

    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int t = 1;
    cin >> t;
    while (t--)
    {
        Sol();
    }

    return 0;
}

详细

Test #1:

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

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
Runtime Error

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:


result: