60分,超时

P2367 语文成绩

gigo_64 @ 2017-07-10 10:52:38

#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
    int n,p,a[5000001],x,y,z;
    scanf("%d%d",&n,&p);
    for(int i=1;i<=n;++i)
      scanf("%d",&a[i]);
    for(int i=1;i<=p;++i)
    {
        scanf("%d%d%d",&x,&y,&z);
        for(int j=x;j<=y;++j)
          a[j]+=z;
    }
    sort(a+1,a+n+1);
    printf("%d",a[1]);
    return 0;
}

by gigo_64 @ 2017-07-10 10:53:47

求大神给一个不超时的解答


by sslzhx @ 2017-07-11 10:40:10

平衡树

/*#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<ctime>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<iomanip>
#include<algorithm>
int main()
{
    int k[5000001],i,a,b,c,d,z,m,t;
    scanf("%d%d",&a,&b);
    for(i=0;i<a;i++)
        scanf("%d",&k[i]);
    for(i=a-1;i>0;i--)
        k[i]=k[i]-k[i-1];
    for(i=0;i<b;i++)
    {
        scanf("%u%u%u",&c,&d,&z);
        k[c-1]+=z;
        k[d]-=z;
    }
    t=k[0];
    for(i=1;i<a;i++)
    {
        k[i]+=k[i-1];
        t=k[i]-t;
    }
    m=k[0];
    for(i=1;i<a;i++)
    {
        if(m>k[i])
        m=k[i];
    }
    printf("%u",m);
}*/

|