mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 13:56:26 +00:00
parent
525c3c6a1a
commit
e4ee2b6c8e
106
S2OJ/1447/1447.cpp
Normal file
106
S2OJ/1447/1447.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#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
S2OJ/1447/data/a1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/a9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/a9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/ex_a1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/ex_a1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/ex_a1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/ex_a1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/ex_a2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/ex_a2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/ex_a2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/ex_a2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/ex_a3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/ex_a3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/ex_a3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/ex_a3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/ex_a4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/ex_a4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/ex_a4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/ex_a4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/ex_a5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/ex_a5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1447/data/ex_a5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1447/data/ex_a5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user