답안 #6718

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
6718 2014-07-05T02:53:37 Z gs13068 역사적 조사 (JOI14_historical) C++
100 / 100
1100 ms 201576 KB
#include<cstdio>
#include<memory.h>
#include<algorithm>

int a[100000];
int b[100000];
int c[100000];
int d[500][100000];
long long x[500][500];

char ss[2097152];

inline int getnum()
{
    int t,r=0;
    do{t=getchar();}while(t<40);
    do{r=r*10+t-48;t=getchar();}while(t>40);
    return r;
}

int main()
{
    char *p;
    long long r;
    int s,e,t;
    int i,j,k,n,m;
    scanf("%d %d\n",&n,&m);
    fgets(ss,2097151,stdin);
    p=ss;
    for(i=0;i<n;i++)
    {
        while(*p<40)p++;
        while(*p>40)
        {
            a[i]=a[i]*10+*p-48;
            p++;
        }
        b[i]=a[i];
    }
    std::sort(b,b+n);
    for(i=0;i<n;i++)a[i]=std::lower_bound(b,b+n,a[i])-b;
    for(i=0;i<n;i++)
    {
        if(i>0&&(i&255)==0)memcpy(d[i>>8],d[(i>>8)-1],n<<2);
        d[i>>8][a[i]]++;
    }
    for(i=0;i<(n>>8);i++)
    {
        memset(c,0,n<<2);
        for(j=i;j<(n>>8);j++)
        {
            if(j>i)x[i][j]=x[i][j-1];
            for(k=0;k^256;k++)
            {
                t=(j<<8)|k;
                c[a[t]]++;
                if(1LL*b[a[t]]*c[a[t]]>x[i][j])x[i][j]=1LL*b[a[t]]*c[a[t]];
            }
        }
    }
    memset(c,0,n<<2);
    for(i=0;i<m;i++)
    {
        s=getnum()-1;e=getnum();
        if(((~-s)>>8)+1<(e>>8))
        {
            r=x[((~-s)>>8)+1][(e>>8)-1];
            for(j=s;j<(((~-s)>>8)+1<<8);j++)
			{
				c[a[j]]++;
				if(1LL*b[a[j]]*(c[a[j]]+d[(e>>8)-1][a[j]]-(((~-s)>>8)+1>0?d[(~-s)>>8][a[j]]:0))>r)r=1LL*b[a[j]]*(c[a[j]]+d[(e>>8)-1][a[j]]-(((~-s)>>8)+1>0?d[(~-s)>>8][a[j]]:0));
			}
            for(j=((e>>8)<<8);j<e;j++)
			{
				c[a[j]]++;
				if(1LL*b[a[j]]*(c[a[j]]+d[(e>>8)-1][a[j]]-(((~-s)>>8)+1>0?d[(~-s)>>8][a[j]]:0))>r)r=1LL*b[a[j]]*(c[a[j]]+d[(e>>8)-1][a[j]]-(((~-s)>>8)+1>0?d[(~-s)>>8][a[j]]:0));
			}
            for(j=s;j<(((~-s)>>8)+1<<8);j++)c[a[j]]=0;
            for(j=((e>>8)<<8);j<e;j++)c[a[j]]=0;
        }
        else
        {
            r=0;
            for(j=s;j<e;j++)
			{
				c[a[j]]++;
				if(1LL*b[a[j]]*c[a[j]]>r)r=1LL*b[a[j]]*c[a[j]];
			}
            for(j=s;j<e;j++)c[a[j]]=0;
        }
        printf("%lld\n",r);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 201576 KB Output is correct
2 Correct 0 ms 201576 KB Output is correct
3 Correct 0 ms 201576 KB Output is correct
4 Correct 0 ms 201576 KB Output is correct
5 Correct 0 ms 201576 KB Output is correct
6 Correct 0 ms 201576 KB Output is correct
7 Correct 0 ms 201576 KB Output is correct
8 Correct 0 ms 201576 KB Output is correct
9 Correct 0 ms 201576 KB Output is correct
10 Correct 0 ms 201576 KB Output is correct
11 Correct 0 ms 201576 KB Output is correct
12 Correct 0 ms 201576 KB Output is correct
13 Correct 0 ms 201576 KB Output is correct
14 Correct 0 ms 201576 KB Output is correct
15 Correct 0 ms 201576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 201576 KB Output is correct
2 Correct 0 ms 201576 KB Output is correct
3 Correct 0 ms 201576 KB Output is correct
4 Correct 0 ms 201576 KB Output is correct
5 Correct 4 ms 201576 KB Output is correct
6 Correct 8 ms 201576 KB Output is correct
7 Correct 4 ms 201576 KB Output is correct
8 Correct 8 ms 201576 KB Output is correct
9 Correct 4 ms 201576 KB Output is correct
10 Correct 12 ms 201576 KB Output is correct
11 Correct 8 ms 201576 KB Output is correct
12 Correct 12 ms 201576 KB Output is correct
13 Correct 12 ms 201576 KB Output is correct
14 Correct 12 ms 201576 KB Output is correct
15 Correct 4 ms 201576 KB Output is correct
16 Correct 8 ms 201576 KB Output is correct
17 Correct 8 ms 201576 KB Output is correct
18 Correct 12 ms 201576 KB Output is correct
19 Correct 12 ms 201576 KB Output is correct
20 Correct 8 ms 201576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 201576 KB Output is correct
2 Correct 0 ms 201576 KB Output is correct
3 Correct 0 ms 201576 KB Output is correct
4 Correct 0 ms 201576 KB Output is correct
5 Correct 0 ms 201576 KB Output is correct
6 Correct 0 ms 201576 KB Output is correct
7 Correct 0 ms 201576 KB Output is correct
8 Correct 4 ms 201576 KB Output is correct
9 Correct 12 ms 201576 KB Output is correct
10 Correct 56 ms 201576 KB Output is correct
11 Correct 204 ms 201576 KB Output is correct
12 Correct 96 ms 201576 KB Output is correct
13 Correct 272 ms 201576 KB Output is correct
14 Correct 264 ms 201576 KB Output is correct
15 Correct 216 ms 201576 KB Output is correct
16 Correct 304 ms 201576 KB Output is correct
17 Correct 176 ms 201576 KB Output is correct
18 Correct 252 ms 201576 KB Output is correct
19 Correct 232 ms 201576 KB Output is correct
20 Correct 136 ms 201576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 201576 KB Output is correct
2 Correct 64 ms 201576 KB Output is correct
3 Correct 168 ms 201576 KB Output is correct
4 Correct 280 ms 201576 KB Output is correct
5 Correct 392 ms 201576 KB Output is correct
6 Correct 476 ms 201576 KB Output is correct
7 Correct 396 ms 201576 KB Output is correct
8 Correct 368 ms 201576 KB Output is correct
9 Correct 408 ms 201576 KB Output is correct
10 Correct 324 ms 201576 KB Output is correct
11 Correct 460 ms 201576 KB Output is correct
12 Correct 700 ms 201576 KB Output is correct
13 Correct 1048 ms 201576 KB Output is correct
14 Correct 1096 ms 201576 KB Output is correct
15 Correct 1084 ms 201576 KB Output is correct
16 Correct 1072 ms 201576 KB Output is correct
17 Correct 1088 ms 201576 KB Output is correct
18 Correct 1076 ms 201576 KB Output is correct
19 Correct 1100 ms 201576 KB Output is correct
20 Correct 1096 ms 201576 KB Output is correct
21 Correct 1064 ms 201576 KB Output is correct
22 Correct 1088 ms 201576 KB Output is correct
23 Correct 1068 ms 201576 KB Output is correct
24 Correct 1076 ms 201576 KB Output is correct
25 Correct 300 ms 201576 KB Output is correct