UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213970#2380. 中位数erican601012ms12904kbC++112.1kb2024-11-14 20:29:202024-11-14 23:06:02

answer

// Problem: A. 中位数
// Contest: undefined - NOIP2024训练赛 05
// URL: http://noi.ac/contest/1157/problem/2380
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// Challenger: Erica N
// ----
// 
#include<bits/stdc++.h>

using namespace std;
#define rd read()
#define ull unsigned long long
#define int long long 
#define pb push_back
#define itn int
#define ps second 
#define pf first


#define rd read()
int read(){
  int xx = 0, ff = 1;char ch = getchar();
  while (ch < '0' || ch > '9'){
    if (ch == '-')ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')xx = xx * 10 + (ch - '0'), ch = getchar();
  return xx * ff;
}
#define zerol = 1
#ifdef zerol
#define cdbg(x...) do { cerr << #x << " -> "; err(x); } while (0)
void err() {cerr << endl;}
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
	for (auto v: a) cerr << v << ' ';err(x...);
}
template<typename T, typename... A>
void err(T a, A... x) {
	cerr << a << ' ';err(x...);
}
#else
#define dbg(...)
#endif
const int N=6e5+5;
const int M=3e5;
const ull P=137;
const int INF=1e18+7;
/*

策略


*/	



namespace BIT{
	int c[N];
	void change(int x,int v){
		x+=M;
		while(x<N){
			c[x]+=v;
			x+=x&-x;
		}
	}
	int query(int x){
		x+=M;
		int res=0;
		while(x){
			res+=c[x];
			x-=x&-x;
		}
		return res;
	}

}using namespace BIT;

int pre[N];
int a[N],b[N];
int n;

int check(int x){
	for(int i=1;i<=n;i++){
		pre[i]=pre[i-1]+(a[i]>=x);
	}
	
	memset(c,0,sizeof c);
	int res=0;
	change(0,1);
	for(int i=1;i<=n;i++){
		res+=query(i/2-pre[i]);
	// cdbg("UJD",i);
		change(i/2-pre[i],1);
	}
	
	// cdbg(x,res);
	return res;
}

signed main(){
	 n=rd;
	for(int i=1;i<=n;i++){
		b[i]=a[i]=rd;
	}
	
	int tot=(1+n)*n/2;
	sort(b+1,b+n+1);
	int len=unique(b+1,b+n+1)-b-1;
	int l=1,r=len;
	int res=0;
	
	// cdbg(tot);
	
	
	// cdbg("OK");
	while(l<=r){
		int mid=l+r>>1;
		// cdbg(l,r);
		if(check(b[mid])>=tot/2)res=mid,r=mid-1;
		else l=mid+1;
	}
	
	cout<<b[res]<<endl;
	
	
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 4ms
memory: 5880kb

input:

200
247837946 222748444 549404903 934970141 181690491 116150147 755881953 912914845 578004877 589768...

output:

411892743

result:

ok 1 number(s): "411892743"

Test #2:

score: 10
Accepted
time: 0ms
memory: 5876kb

input:

200
504553675 321343511 781936447 172776833 779139954 643752948 106 164 303976944 828799931 11502170...

output:

451369372

result:

ok 1 number(s): "451369372"

Test #3:

score: 0
Wrong Answer
time: 4ms
memory: 5876kb

input:

200
738368650 91602659 340556191 835209882 409442204 656938221 258295858 90658347 126689369 56196859...

output:

423214040

result:

wrong answer 1st numbers differ - expected: '420852999', found: '423214040'

Test #4:

score: 0
Wrong Answer
time: 8ms
memory: 5988kb

input:

5000
300051244 685920750 122806687 315801142 33592358 339985437 262520930 380010194 687330910 550362...

output:

465222581

result:

wrong answer 1st numbers differ - expected: '465193387', found: '465222581'

Test #5:

score: 10
Accepted
time: 7ms
memory: 5984kb

input:

5000
108135249 950186870 146626753 682580494 744412491 4159 995071655 157947560 668940645 878891308 ...

output:

466892796

result:

ok 1 number(s): "466892796"

Test #6:

score: 0
Wrong Answer
time: 4ms
memory: 5984kb

input:

5000
246610103 780664789 678774940 716124165 518453378 300121008 135383319 939869983 430946660 13412...

output:

470538762

result:

wrong answer 1st numbers differ - expected: '470507384', found: '470538762'

Test #7:

score: 10
Accepted
time: 242ms
memory: 12904kb

input:

300000
786856547 380253059 684225515 795392038 881780483 18437791 793783577 832330260 801624996 3466...

output:

463539280

result:

ok 1 number(s): "463539280"

Test #8:

score: 0
Wrong Answer
time: 252ms
memory: 12904kb

input:

300000
951000485 930070933 3566360 157114366 150196488 611226665 123590886 950624066 472150346 57976...

output:

462340870

result:

wrong answer 1st numbers differ - expected: '462334620', found: '462340870'

Test #9:

score: 10
Accepted
time: 253ms
memory: 12904kb

input:

300000
728509094 406128756 696166390 756254976 31403187 672131182 35544213 870708756 3659210 5227553...

output:

464162969

result:

ok 1 number(s): "464162969"

Test #10:

score: 10
Accepted
time: 238ms
memory: 12904kb

input:

300000
804874490 52247250 546638789 400214210 383796618 47995083 814777769 507157584 466189162 28296...

output:

463577194

result:

ok 1 number(s): "463577194"