QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#723160#6433. Klee in Solitary ConfinementONISINORE 4ms18836kbC++201.9kb2024-11-07 21:18:472024-11-07 21:18:47

Judging History

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

  • [2024-11-07 21:18:47]
  • 评测
  • 测评结果:RE
  • 用时:4ms
  • 内存:18836kb
  • [2024-11-07 21:18:47]
  • 提交

answer

#include <bits/stdc++.h>

//DEBUG:    https://github.com/sharkdp/dbg-macro
#ifdef LOCAL
#include "../Lib/dbg-macro-0.5.1/dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif

#define endl '\n'
using namespace std;
typedef long long ll;
typedef long double llf;
const ll MAXN=2e5+10,MOD=998244353,INF=1e9;

ll qpow(ll base,ll exp){ll ans=1;while(exp){if(exp&1)(ans*=base)%=MOD;(base*=base)%=MOD;exp>>=1;}return ans;}
template<class T>ll max_binary_answer(ll l,ll r,T check,bool cmp=true){ll m;while(l<r){m=(l+r+1)/2;if(cmp^!check(m))l=m;else r=m-1;}return l;}
template<class T>ll min_binary_answer(ll l,ll r,T check,bool cmp=true){ll m;while(l<r){m=(l+r)/2;if(cmp^!check(m))r=m;else l=m+1;}return r;}
ll exgcd(ll a,ll b,ll &x,ll &y){ll tmp;return b==0?(x=1,y=0,a):(tmp=exgcd(b,a%b,y,x),y-=(a/b)*x,tmp);}
ll highbit(ll x){for(ll i=1;i<(ll)sizeof(ll)*4;i<<=1)x|=x>>i;return x-(x>>1);}
ll lowbit(ll x){return x&(-x);}
//--------Global declared area--------

//--------Global declared end --------
void solve(int test_num){
	int n,k,tmp,ans=0;
	cin>>n>>k;
	map<int,vector<int>> m;
	vector<int> cnt(4e6+5);
	for(int i=0;i<n;i++){
		cin>>tmp;
		tmp+=1000000;
		m[tmp].push_back(-1);
		m[tmp+k].push_back(1);
		cnt[tmp]++;
		ans=max(ans,cnt[tmp]);
	}
	if(k!=0){
		for(auto [x,a]:m){
			int sum=0,c=cnt[x];
			for(int i=0;i<(int)a.size();i++){
				if(sum>0){
					sum+=a[i];
				}else{
					sum=a[i];
				}
				ans=max(ans,c+sum);
			}
		}
	}
	cout<<ans<<endl;
}

int main(){
#ifdef ACM
	freopen("D:/Code/C or C++/File/input.txt","r",stdin);
	freopen("D:/Code/C or C++/File/output.txt","w",stdout);
	freopen("D:/Code/C or C++/File/error.txt","w",stderr);
#else
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr),std::cout.tie(nullptr);
#endif
	int t=1;
//	cin>>t;
	for(int i=1;i<=t;i++){
		solve(i);
		//cout.flush();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 2
2 2 4 4 4

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 4ms
memory: 18716kb

input:

7 1
3 2 3 2 2 2 3

output:

6

result:

ok 1 number(s): "6"

Test #3:

score: 0
Accepted
time: 0ms
memory: 18812kb

input:

7 1
2 3 2 3 2 3 3

output:

5

result:

ok 1 number(s): "5"

Test #4:

score: 0
Accepted
time: 0ms
memory: 18772kb

input:

9 -100
-1 -2 1 2 -1 -2 1 -2 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

score: 0
Accepted
time: 0ms
memory: 18836kb

input:

200 121649
0 527189 -1000000 -306471 -998939 527189 -1000000 -1000000 0 527189 0 527189 0 527189 -306471 -998939 -306471 -306471 -306471 0 0 527189 527189 1000000 527189 -1000000 1000000 648838 -1000000 -998939 -998939 -998939 0 1000000 -1000000 -998939 527189 1000000 648838 -1000000 1000000 648838 ...

output:

37

result:

ok 1 number(s): "37"

Test #6:

score: -100
Runtime Error

input:

200 -454379
-385892 454379 -1000000 373644 -665078 -1000000 -1000000 454379 0 1000000 373644 -1000000 1000000 -385892 -1000000 373644 0 -665078 0 -665078 -1000000 -665078 -385892 -665078 -385892 454379 -665078 -385892 -1000000 454379 1000000 -385892 373644 454379 -1000000 -385892 -1000000 -385892 -1...

output:


result: