답안 #634923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634923 2022-08-25T09:00:58 Z minhcool 역사적 조사 (JOI14_historical) C++17
100 / 100
2138 ms 13748 KB
//#include "monster.h"
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 1e5 + 5;
 
const int oo = 1e18 + 7, mod = 1e9 + 7;
 
int n, q;

int a[N];

int blk_sz = 305;

unordered_map<int, int> cnt;
int cur_ans;
int answer[N];

vector<iii> queries[N];

bool cmp(iii a, iii b){
    return a.fi.se < b.fi.se;
}

int no_blk[N], st_blk[N];

void process(){
    cin >> n >> q;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        no_blk[i] = no_blk[i - 1];
        if((i % blk_sz) == 1){
            no_blk[i]++;
            st_blk[no_blk[i]] = i;
        }
    }
    for(int i = 1; i <= q; i++){
        int l, r;
        cin >> l >> r;
        if(no_blk[l] == no_blk[r]){
            cur_ans = 0;
            for(int j = l; j <= r; j++){
                cnt[a[j]]++;
                cur_ans = max(cur_ans, cnt[a[j]] * a[j]);
            }
            answer[i] = cur_ans;
            cnt.clear();
        }
        else queries[no_blk[l] + 1].pb({{l, r}, i});
    }
    for(int i = 1; i <= no_blk[n]; i++) sort(queries[i].begin(), queries[i].end(), cmp);
    for(int i = 1; i <= no_blk[n]; i++){
        int cur_itr = st_blk[i] - 1;
        cur_ans = 0;
        cnt.clear();
        for(auto it : queries[i]){
            while(cur_itr < it.fi.se){
                cur_itr++;
                cnt[a[cur_itr]]++;
                cur_ans = max(cur_ans, cnt[a[cur_itr]] * a[cur_itr]);
            }
            int rem = cur_ans;
            for(int j = st_blk[i] - 1; j >= it.fi.fi; j--){
                cnt[a[j]]++;
                cur_ans = max(cur_ans, cnt[a[j]] * a[j]);
            }
            answer[it.se] = cur_ans;
            cur_ans = rem;
            for(int j = st_blk[i] - 1; j >= it.fi.fi; j--) cnt[a[j]]--;
        }
    }
    for(int i = 1; i <= q; i++) cout << answer[i] << "\n";
}

