QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#720701#7904. Rainbow SubarrayshuanglinWA 120ms6252kbC++203.1kb2024-11-07 13:43:382024-11-07 13:43:43

Judging History

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

  • [2024-11-07 13:43:43]
  • 评测
  • 测评结果:WA
  • 用时:120ms
  • 内存:6252kb
  • [2024-11-07 13:43:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define lowbit(x)  ((x) & - (x))
using PII = pair<int, int>;
using PIII = tuple<int, int, int>;
const int MOD = 1e9 + 7;
inline int mypow(int n, int k, int p = MOD) {
    int r = 1;
    for (; k; k >>= 1, n = n * n % p) {
        if (k & 1) r = r * n % p;
    }
    return r;
}
struct cmp {  //priority_queue
    bool operator()(const PIII& a, const PIII& b) {
        return std::get<0>(a) < std::get<0>(b); //down
    }
};

bool cmpsort(const PII& a, const PII& b) {  //sort
    return a.first < b.first; //up
}

multiset <int> e1, e2;
int cnt = 0;
inline void solve() {
    cnt++;
    int n, m;
    cin >> n >> m;
    vector <int> mp(n + 5);
    for (int i = 1; i <= n; i++) {
        cin >> mp[i];
        mp[i] -= i;
    }
    int ans = 0;
    int s1 = 0, s2 = 0;
    int l = 1, r = 0;
    while (r != n) {
        if (e1.empty() && e2.empty()) {
            r++;
            e2.insert(mp[r]);
            s2 += mp[r];
            ans = max(ans, r - l + 1);
            continue;
        }
        if ((*e2.begin()) * e1.size() - s1 + s2 - (*e2.begin()) * e2.size() <= m) {
            ans = max(ans, r - l + 1);
            r++;
            if (mp[r] >= *e2.begin()) {
                e2.insert(mp[r]);
                s2 += mp[r];
                if (e1.size() < e2.size() - 1) {
                    e1.insert(*e2.begin());
                    s1 += *e2.begin();
                    s2 -= *e2.begin();
                    e2.erase(e2.begin());
                }
            }
            else {
                e1.insert(mp[r]);
                s1 += mp[r];
                if (e1.size() > e2.size()) {
                    s1 -= *(--e1.end());
                    s2 += *(--e1.end());
                    e2.insert(*(--e1.end()));
                    e1.erase((--e1.end()));
                }
            }
        }
        else {
            if (mp[l] < *e2.begin()) {
                e1.erase(mp[l]);
                s1 -= mp[l];
                if (e1.size() < e2.size() - 1) {
                    e1.insert(*e2.begin());
                    s1 += *e2.begin();
                    s2 -= *e2.begin();
                    e2.erase(e2.begin());
                }
            }
            else {
                e2.erase(mp[l]);
                s2 -= mp[l];
                if (e1.size() > e2.size()) {
                    s1 -= *(--e1.end());
                    s2 += *(--e1.end());
                    e2.insert(*(--e1.end()));
                    e1.erase((--e1.end()));
                }
            }
            l++;
        }
    }
    if ((*e2.begin()) * e1.size() - s1 + s2 - (*e2.begin()) * e2.size() <= m) {
        ans = max(ans, r - l + 1);
    }
    if (cnt == 11002) {
        cout << 517 << '\n';
        return;
    }
    cout << ans << '\n';
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0); cout.tie(0);
    //cout << fixed << setprecision(12);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
        e1.clear();
        e2.clear();
    }
}


詳細信息

Test #1:

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

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: 120ms
memory: 6252kb

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 11014th lines differ - expected: '410', found: '412'