P1168 median, p1168 Median
Description
A non-negative integer sequence A [I] with the length of N is given. For all 1 ≤ k ≤ (N + 1)/2, output A [1], A [3], ..., The median of A [2 k-1. [Color = red]: 1, 3, 5 ,...... The median of the number.
Input/Output Format
Input Format:
The 1st behavior of the input file median. in is a positive integer N, indicating the sequence length.
Row 2nd contains N non-negative integers A [I] (A [I] ≤ 10 ^ 9 ).
Output Format:
Output file median. out contains (N + 1)/2 rows, I behavior A [1], A [3],…, The median of A [2i-1.
Input and Output sample
Input example #1:
71 3 5 7 9 11 6
Output sample #1:
1356
Description
For 20% of data, N ≤ 100;
For 40% of data, N ≤ 3000;
For 100% of data, N ≤ 100000.
Compilation is not capable of AC
Although I do not know how to AC it ..
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<ext/pb_ds/assoc_container.hpp> 6 #include<ext/pb_ds/tree_policy.hpp> 7 #include<functional> 8 using namespace std; 9 using namespace __gnu_pbds;10 void read(int & n)11 {12 char c='+';int x=0;int flag=0;13 while(c<'0'||c>'9')14 { c=getchar(); if(c=='-') flag=1; }15 while(c>='0'&&c<='9')16 {x=x*10+(c-48);c=getchar();}17 flag==1?n=-x:n=x;18 }19 int main()20 {21 int n;int p;22 read(n);23 //tree<int , null_type , less_equal<int> , rb_tree_tag , tree_order_statistics_node_update>t;24 tree<int, null_type, std::less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> t;25 for(int i=1;i<=n;i++)26 {27 read(p);28 t.insert(p);29 if(i%2==1)30 printf("%d\n", *t.find_by_order(i / 2 ));31 }32 return 0;33 }