Submission #259017

# Submission time Handle Problem Language Result Execution time Memory
259017 2020-08-07T04:18:56 Z 반딧불(#5071) 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 11724 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
int sqrtN;

struct Query{
    int l, r, idx;
    Query(){}
    Query(int l, int r, int idx): l(l), r(r), idx(idx){}

    bool operator<(const Query &tmp)const{
        if(l/sqrtN != tmp.l/sqrtN) return l < tmp.l;
        return r < tmp.r;
    }
};

int n, q, k;
ll arr[100002];
vector<Query> vec;
ll cnt[100002];
ll ans[100002];
vector<ll> v;
multiset<ll> mst;

void removeNum(ll x){
    mst.erase(mst.find(cnt[x] * v[x]));
    cnt[x]--;
    mst.insert(cnt[x] * v[x]);
}
void addNum(ll x){
    mst.erase(mst.find(cnt[x] * v[x]));
    cnt[x]++;
    mst.insert(cnt[x] * v[x]);
}

void renumber(){
    for(int i=0; i<n; i++) v.push_back(arr[i]);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    for(int i=0; i<n; i++) arr[i] = lower_bound(v.begin(), v.end(), arr[i]) - v.begin();
    k = (int)v.size();
}

int main(){
    scanf("%d %d", &n, &q);
    sqrtN = ceil(sqrt(n));
    for(int i=0; i<n; i++) scanf("%lld", &arr[i]);
    renumber();
    for(int i=1; i<=q; i++){
        int l, r;
        scanf("%d %d", &l, &r);
        l--, r--;
        vec.push_back(Query(l, r, i));
    }
    sort(vec.begin(), vec.end());

    for(int i=0; i<k; i++) mst.insert(0);

    int s = 0, e = -1;
    for(int i=0; i<q; i++){
        Query tmp = vec[i];
        int l = tmp.l, r = tmp.r, idx = tmp.idx;
        while(e < r) addNum(arr[++e]);
        while(s > l) addNum(arr[--s]);
        while(e > r) removeNum(arr[e--]);
        while(s < l) removeNum(arr[s++]);
        ans[idx] = *mst.rbegin();
    }

    for(int i=1; i<=q; i++){
        printf("%lld\n", ans[i]);
    }
}

Compilation message

historic.cpp: In function 'int main()':
historic.cpp:47: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:49:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0; i<n; i++) scanf("%lld", &arr[i]);
                            ~~~~~^~~~~~~~~~~~~~~~~
historic.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &l, &r);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 17 ms 512 KB Output is correct
5 Correct 48 ms 632 KB Output is correct
6 Correct 84 ms 760 KB Output is correct
7 Correct 95 ms 760 KB Output is correct
8 Correct 66 ms 740 KB Output is correct
9 Correct 69 ms 760 KB Output is correct
10 Correct 124 ms 768 KB Output is correct
11 Correct 128 ms 768 KB Output is correct
12 Correct 117 ms 768 KB Output is correct
13 Correct 120 ms 784 KB Output is correct
14 Correct 123 ms 768 KB Output is correct
15 Correct 116 ms 768 KB Output is correct
16 Correct 71 ms 888 KB Output is correct
17 Correct 35 ms 768 KB Output is correct
18 Correct 114 ms 888 KB Output is correct
19 Correct 119 ms 784 KB Output is correct
20 Correct 117 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 12 ms 768 KB Output is correct
9 Correct 24 ms 1404 KB Output is correct
10 Correct 16 ms 1788 KB Output is correct
11 Correct 100 ms 6496 KB Output is correct
12 Correct 70 ms 2980 KB Output is correct
13 Correct 99 ms 4076 KB Output is correct
14 Correct 146 ms 7144 KB Output is correct
15 Correct 172 ms 10216 KB Output is correct
16 Correct 166 ms 10488 KB Output is correct
17 Correct 59 ms 3692 KB Output is correct
18 Correct 95 ms 6504 KB Output is correct
19 Correct 144 ms 11724 KB Output is correct
20 Correct 91 ms 9064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 217 ms 1080 KB Output is correct
2 Correct 865 ms 1648 KB Output is correct
3 Correct 2071 ms 2416 KB Output is correct
4 Correct 3766 ms 3492 KB Output is correct
5 Execution timed out 4083 ms 3948 KB Time limit exceeded
6 Halted 0 ms 0 KB -