Submission #3882041


Source Code Expand

#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

const int MX = 100005;
const int MM = 1000000007;

int A[MX];
int N;

struct BIT{
	int t[MX*2];
	int read(int x){
		int r = 0;
		while(x) r += t[x], x -= x&-x;
		return r;
	}
	int update(int x, int v){
		while(x < MX*2) t[x] += v, x += x&-x;
	}
} tree;

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", A+i);
	int s = 0, e = 1e9;
	while(s <= e){
		int m = (s+e) / 2;
		for(int i = 0; i < MX*2; i++) tree.t[i] = 0;
		int pr = 0;
		ll tot = 0;
		
		for(int i = 1; i <= N; i++){
			tree.update(N+pr, 1);
			pr += A[i] >= m? 1 : -1;
			tot += tree.read(N+pr);
		}
		tot = (ll)N*(N+1)/2 - tot;
		if(tot >= (ll)N*(N+1)/2/2+1) e = m-1;
		else s = m+1;
	}swap(s, e);
	printf("%d\n", s);
}

Submission Info

Submission Time
Task D - Median of Medians
User zigui
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2000 Byte
Status AC
Exec Time 91 ms
Memory 1408 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:74:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
./Main.cpp:75:46: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= N; i++) scanf("%d", A+i);
                                              ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 19
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt
Case Name Status Exec Time Memory
0_00.txt AC 4 ms 1024 KiB
0_01.txt AC 4 ms 1024 KiB
0_02.txt AC 4 ms 1024 KiB
1_00.txt AC 4 ms 1024 KiB
1_01.txt AC 4 ms 1024 KiB
1_02.txt AC 74 ms 1408 KiB
1_03.txt AC 75 ms 1408 KiB
1_04.txt AC 75 ms 1408 KiB
1_05.txt AC 75 ms 1408 KiB
1_06.txt AC 75 ms 1408 KiB
1_07.txt AC 74 ms 1408 KiB
1_08.txt AC 89 ms 1408 KiB
1_09.txt AC 89 ms 1408 KiB
1_10.txt AC 87 ms 1408 KiB
1_11.txt AC 88 ms 1408 KiB
1_12.txt AC 84 ms 1408 KiB
1_13.txt AC 89 ms 1408 KiB
1_14.txt AC 91 ms 1408 KiB
1_15.txt AC 90 ms 1408 KiB