为啥RE?

P2367 语文成绩

D_FANG @ 2022-09-12 11:58:33

代码

#include<bits/stdc++.h>
using namespace std;
int a[500010];
int n;
void qsort(int l,int r){
    int i,j,mid;
    i=l;
    j=r;
    mid=a[(i+j)/2];
    do{
        while (a[i]<mid) i++;
        while (a[j]>mid) j--;
        if (i<=j){
            swap(a[i],a[j]);
            i++;
            j--;
        }
    }while (i<=j);
    if (i<r) qsort(i,r);
    if (l<j) qsort(l,j);
}
int q;
int main(){
    cin>>n;
    cin>>q;
    for (int i=1;i<=n;i++){
        cin>>a[i];
    }
    for (int i=1;i<=q;i++){
        int x,y,z;
        cin>>x>>y>>z;
        for (int j=x;j<=y;j++){
            a[j]+=z;
        }
    }
    qsort(1,n);
    cout<<a[1];
    return 0;
}

不开O2前,1.2.3AC,4TLE,5WA 开O2后,1,2,3,4AC,5RE


by scp020 @ 2022-09-12 12:07:25

@zhougong 仔细看题, n \le 10^6


by scp020 @ 2022-09-12 12:07:46

@zhougong 你 a 数组开的什么玩意


by D_FANG @ 2022-09-12 12:08:25

e 谢谢https://www.luogu.com.cn/user/553625


by henry123456789 @ 2022-12-04 10:55:34

数组开小了


|