QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#695663 | #7904. Rainbow Subarray | Traveler | WA | 147ms | 7660kb | C++20 | 3.6kb | 2024-10-31 20:32:19 | 2024-10-31 20:32:25 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<stdlib.h>
#include<unordered_map>
#include<vector>
#include<array>
#include<math.h>
#include<map>
#include<stdio.h>
#include<queue>
#include<assert.h>
#include<string>
#include<limits.h>
#include<stack>
#include<set>
#include<list>
#include<algorithm>
#include <chrono>
#include<random>
using namespace std;
//
//typedef long long LL;
//#define int long long
//typedef unsigned long long ULL;
//typedef pair<LL, LL>PII;
//typedef pair<double, double>PDD;
//typedef pair<char, char>PCC;
//LL n, m, k;
//
//const LL inf = 1e18;
//const LL N = 1e6 + 10;
//const LL mod = 1e9 + 7;
//const LL mod2 = 998244353;
//
//
//signed main() {
// std::ios::sync_with_stdio(false);
// std::cin.tie(nullptr);
//
// int t = 1;
// //cin >> t;
// while (t--) {
// solve();
// }
//
// return 0;
//}
#define int long long
#define MAXN 500000
using namespace std;
int T;
int N, K;
int A[MAXN + 5];
priority_queue<pair<int, int> > q1;
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q2;
int l = 1, r = 0;
int cnt1 = 0, cnt2 = 0, tmp = 0, sum1 = 0, sum2 = 0, num1 = 0, num2 = 0, ans = 0;
int calc() {
return (tmp * num1 - sum1) + (sum2 - tmp * num2);
}
void adjust() {
while (num1 < num2&&!q2.empty()) {
pair<int, int> t = q2.top();q2.pop();
if (t.second < l)continue;
q1.push(t);
num1++;
num2--;
sum1 += t.first;
sum2 -= t.first;
}
while (num1 > num2 + 1&&!q1.empty()) {
pair<int, int> t = q1.top();q1.pop();
if (t.second < l)continue;
q2.push(t);
num1--;
num2++;
sum1 -= t.first;
sum2 += t.first;
}
if (!q1.empty())tmp = q1.top().first;
}
signed main()
{
//ios::sync_with_stdio(false);
//cin.tie(0);
cin >> T;
while (T--) {
while (!q1.empty())q1.pop();
while (!q2.empty())q2.pop();
cnt1 = 0, cnt2 = 0, tmp = A[1], sum1 = 0, sum2 = 0, num1 = 0, num2 = 0, ans = 0;
l = 1, r = 0;
cin >> N >> K;
for (int i = 1;i <= N;i++) {
cin >> A[i];
A[i] -= i;
}
for (int i = 1;i <= N;i++) {
while (l <= r && calc() > K) {
while (!q2.empty() && q2.top().second < l) {
q2.pop();
}
while (!q1.empty() && q1.top().second < l) {
q1.pop();
}
if (A[l] > tmp) {
num2--;
sum2 -= A[l];
}
else {
num1--;
sum1 -= A[l];
}
l++;
adjust();
}
ans = max(ans, num1 + num2);
if (A[i] > tmp) {
q2.push(pair<int, int>(A[i], i));
sum2 += A[i];
num2++;
}
else {
q1.push(pair<int, int>(A[i], i));
sum1 += A[i];
num1++;
}
r++;
adjust();
}
while (l <= r && calc() > K) {
if (A[l] > tmp) {
num2--;
sum2 -= A[l];
}
else {
num1--;
sum1 -= A[l];
}
l++;
adjust();
}
ans = max(ans, num1 + num2);
cout << ans << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
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: 147ms
memory: 7660kb
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 4309th lines differ - expected: '5', found: '4'