signed main(){
	ios_base::sync_with_stdio(0);
	process();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2680 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2656 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2604 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2684 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2680 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2656 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2604 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2684 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 3 ms 2692 KB Output is correct
17 Correct 4 ms 2700 KB Output is correct
18 Correct 7 ms 2772 KB Output is correct
19 Correct 13 ms 2784 KB Output is correct
20 Correct 21 ms 2952 KB Output is correct
21 Correct 29 ms 3076 KB Output is correct
22 Correct 28 ms 3068 KB Output is correct
23 Correct 28 ms 3044 KB Output is correct
24 Correct 29 ms 3060 KB Output is correct
25 Correct 34 ms 3108 KB Output is correct
26 Correct 35 ms 3084 KB Output is correct
27 Correct 36 ms 3124 KB Output is correct
28 Correct 38 ms 3120 KB Output is correct
29 Correct 37 ms 3148 KB Output is correct
30 Correct 40 ms 3036 KB Output is correct
31 Correct 38 ms 3088 KB Output is correct
32 Correct 32 ms 3040 KB Output is correct
33 Correct 40 ms 3028 KB Output is correct
34 Correct 41 ms 3148 KB Output is correct
35 Correct 40 ms 3140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2684 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 3 ms 2824 KB Output is correct
8 Correct 4 ms 2980 KB Output is correct
9 Correct 9 ms 3320 KB Output is correct
10 Correct 11 ms 3812 KB Output is correct
11 Correct 220 ms 8016 KB Output is correct
12 Correct 25 ms 4952 KB Output is correct
13 Correct 144 ms 6360 KB Output is correct
14 Correct 274 ms 7928 KB Output is correct
15 Correct 42 ms 8064 KB Output is correct
16 Correct 1026 ms 10804 KB Output is correct
17 Correct 222 ms 6408 KB Output is correct
18 Correct 511 ms 9664 KB Output is correct
19 Correct 671 ms 11268 KB Output is correct
20 Correct 318 ms 9564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2680 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2656 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2604 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2684 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 3 ms 2692 KB Output is correct
17 Correct 4 ms 2700 KB Output is correct
18 Correct 7 ms 2772 KB Output is correct
19 Correct 13 ms 2784 KB Output is correct
20 Correct 21 ms 2952 KB Output is correct
21 Correct 29 ms 3076 KB Output is correct
22 Correct 28 ms 3068 KB Output is correct
23 Correct 28 ms 3044 KB Output is correct
24 Correct 29 ms 3060 KB Output is correct
25 Correct 34 ms 3108 KB Output is correct
26 Correct 35 ms 3084 KB Output is correct
27 Correct 36 ms 3124 KB Output is correct
28 Correct 38 ms 3120 KB Output is correct
29 Correct 37 ms 3148 KB Output is correct
30 Correct 40 ms 3036 KB Output is correct
31 Correct 38 ms 3088 KB Output is correct
32 Correct 32 ms 3040 KB Output is correct
33 Correct 40 ms 3028 KB Output is correct
34 Correct 41 ms 3148 KB Output is correct
35 Correct 40 ms 3140 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 1 ms 2684 KB Output is correct
38 Correct 2 ms 2688 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 3 ms 2644 KB Output is correct
41 Correct 2 ms 2772 KB Output is correct
42 Correct 3 ms 2824 KB Output is correct
43 Correct 4 ms 2980 KB Output is correct
44 Correct 9 ms 3320 KB Output is correct
45 Correct 11 ms 3812 KB Output is correct
46 Correct 220 ms 8016 KB Output is correct
47 Correct 25 ms 4952 KB Output is correct
48 Correct 144 ms 6360 KB Output is correct
49 Correct 274 ms 7928 KB Output is correct
50 Correct 42 ms 8064 KB Output is correct
51 Correct 1026 ms 10804 KB Output is correct
52 Correct 222 ms 6408 KB Output is correct
53 Correct 511 ms 9664 KB Output is correct
54 Correct 671 ms 11268 KB Output is correct
55 Correct 318 ms 9564 KB Output is correct
56 Correct 71 ms 3420 KB Output is correct
57 Correct 151 ms 4332 KB Output is correct
58 Correct 307 ms 5372 KB Output is correct
59 Correct 464 ms 6488 KB Output is correct
60 Correct 646 ms 7420 KB Output is correct
61 Correct 774 ms 8192 KB Output is correct
62 Correct 705 ms 8984 KB Output is correct
63 Correct 892 ms 10172 KB Output is correct
64 Correct 1145 ms 11012 KB Output is correct
65 Correct 785 ms 11316 KB Output is correct
66 Correct 1058 ms 11512 KB Output is correct
67 Correct 1113 ms 11636 KB Output is correct
68 Correct 1468 ms 11792 KB Output is correct
69 Correct 2040 ms 12880 KB Output is correct
70 Correct 2092 ms 13748 KB Output is correct
71 Correct 1980 ms 13348 KB Output is correct
72 Correct 2138 ms 12936 KB Output is correct
73 Correct 2035 ms 12852 KB Output is correct
74 Correct 1980 ms 12720 KB Output is correct
75 Correct 1944 ms 12576 KB Output is correct
76 Correct 1826 ms 12600 KB Output is correct
77 Correct 1889 ms 12536 KB Output is correct
78 Correct 1833 ms 12460 KB Output is correct
79 Correct 1852 ms 12396 KB Output is correct
80 Correct 927 ms 12216 KB Output is correct