# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
779983 |
2023-07-12T04:48:12 Z |
이동현(#10007) |
역사적 조사 (JOI14_historical) |
C++17 |
|
4000 ms |
132400 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 = 3000;
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
724 KB |
Output is correct |
18 |
Correct |
11 ms |
1492 KB |
Output is correct |
19 |
Correct |
58 ms |
4616 KB |
Output is correct |
20 |
Correct |
281 ms |
8684 KB |
Output is correct |
21 |
Correct |
611 ms |
33520 KB |
Output is correct |
22 |
Correct |
661 ms |
33432 KB |
Output is correct |
23 |
Correct |
535 ms |
33372 KB |
Output is correct |
24 |
Correct |
595 ms |
33372 KB |
Output is correct |
25 |
Correct |
562 ms |
66180 KB |
Output is correct |
26 |
Correct |
621 ms |
66296 KB |
Output is correct |
27 |
Correct |
677 ms |
66220 KB |
Output is correct |
28 |
Correct |
588 ms |
66368 KB |
Output is correct |
29 |
Correct |
670 ms |
66284 KB |
Output is correct |
30 |
Correct |
686 ms |
66244 KB |
Output is correct |
31 |
Correct |
578 ms |
33360 KB |
Output is correct |
32 |
Correct |
414 ms |
9060 KB |
Output is correct |
33 |
Correct |
647 ms |
66196 KB |
Output is correct |
34 |
Correct |
619 ms |
66196 KB |
Output is correct |
35 |
Correct |
425 ms |
66296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 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 |
1004 KB |
Output is correct |
8 |
Correct |
4 ms |
1112 KB |
Output is correct |
9 |
Correct |
10 ms |
2756 KB |
Output is correct |
10 |
Correct |
22 ms |
1108 KB |
Output is correct |
11 |
Correct |
94 ms |
4984 KB |
Output is correct |
12 |
Correct |
45 ms |
5672 KB |
Output is correct |
13 |
Correct |
70 ms |
10144 KB |
Output is correct |
14 |
Correct |
78 ms |
6820 KB |
Output is correct |
15 |
Correct |
91 ms |
7636 KB |
Output is correct |
16 |
Correct |
50 ms |
6976 KB |
Output is correct |
17 |
Correct |
36 ms |
6216 KB |
Output is correct |
18 |
Correct |
64 ms |
11116 KB |
Output is correct |
19 |
Correct |
59 ms |
11200 KB |
Output is correct |
20 |
Correct |
27 ms |
6092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
724 KB |
Output is correct |
18 |
Correct |
11 ms |
1492 KB |
Output is correct |
19 |
Correct |
58 ms |
4616 KB |
Output is correct |
20 |
Correct |
281 ms |
8684 KB |
Output is correct |
21 |
Correct |
611 ms |
33520 KB |
Output is correct |
22 |
Correct |
661 ms |
33432 KB |
Output is correct |
23 |
Correct |
535 ms |
33372 KB |
Output is correct |
24 |
Correct |
595 ms |
33372 KB |
Output is correct |
25 |
Correct |
562 ms |
66180 KB |
Output is correct |
26 |
Correct |
621 ms |
66296 KB |
Output is correct |
27 |
Correct |
677 ms |
66220 KB |
Output is correct |
28 |
Correct |
588 ms |
66368 KB |
Output is correct |
29 |
Correct |
670 ms |
66284 KB |
Output is correct |
30 |
Correct |
686 ms |
66244 KB |
Output is correct |
31 |
Correct |
578 ms |
33360 KB |
Output is correct |
32 |
Correct |
414 ms |
9060 KB |
Output is correct |
33 |
Correct |
647 ms |
66196 KB |
Output is correct |
34 |
Correct |
619 ms |
66196 KB |
Output is correct |
35 |
Correct |
425 ms |
66296 KB |
Output is correct |
36 |
Correct |
0 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 |
1 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 |
1004 KB |
Output is correct |
43 |
Correct |
4 ms |
1112 KB |
Output is correct |
44 |
Correct |
10 ms |
2756 KB |
Output is correct |
45 |
Correct |
22 ms |
1108 KB |
Output is correct |
46 |
Correct |
94 ms |
4984 KB |
Output is correct |
47 |
Correct |
45 ms |
5672 KB |
Output is correct |
48 |
Correct |
70 ms |
10144 KB |
Output is correct |
49 |
Correct |
78 ms |
6820 KB |
Output is correct |
50 |
Correct |
91 ms |
7636 KB |
Output is correct |
51 |
Correct |
50 ms |
6976 KB |
Output is correct |
52 |
Correct |
36 ms |
6216 KB |
Output is correct |
53 |
Correct |
64 ms |
11116 KB |
Output is correct |
54 |
Correct |
59 ms |
11200 KB |
Output is correct |
55 |
Correct |
27 ms |
6092 KB |
Output is correct |
56 |
Correct |
1846 ms |
66408 KB |
Output is correct |
57 |
Execution timed out |
4072 ms |
132400 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |