QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#571036 | #9314. The Median of the Median of the Median | N_z_ | AC ✓ | 92ms | 19012kb | C++14 | 5.3kb | 2024-09-17 20:06:40 | 2024-09-18 18:13:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct time_helper
{
#ifdef LOCAL
clock_t time_last;
#endif
time_helper()
{
#ifdef LOCAL
time_last=clock();
#endif
}
void test()
{
#ifdef LOCAL
auto time_now=clock();
std::cerr<<"time:"<<1.*(time_now-time_last)/CLOCKS_PER_SEC<<";all_time:"<<1.*time_now/CLOCKS_PER_SEC<<std::endl;
time_last=time_now;
#endif
}
~time_helper()
{
test();
}
}time_helper;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
#define Setprecision 10
#define between '\n'
#define __int128 long long
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(T x){for(auto &y:x)*this<<y<<between;*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-Setprecision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(T c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(std::string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<class Fun>class y_combinator_result{Fun fun_;public:template<class T>explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}template<class ...Args>decltype(auto) operator()(Args &&...args){return fun_(std::ref(*this), std::forward<Args>(args)...);}};template<class Fun>decltype(auto) y_combinator(Fun &&fun){return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));}
void solve();
main()
{
int t=1;
// cin>>t;
while(t--)solve();
}
void solve()
{
int n;
cin>>n;
vector<int>a(n),v;
cin>>a,v=a;
sort(v.begin(),v.end());
int l=0,r=n-1,ans=-1;
auto chk=[&](int v)
{
vector<vector<int>>b(n,vector<int>(n));
for(int x=0;x<n;x++)
{
int cnt=0;
for(int y=x;y<n;y++)
{
cnt+=a[y]>=v;
b[x][y]=2*cnt>y-x+1;
if(y)b[x][y]+=b[x][y-1];
}
}
for(int x=n-2;x>=0;x--)
for(int y=x;y<n;y++)
b[x][y]+=b[x+1][y];
int cnt=0;
for(int x=0;x<n;x++)
for(int y=x;y<n;y++)
cnt+=4*b[x][y]>(y-x+1)*(y-x+2);
return cnt*4>n*(n+1);
};
while(l<=r)
{
int mi=(l+r)/2;
if(chk(v[mi]))ans=v[mi],l=mi+1;
else r=mi-1;
}
cout<<ans<<endl;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
4 1 3 1 7
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
8 3 3 8 4 5 3 8 5
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 88ms
memory: 17180kb
input:
1883 935804604 209383625 842052635 830082014 365721046 29571412 503828250 261878653 304868479 615753663 149387882 137293208 553441715 659054561 809401479 786598486 257715598 738987349 749751119 675212261 214984147 816730618 204108936 529505526 670681192 375128179 445679706 531625791 954119640 739969...
output:
484006473
result:
ok 1 number(s): "484006473"
Test #4:
score: 0
Accepted
time: 78ms
memory: 18180kb
input:
1957 872909724 707949349 490997221 189511043 696381097 482433184 174043836 548201426 788208141 757294560 536411878 361961 65102705 599648900 120639869 620050728 789988994 932102606 540785122 931710164 286821745 583586084 633444407 849735317 780584308 266550416 98570723 722783990 500921667 819344705 ...
output:
516436748
result:
ok 1 number(s): "516436748"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3792kb
input:
178 692096263 317825236 931010188 434850173 52089022 326215531 68436615 315432237 122955263 641096948 348783853 876201150 853561741 370774198 822929299 828427226 546309487 178339038 549855187 410459983 953700209 566391036 649762057 955693969 976755106 277332611 380022551 211888435 42883285 988396877...
output:
593518959
result:
ok 1 number(s): "593518959"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3752kb
input:
173 69392871 816390960 874922071 794279201 87781777 334366903 738652201 601755009 166103436 192703253 735807848 589526799 219998539 16401241 279391882 366912172 228325988 371454295 781080678 111668287 170762000 333246502 638906040 570891055 791690926 463722145 178137760 257822443 589685312 67772391 ...
output:
408439899
result:
ok 1 number(s): "408439899"
Test #7:
score: 0
Accepted
time: 87ms
memory: 19012kb
input:
2000 844787697 717725741 297174490 620713157 869654860 100305714 252182391 350740797 989692676 884515006 283929742 228386094 243395665 931009658 504278816 417368345 996825244 840349536 30435490 464970260 925567493 320798785 588704893 225104969 963755486 262212671 155822732 272322421 979407661 217426...
output:
493853563
result:
ok 1 number(s): "493853563"
Test #8:
score: 0
Accepted
time: 92ms
memory: 18984kb
input:
2000 125514461 95022349 795740214 269657744 524051185 725933061 555301058 20956383 570982744 927663180 130503343 910377386 251688610 442670648 444873155 283896336 535310191 667590228 223550748 256004263 626775796 392636383 500784551 509216248 283985276 517339979 342212266 70437630 465533157 91397139...
output:
477878585
result:
ok 1 number(s): "477878585"
Extra Test:
score: 0
Extra Test Passed