QwQ,快排40分,(雾:AC AC WA TLE TLE

P1923 【深基9.例4】求第 k 小的数

Max6700 @ 2023-05-10 22:40:06

#include<bits/stdc++.h>
using namespace std;

int n,m;
int a[5000010];

int main(){

    scanf("%d %d",&n,&m);

    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }

    sort(a+1,a+n);

    cout<<a[m+1];

    return 0;
}

by GWBailang @ 2023-05-10 22:41:36

@Max6700 首先呢,你最好开long long。


by Max6700 @ 2023-05-10 22:43:11

@GWBailang 好哒好哒,其次捏?


by tZEROちゃん @ 2023-05-10 23:03:00

@Max6700 a+1,a+n+1


by tZEROちゃん @ 2023-05-10 23:04:21

不用开ll,1e9在int范围捏@gwbailang


by Max6700 @ 2023-05-11 06:46:40

@tZEROちゃん 啊谢谢,问题是还有2个TLE啊


by GeorgeAAAADHD @ 2023-05-11 07:07:18

@Max6700 可以加上这一条然后改 cin

ios::sync_with_stdio(false);

cin.tie(0);


by tZEROちゃん @ 2023-05-11 12:07:17

@Max6700 nlogn的复杂的过不了5e6吧,尝试使用o(n)的算法


by GWBailang @ 2023-05-11 12:49:15

首先如果题目的范围接近1e9,最好开long long

然后这个sort应该是sort(a+1,a+n+1)

最后呢,sort的时间复杂度肯定会超


by Max6700 @ 2023-05-11 18:08:36

@GeorgeAAAADHD

大雾:

21ms/1.21MB
AC
#1
Accepted, 得分 20.ok accepted

20ms/1.12MB
AC
#2
Accepted, 得分 20.ok accepted

19ms/992.00KB
AC
#3
Accepted, 得分 20.ok accepted

1.19s/34.41MB
TLE
#4
Time Limit Exceeded.

1.20s/38.55MB
TLE
#5
Time Limit Exceeded.

by Max6700 @ 2023-05-11 18:10:03

@tZEROちゃん 桶?还是啥?QAQ


| 下一页