mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
parent
47265ad1cc
commit
dd5a43941a
106
LibreOJ/6285/6285.cpp
Normal file
106
LibreOJ/6285/6285.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 100005;
|
||||
|
||||
int n, t, a[N], st[N], ed[N], pos[N], f[1005][1005], cnt[N];
|
||||
std::vector<int> nums, v[N];
|
||||
|
||||
inline int find(int x) {
|
||||
return std::lower_bound(nums.begin(), nums.end(), x) - nums.begin();
|
||||
}
|
||||
|
||||
void pre(int x) {
|
||||
memset(cnt, 0x00, sizeof(cnt));
|
||||
std::pair<int, int> res;
|
||||
|
||||
for (int i = st[x]; i <= n; i++) {
|
||||
cnt[a[i]]++;
|
||||
|
||||
if (cnt[a[i]] > res.first || (cnt[a[i]] == res.first && nums[a[i]] < nums[res.second])) {
|
||||
res = std::make_pair(cnt[a[i]], a[i]);
|
||||
}
|
||||
|
||||
f[x][pos[i]] = res.second;
|
||||
}
|
||||
}
|
||||
|
||||
inline int get(int x, int l, int r) {
|
||||
return std::upper_bound(v[x].begin(), v[x].end(), r) - std::lower_bound(v[x].begin(), v[x].end(), l);
|
||||
}
|
||||
|
||||
int query(int l, int r) {
|
||||
int p = pos[l],
|
||||
q = pos[r];
|
||||
std::pair<int, int> res;
|
||||
|
||||
if (p == q) {
|
||||
for (int i = l; i <= r; i++) {
|
||||
int _ = get(a[i], l, r);
|
||||
if (_ > res.first || (_ == res.first && nums[a[i]] < nums[res.second])) {
|
||||
res = std::make_pair(_, a[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return nums[res.second];
|
||||
}
|
||||
|
||||
res.second = f[p + 1][q - 1];
|
||||
res.first = get(res.second, l, r);
|
||||
|
||||
for (int i = l; i <= ed[p]; i++) {
|
||||
int _ = get(a[i], l, r);
|
||||
if (_ > res.first || (_ == res.first && nums[a[i]] < nums[res.second])) {
|
||||
res = std::make_pair(_, a[i]);
|
||||
}
|
||||
}
|
||||
for (int i = st[q]; i <= r; i++) {
|
||||
int _ = get(a[i], l, r);
|
||||
if (_ > res.first || (_ == res.first && nums[a[i]] < nums[res.second])) {
|
||||
res = std::make_pair(_, a[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return nums[res.second];
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
|
||||
cin >> n;
|
||||
|
||||
t = std::sqrt(n);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
pos[i] = (i - 1) / t + 1;
|
||||
nums.push_back(a[i]);
|
||||
}
|
||||
|
||||
std::sort(nums.begin(), nums.end());
|
||||
nums.erase(std::unique(nums.begin(), nums.end()), nums.end());
|
||||
nums.insert(nums.begin(), 0);
|
||||
|
||||
for (int i = 1; i <= n; i++) v[a[i] = find(a[i])].push_back(i);
|
||||
|
||||
for (int i = 1; i <= pos[n]; i++) {
|
||||
st[i] = (i - 1) * t + 1;
|
||||
ed[i] = std::min(n, i * t);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= pos[n]; i++) pre(i);
|
||||
|
||||
for (int i = 1, l, r; i <= n; i++) {
|
||||
cin >> l >> r;
|
||||
cout << query(l, r) << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
LibreOJ/6285/data/a1.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a1.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a10.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a10.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a2.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a2.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a3.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a3.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a4.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a4.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a5.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a5.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a6.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a6.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a7.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a7.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a8.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a8.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a9.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/a9.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/a9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/ex_1.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/ex_1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/ex_1.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/ex_1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/ex_2.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/ex_2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/ex_2.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/ex_2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/ex_3.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/ex_3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/ex_3.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/ex_3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/ex_4.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/ex_4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/ex_4.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/ex_4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/ex_5.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/ex_5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6285/data/ex_5.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6285/data/ex_5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user