Submission #779966

# Submission time Handle Problem Language Result Execution time Memory
779966 2023-07-12T04:38:15 Z 이동현(#10007) 역사적 조사 (JOI14_historical) C++17
0 / 100
4 ms 1240 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;

const int NS = (int)1e5 + 4;
int n, q;
int B = 1000;
int a[NS];
int srt[NS];
int cnt[NS], ans[NS];
struct ran{
    int l, r, id;
    bool operator<(const ran&R)const{
        return l / B < R.l / B || (l / B == R.l / B && ((r < R.r) ^ (l / B % 2)));
    }
}que[NS];

struct Data{
    long long val;
    int id;
    Data(){}
    Data(long long val, int id):val(val), id(id){}
    bool operator<(const Data&r)const{
        return val < r.val;
    }
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> q;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        srt[i] = a[i];
    }
    sort(srt, srt + n);
    for(int i = 0; i < n; ++i){
        a[i] = lower_bound(srt, srt + n, a[i]) - srt;
    }
    for(int i = 0; i < q; ++i){
        cin >> que[i].l >> que[i].r;
        --que[i].l, --que[i].r;
        que[i].id = i;
    }
    sort(que, que + q);

    priority_queue<Data> pq;
    int r = -1, l = 0;
    for(int i = 0; i < q; ++i){
        while(r < que[i].r){
            ++r;
            ++cnt[a[r]];
            pq.push(Data((long long)srt[a[r]] * cnt[a[r]], a[r]));
        }
        while(l > que[i].l){
            --l;
            ++cnt[a[l]];
            pq.push(Data((long long)srt[a[l]] * cnt[a[l]], a[l]));
        }
        while(r > que[i].r){
            --cnt[a[r]];
            pq.push(Data((long long)srt[a[r]] * cnt[a[r]], a[r]));
            --r;
        }
        while(l < que[i].l){
            --cnt[a[l]];
            pq.push(Data((long long)srt[a[l]] * cnt[a[l]], a[l]));
            ++l;
        }

        while((long long)srt[pq.top().id] * cnt[pq.top().id] != pq.top().val){
            pq.pop();
        }

        ans[que[i].id] = pq.top().val;
    }

    for(int i = 0; i < q; ++i){
        cout << ans[i] << '\n';
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 476 KB Output is correct
7 Correct 4 ms 1060 KB Output is correct
8 Incorrect 4 ms 1240 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -