답안 #779980

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779980 2023-07-12T04:46:06 Z 이동현(#10007) 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 265540 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];
long long 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 452 KB Output is correct
17 Correct 3 ms 728 KB Output is correct
18 Correct 11 ms 1536 KB Output is correct
19 Correct 47 ms 4640 KB Output is correct
20 Correct 131 ms 8796 KB Output is correct
21 Correct 246 ms 17208 KB Output is correct
22 Correct 209 ms 17112 KB Output is correct
23 Correct 210 ms 8844 KB Output is correct
24 Correct 240 ms 17084 KB Output is correct
25 Correct 210 ms 17080 KB Output is correct
26 Correct 181 ms 17084 KB Output is correct
27 Correct 200 ms 17160 KB Output is correct
28 Correct 165 ms 17192 KB Output is correct
29 Correct 196 ms 17152 KB Output is correct
30 Correct 195 ms 17088 KB Output is correct
31 Correct 225 ms 17148 KB Output is correct
32 Correct 190 ms 8896 KB Output is correct
33 Correct 198 ms 17116 KB Output is correct
34 Correct 184 ms 17192 KB Output is correct
35 Correct 145 ms 17140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 3 ms 984 KB Output is correct
8 Correct 4 ms 1112 KB Output is correct
9 Correct 10 ms 3132 KB Output is correct
10 Correct 19 ms 1236 KB Output is correct
11 Correct 91 ms 6416 KB Output is correct
12 Correct 42 ms 4424 KB Output is correct
13 Correct 70 ms 11256 KB Output is correct
14 Correct 81 ms 8356 KB Output is correct
15 Correct 95 ms 9744 KB Output is correct
16 Correct 53 ms 8536 KB Output is correct
17 Correct 35 ms 6724 KB Output is correct
18 Correct 61 ms 12772 KB Output is correct
19 Correct 76 ms 13128 KB Output is correct
20 Correct 29 ms 7120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 452 KB Output is correct
17 Correct 3 ms 728 KB Output is correct
18 Correct 11 ms 1536 KB Output is correct
19 Correct 47 ms 4640 KB Output is correct
20 Correct 131 ms 8796 KB Output is correct
21 Correct 246 ms 17208 KB Output is correct
22 Correct 209 ms 17112 KB Output is correct
23 Correct 210 ms 8844 KB Output is correct
24 Correct 240 ms 17084 KB Output is correct
25 Correct 210 ms 17080 KB Output is correct
26 Correct 181 ms 17084 KB Output is correct
27 Correct 200 ms 17160 KB Output is correct
28 Correct 165 ms 17192 KB Output is correct
29 Correct 196 ms 17152 KB Output is correct
30 Correct 195 ms 17088 KB Output is correct
31 Correct 225 ms 17148 KB Output is correct
32 Correct 190 ms 8896 KB Output is correct
33 Correct 198 ms 17116 KB Output is correct
34 Correct 184 ms 17192 KB Output is correct
35 Correct 145 ms 17140 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 3 ms 984 KB Output is correct
43 Correct 4 ms 1112 KB Output is correct
44 Correct 10 ms 3132 KB Output is correct
45 Correct 19 ms 1236 KB Output is correct
46 Correct 91 ms 6416 KB Output is correct
47 Correct 42 ms 4424 KB Output is correct
48 Correct 70 ms 11256 KB Output is correct
49 Correct 81 ms 8356 KB Output is correct
50 Correct 95 ms 9744 KB Output is correct
51 Correct 53 ms 8536 KB Output is correct
52 Correct 35 ms 6724 KB Output is correct
53 Correct 61 ms 12772 KB Output is correct
54 Correct 76 ms 13128 KB Output is correct
55 Correct 29 ms 7120 KB Output is correct
56 Correct 474 ms 17372 KB Output is correct
57 Correct 1176 ms 34268 KB Output is correct
58 Correct 1689 ms 67508 KB Output is correct
59 Correct 2499 ms 133828 KB Output is correct
60 Correct 2864 ms 265540 KB Output is correct
61 Execution timed out 4082 ms 69188 KB Time limit exceeded
62 Halted 0 ms 0 KB -