2AC 4TLE 求助

P1168 中位数

@[liuxinrui09](/user/1065083) 单纯的T了,每次都排一遍序太慢了而已,建议去学习一下权值线段树
by Wunsch @ 2023-08-22 14:12:18


@[liuxinrui09](/user/1065083) ~~这里不要脸的贴一下自己的[blog](https://www.luogu.com.cn/blog/CA931/wei-wan-dai-xu)~~ (尽管我的blog珂能对大多数人来说并不友好
by Wunsch @ 2023-08-22 14:25:55


建议学习vector,很好懂 ``` #include<iostream> #include<vector> #include<algorithm> using namespace std; vector <int> s; int k,n,m; int cnt=1; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin>>k; for(int i=1;i<=k;i++) { cin>>m; s.insert(upper_bound(s.begin(),s.end(),m),m); if(i&1){ cout<<s[(1+i)/2-1]<<"\n"; } } return 0; } ``` 求关
by hgzx__lc @ 2023-09-26 14:23:36


|