답안 #42353

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42353 2018-02-26T11:34:31 Z dqhungdl 역사적 조사 (JOI14_historical) C++14
100 / 100
191 ms 6488 KB
#include <bits/stdc++.h>
using namespace std;

struct data
{
    int l,r,id;
};

typedef pair<int,int> ii;
const int block=320;
int n,T,a[100005],Pre[100005];
int64_t rs[100005],Free[100005];
ii b[100005];
vector<data> Q[350];

bool cmp(data x1,data x2)
{
    return x1.r<x2.r;
}

int main()
{
    ios_base::sync_with_stdio(false);
    //freopen("TEST.INP","r",stdin);
    cin>>n>>T;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        b[i]=ii(a[i],i);
    }
    sort(b+1,b+n+1);
    Pre[b[1].second]=1;
    int l,r,Count=1;
    for(int i=2;i<=n;i++)
        if(b[i].first>b[i-1].first)
            Pre[b[i].second]=++Count;
        else
            Pre[b[i].second]=Count;
    for(int i=1;i<=T;i++)
    {
        cin>>l>>r;
        Q[(l-1)/block+1].push_back({l,r,i});
    }
    for(int i=1;i<=(n-1)/block+1;i++)
    {
        sort(Q[i].begin(),Q[i].end(),cmp);
        for(int j=1;j<=Count;j++)
            Free[j]=0;
        int tmp=i*block+1;
        int64_t res=0;
        for(int j=0;j<Q[i].size();j++)
        {
            int l=Q[i][j].l;
            int r=Q[i][j].r;
            int id=Q[i][j].id;
            if(r<=i*block)
            {
                for(int t=l;t<=r;t++)
                {
                    Free[Pre[t]]+=a[t];
                    rs[id]=max(rs[id],Free[Pre[t]]);
                }
                for(int t=l;t<=r;t++)
                    Free[Pre[t]]-=a[t];
            }
            else
            {
                while(tmp<=r)
                {
                    Free[Pre[tmp]]+=a[tmp];
                    res=max(res,Free[Pre[tmp]]);
                    tmp++;
                }
                rs[id]=res;
                for(int t=l;t<=i*block;t++)
                {
                    Free[Pre[t]]+=a[t];
                    rs[id]=max(rs[id],Free[Pre[t]]);
                }
                for(int t=l;t<=i*block;t++)
                    Free[Pre[t]]-=a[t];
            }
        }
    }
    for(int i=1;i<=T;i++)
        cout<<rs[i]<<"\n";
}

Compilation message

historic.cpp: In function 'int main()':
historic.cpp:51:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<Q[i].size();j++)
                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 2 ms 476 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 2 ms 612 KB Output is correct
7 Correct 2 ms 612 KB Output is correct
8 Correct 1 ms 612 KB Output is correct
9 Correct 2 ms 612 KB Output is correct
10 Correct 1 ms 612 KB Output is correct
11 Correct 2 ms 612 KB Output is correct
12 Correct 2 ms 612 KB Output is correct
13 Correct 2 ms 612 KB Output is correct
14 Correct 2 ms 612 KB Output is correct
15 Correct 1 ms 612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 612 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 612 KB Output is correct
4 Correct 3 ms 676 KB Output is correct
5 Correct 6 ms 692 KB Output is correct
6 Correct 6 ms 836 KB Output is correct
7 Correct 6 ms 836 KB Output is correct
8 Correct 7 ms 852 KB Output is correct
9 Correct 6 ms 852 KB Output is correct
10 Correct 6 ms 852 KB Output is correct
11 Correct 6 ms 916 KB Output is correct
12 Correct 9 ms 1044 KB Output is correct
13 Correct 6 ms 1044 KB Output is correct
14 Correct 8 ms 1044 KB Output is correct
15 Correct 6 ms 1044 KB Output is correct
16 Correct 8 ms 1044 KB Output is correct
17 Correct 7 ms 1044 KB Output is correct
18 Correct 8 ms 1044 KB Output is correct
19 Correct 8 ms 1044 KB Output is correct
20 Correct 6 ms 1044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1044 KB Output is correct
2 Correct 1 ms 1044 KB Output is correct
3 Correct 1 ms 1044 KB Output is correct
4 Correct 2 ms 1044 KB Output is correct
5 Correct 2 ms 1044 KB Output is correct
6 Correct 2 ms 1044 KB Output is correct
7 Correct 3 ms 1044 KB Output is correct
8 Correct 5 ms 1044 KB Output is correct
9 Correct 8 ms 1068 KB Output is correct
10 Correct 28 ms 1452 KB Output is correct
11 Correct 71 ms 5164 KB Output is correct
12 Correct 25 ms 5164 KB Output is correct
13 Correct 42 ms 5164 KB Output is correct
14 Correct 66 ms 5164 KB Output is correct
15 Correct 74 ms 6488 KB Output is correct
16 Correct 128 ms 6488 KB Output is correct
17 Correct 50 ms 6488 KB Output is correct
18 Correct 90 ms 6488 KB Output is correct
19 Correct 97 ms 6488 KB Output is correct
20 Correct 55 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 6488 KB Output is correct
2 Correct 22 ms 6488 KB Output is correct
3 Correct 35 ms 6488 KB Output is correct
4 Correct 50 ms 6488 KB Output is correct
5 Correct 69 ms 6488 KB Output is correct
6 Correct 83 ms 6488 KB Output is correct
7 Correct 85 ms 6488 KB Output is correct
8 Correct 104 ms 6488 KB Output is correct
9 Correct 119 ms 6488 KB Output is correct
10 Correct 182 ms 6488 KB Output is correct
11 Correct 124 ms 6488 KB Output is correct
12 Correct 137 ms 6488 KB Output is correct
13 Correct 134 ms 6488 KB Output is correct
14 Correct 171 ms 6488 KB Output is correct
15 Correct 191 ms 6488 KB Output is correct
16 Correct 183 ms 6488 KB Output is correct
17 Correct 181 ms 6488 KB Output is correct
18 Correct 182 ms 6488 KB Output is correct
19 Correct 159 ms 6488 KB Output is correct
20 Correct 167 ms 6488 KB Output is correct
21 Correct 157 ms 6488 KB Output is correct
22 Correct 157 ms 6488 KB Output is correct
23 Correct 162 ms 6488 KB Output is correct
24 Correct 175 ms 6488 KB Output is correct
25 Correct 186 ms 6488 KB Output is correct