답안 #230068

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
230068 2020-05-08T05:16:16 Z dantoh000 역사적 조사 (JOI14_historical) C++14
100 / 100
363 ms 10704 KB
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int,int,int> iii;
typedef long long ll;
const int N = 100005;
const int BK = 300;
int n,q;
int ct[N];
int a[N];
vector<int> v;
unordered_map<int,int> ID;
ll ans[N];
ll cur = 0;
vector<iii> qu[N/BK+1];
int add[N];
bool cmp(iii a, iii b){
    return (get<1>(a) < get<1>(b));
}
void ADD(int id){
    //printf("adding %d\n",id);
    ct[a[id]]++;
    cur = max(cur,(ll)ct[a[id]]*v[a[id]]);
}
void remove(int id){
    //printf("removing %d\n",id);
    ct[a[id]]--;
}
int main(){
    scanf("%d%d",&n,&q);
    for (int i = 1 ; i <= n; i++) {
        scanf("%d",&a[i]);
        v.push_back(a[i]);
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    for (int i = 0; i < (int) v.size(); i++){
        ID[v[i]] = i;
    }
    for (int i = 1; i <= n; i++){
        a[i] = ID[a[i]];
    }
    for (int i = 0; i < q; i++){
        int l,r;
        scanf("%d%d",&l,&r);
        qu[l/BK].emplace_back(l,r,i);
    }
    int R;
    int L_;
    for (int Q = 0; Q <= n/BK; Q++){
        cur =  0;
        L_ = R = (Q*BK)+BK;
        bool first = true;
        memset(ct,0,sizeof(ct));
        //printf("%d %d\n",Q,(int)qu[Q].size());
        sort(qu[Q].begin(),qu[Q].end(),cmp);
        for (auto q : qu[Q]){
            int l,r,id;
            tie(l,r,id) = q;
            vector<int> used;
            if (r < L_){
                //printf("WITHIN %d %d\n",l,r);
                for (int i = l; i <= r; i++){
                    used.push_back(a[i]);
                    ct[a[i]]++;
                    ans[id] = max(ans[id],(ll)ct[a[i]]*v[a[i]]);
                }
                for (auto x : used) ct[x] = 0;
                used.clear();
                continue;
            }
            else{
                if (first){ ADD(R); first =  false; }
                while (R < r){
                    R++;
                    ADD(R);
                }
            }
            for (int i = L_-1; i >= l; i--){
                used.push_back(a[i]);
                add[a[i]]++;
            }
            ans[id] = cur;
            for (auto x : used){
                if (add[x] == 0) continue;
                ans[id] = max(ans[id],(ll)(ct[x]+add[x])*v[x]);
                add[x] = 0;
            }
            //printf("%d %d %lld\n",l,r,ans[id]);
        }
    }
    for (int i = 0; i < q; i++){
        printf("%lld\n",ans[i]);
    }



}

Compilation message

historic.cpp: In function 'int main()':
historic.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&q);
     ~~~~~^~~~~~~~~~~~~~
historic.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
         ~~~~~^~~~~~~~~~~~
historic.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&l,&r);
         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 768 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
6 Correct 6 ms 768 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 5 ms 768 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 5 ms 768 KB Output is correct
15 Correct 5 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 9 ms 896 KB Output is correct
5 Correct 13 ms 896 KB Output is correct
6 Correct 16 ms 1024 KB Output is correct
7 Correct 17 ms 1024 KB Output is correct
8 Correct 17 ms 1024 KB Output is correct
9 Correct 16 ms 1024 KB Output is correct
10 Correct 20 ms 1152 KB Output is correct
11 Correct 19 ms 1280 KB Output is correct
12 Correct 24 ms 1152 KB Output is correct
13 Correct 23 ms 1152 KB Output is correct
14 Correct 17 ms 1152 KB Output is correct
15 Correct 18 ms 1152 KB Output is correct
16 Correct 16 ms 1024 KB Output is correct
17 Correct 15 ms 1152 KB Output is correct
18 Correct 18 ms 1152 KB Output is correct
19 Correct 18 ms 1152 KB Output is correct
20 Correct 18 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 768 KB Output is correct
5 Correct 6 ms 896 KB Output is correct
6 Correct 6 ms 896 KB Output is correct
7 Correct 7 ms 896 KB Output is correct
8 Correct 10 ms 1152 KB Output is correct
9 Correct 15 ms 1536 KB Output is correct
10 Correct 17 ms 1532 KB Output is correct
11 Correct 136 ms 5464 KB Output is correct
12 Correct 35 ms 2416 KB Output is correct
13 Correct 80 ms 3696 KB Output is correct
14 Correct 139 ms 6896 KB Output is correct
15 Correct 106 ms 10192 KB Output is correct
16 Correct 203 ms 9292 KB Output is correct
17 Correct 107 ms 3184 KB Output is correct
18 Correct 192 ms 6040 KB Output is correct
19 Correct 224 ms 10704 KB Output is correct
20 Correct 98 ms 7504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 1280 KB Output is correct
2 Correct 55 ms 2040 KB Output is correct
3 Correct 88 ms 2680 KB Output is correct
4 Correct 121 ms 3828 KB Output is correct
5 Correct 159 ms 4720 KB Output is correct
6 Correct 194 ms 4980 KB Output is correct
7 Correct 198 ms 5360 KB Output is correct
8 Correct 220 ms 6256 KB Output is correct
9 Correct 244 ms 7024 KB Output is correct
10 Correct 282 ms 6896 KB Output is correct
11 Correct 266 ms 7152 KB Output is correct
12 Correct 295 ms 7152 KB Output is correct
13 Correct 330 ms 7616 KB Output is correct
14 Correct 341 ms 8816 KB Output is correct
15 Correct 363 ms 10448 KB Output is correct
16 Correct 356 ms 9328 KB Output is correct
17 Correct 339 ms 9200 KB Output is correct
18 Correct 345 ms 8940 KB Output is correct
19 Correct 356 ms 8816 KB Output is correct
20 Correct 356 ms 8944 KB Output is correct
21 Correct 342 ms 8816 KB Output is correct
22 Correct 339 ms 8816 KB Output is correct
23 Correct 348 ms 8556 KB Output is correct
24 Correct 345 ms 8560 KB Output is correct
25 Correct 259 ms 7664 KB Output is correct