SIXIANG32 @ 2022-01-27 16:22:53
新年好兆头,耶耶耶
WA 了。找了很久都觉得没有问题,希望有巨佬能指出错误/kk
#include <iostream>
#include <algorithm>
#include <cmath>
#define MAXN 40000
#define QWQ cout << "qwq" << endl;
using namespace std;
int n, m, cnt;
int a[MAXN + 10], qaq[MAXN + 10];
int pl[MAXN + 10], pr[MAXN + 10], cl[MAXN + 10], len;
int c[40 + 10][40 + 10][MAXN + 10];
int f[100 + 10][100 + 10][2];
int big, gib;
void Three_Flower() {
for(int p = 1; p <= n; p++) qaq[p] = a[p];
sort(qaq + 1, qaq + n + 1);
cnt = unique(qaq + 1, qaq + n + 1) - qaq - 1;
for(int p = 1; p <= n; p++)
a[p] = lower_bound(qaq + 1, qaq + cnt + 1, a[p]) - qaq;
}
void qwq(int l, int r, int num) {
c[l][r][num]++;
if(c[l][r][num] > big || (c[l][r][num] == big && num < gib)) {
big = c[l][r][num];
gib = num;
}
}
int solve(int l, int r) {
int L = cl[l], R = cl[r];
int x = 0, y = 0;
if(L + 1 <= R - 1) x = L + 1, y = r - 1;
big = f[x][y][0], gib = f[x][y][1];
if(L == R) {
for(int p = l; p <= r; p++) qwq(x, y, a[p]);
for(int p = l; p <= r; p++) c[x][y][a[p]]--;
}
else {
for(int p = l; p <= pr[L]; p++) qwq(x, y, a[p]);
for(int p = pl[R]; p <= r; p++) qwq(x, y, a[p]);
for(int p = l; p <= pr[L]; p++) c[x][y][a[p]]--;
for(int p = pl[R]; p <= r; p++) c[x][y][a[p]]--;
}
return qaq[gib];
}
void block() {
len = n / pow(double(n), 0.333);
for(int p = 1; p <= ceil(n * 1.0 / len); p++) {
pl[p] = (p - 1)* len + 1;
pr[p] = p * len;
}
for(int p = 1; p <= n; p++)
cl[p] = (p - 1) / len + 1;
for(int p = 1; p <= ceil(n * 1.0 / len); p++)
for(int i = p; i <= ceil(n * 1.0 / len); i++) {
for(int j = pl[p]; j <= pr[i]; j++) c[p][i][a[j]]++;
for(int j = 1; j <= cnt; j++)
if(c[p][i][j] > f[p][i][0] || (c[p][i][j] == f[p][i][0] && j < f[p][i][1]))
f[p][i][0] = c[p][i][j], f[p][i][1] = j;
}
}
int main() {
//freopen("test.txt", "r", stdin);
cin >> n >> m;
for(int p = 1; p <= n; p++) cin >> a[p];
Three_Flower();
block();
int last = 0;
while(m--) {
int x, y;
cin >> x >> y;
x = (x + last - 1) % n + 1, y = (y + last - 1) % n + 1;
if(x > y) swap(x, y);
last = solve(x, y);
cout << last << endl;
}
}