QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#298317 | #7904. Rainbow Subarray | ucup-team1516# | WA | 1395ms | 6180kb | C++20 | 3.0kb | 2024-01-05 23:49:28 | 2024-01-05 23:49:29 |
Judging History
answer
#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while(t--) {
int n;
long long k;
cin >> n >> k;
vector<int>a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
a[i] -= i;
}
int l = 1,r = n+1;
while(l+1 < r) {
int mid = (l+r)/2;
multiset<int>st1,st2;
long long sum1 = 0,sum2 = 0;
for(int i = 0; i < mid; i++) {
st1.insert(a[i]);
sum1 += a[i];
if(st1.size() > st2.size()+1) {
int b = *st1.rbegin();
sum1 -= b;
sum2 += b;
st2.insert(b);
st1.erase(st1.find(b));
}
}
bool flag = false;
int b = *st1.rbegin();
if(sum2-1ll*st2.size()*b+1ll*st1.size()*b-sum1 <= k) {
flag = true;
}
for(int i = mid; i < n; i++) {
if(*st1.rbegin() < a[i]) {
st2.insert(a[i]);
sum2 += a[i];
}
else {
st1.insert(a[i]);
sum1 += a[i];
}
if(st1.count(a[i-mid])) {
st1.erase(st1.find(a[i-mid]));
sum1 -= a[i-mid];
}
else {
st2.erase(st2.find(a[i-mid]));
sum2 -= a[i-mid];
}
while(st1.size() > st2.size()+1) {
int b = *st1.rbegin();
sum1 -= b;
sum2 += b;
st2.insert(b);
st1.erase(st1.find(b));
}
while(st2.size() > st1.size()) {
int b = *st2.begin();
sum2 -= b;
sum1 += b;
st1.insert(b);
st2.erase(st2.find(b));
}
int b = *st1.rbegin();
if(sum2-1ll*st2.size()*b+1ll*st1.size()*b-sum1 <= k) {
flag = true;
}
}
if(flag) {
l = mid;
}
else {
r = mid;
}
}
cout << l << "\n";
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3520kb
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: 1395ms
memory: 6180kb
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 5 3 2 6 5 7 2 5 1 4 1 1 3 3 3 7 9 7 7 1 7 8 2 4 3 1 6 7 7 3 4 3 10 3 8 6 6 3 1 6 3 1 3 5 6 4 6 4 1 4 7 1 8 3 5 6 9 1 7 5 3 1 6 4 5 3 3 3 6 2 3 10 1 4 3 2 4 5 1 7 5 5 5 8 5 3 6 3 5 7 9 5 4 5 2 1 5 2 3 3 4 8 1 3 1 2 2 8 5 1 6 8 1 8 4 5 6 6 8 4 8 3 2 8 4 5 6 2 7 2 4 1 5 5 5 3 3 4 1 2 1 4 5 9 4 7 3 3 ...
result:
wrong answer 2nd lines differ - expected: '4', found: '5'