QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#681139#7904. Rainbow SubarraysiyueWA 1767ms7380kbC++231.6kb2024-10-27 01:50:462024-10-27 01:50:47

Judging History

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

  • [2024-10-27 01:50:47]
  • 评测
  • 测评结果:WA
  • 用时:1767ms
  • 内存:7380kb
  • [2024-10-27 01:50:46]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<double,null_type,less<double>,rb_tree_tag,tree_order_statistics_node_update> rbt_t;

struct tree_t{
	rbt_t rbt;
	int tim;
	tree_t(){tim=0;}
	void init(){
		tim=0;
		rbt.clear();
	}

	void ins(int x){
		++tim;
		rbt.insert(x+tim*3e-7);
	}

	void del(int x){
		rbt.erase(rbt.lower_bound(x));
	}

	int kth(int k){
		return round(*rbt.find_by_order(k-1));
	}
};

template<typename Tp>
Tp read(){
	Tp res=0,sign=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-'){sign=-sign;}
	for(;ch>='0'&&ch<='9';ch=getchar()){res=(res<<3)+(res<<1)+(ch^'0');}
	return res*sign;
}

#define rep(i,l,r) for(int i=l;i<=r;++i)
#define dep(i,r,l) for(int i=r;i>=l;--i)

typedef long long ll;

const int N=5e5+10;

int n;
ll k;

int a[N];

tree_t T;	

bool check(int len){
	ll res=0;
	T.init();
	rep(i,1,len){
		T.ins(a[i]);
	}
	int f=T.kth((len+1)/2);
	rep(i,1,len){
		res+=abs(a[i]-f);
	}
	ll ans=res;
	rep(i,len+1,n){
		T.del(a[i-len]),T.ins(a[i]);
		res=res-abs(a[i-len]-f)+abs(a[i]-f);
		int _f=T.kth((len+1)/2);
		res-=abs(_f-f);
		f=_f;
		ans=min(ans,res);
	}
	return ans<=k;
}

void solve(){
	// n=read<int>(),k=read<ll>();
	scanf("%d%lld",&n,&k);
	// rep(i,1,n)a[i]=read<int>()-i;
	rep(i,1,n)scanf("%d",&a[i]),a[i]-=i;
	int l=1,r=n;
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid))l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",r);
}

int main(){
	// int t=read<int>();
	int t;scanf("%d",&t);
	while(t--)solve();
	return 0;
}

詳細信息

Test #1:

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

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: 1767ms
memory: 7380kb

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
3
1
1
4
1
2
7
8
7
7
1
7
5
2
4
3
1
6
7
7
3
4
3
9
3
8
6
6
3
1
6
3
1
2
4
5
4
6
4
2
4
7
1
6
3
5
6
6
1
7
5
3
1
6
3
5
3
2
2
6
1
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
1
4
4
4
8
1
4
1
2
2
8
3
1
6
8
1
8
4
5
6
6
7
4
8
3
2
8
4
5
6
2
6
2
4
1
5
4
5
4
2
4
1
2
1
3
5
8
3
7
3
3
4...

result:

wrong answer 11th lines differ - expected: '4', found: '3'