BriMon @ 2018-02-18 15:48:53
有四个点对了, 剩下全Re; 求改错!!! 谢!
#include <cstdio>
#include <iostream>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
int n, m, t;
int lastans;
int a[50010], c[50010];
vector <int> v[50010];
int pos[50010];
int f[5000][5000];
int cnt[50010];
int query(int cur, int l, int r)
{
return upper_bound(v[cur].begin(), v[cur].end(), r) - lower_bound(v[cur].begin(), v[cur].end(), l);
}
int main()
{
cin>>n>>m;
int k = 0;
for(register int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
c[i] = a[i];
}
sort(c+1,c+1+n);
for(register int i=1;i<=n;i++)
{
t = a[i];
a[i] = lower_bound(c+1, c+1+n, a[i]) - c;
v[a[i]].push_back(i);
pos[a[i]] = t;
}
int maxn;
int si = (int)sqrt(n);
if(si == 0) si = 1;
for(register int i = 0; i <= (n - 1) / si; i++)
{
maxn = 0;
for(register int j = i * si + 1;j <= n; j++)
{
cnt[a[j]]++;
if(cnt[a[j]] > maxn || (cnt[a[j]] == maxn && a[j] < t))
{
maxn = cnt[a[j]];
t = a[j];
}
if(j % si == 0) f[i][(j-1)/si] = t;
}
memset(cnt, 0, sizeof cnt);
}
while(m--)
{
int ans;
int x, y;
scanf("%d%d",&x,&y);
maxn = 0;
x = (x + lastans - 1) % n + 1;
y = (y + lastans - 1) % n + 1;
if(x > y) swap(x, y);
if((y-1)/si - (x-1)/si < 2)
{
for(register int i=x;i<=y;i++)
{
int t = query(a[i], x, y);
//cout<<t<<" ";
if(t > maxn || (t == maxn && a[i] < ans))
{
// cout<<i<<" ";
maxn = t;
ans = a[i];
}
}
}
else
{
for(register int i = x; i <= ((x - 1) / si + 1) * si; i++)
{
int t = query(a[i], x, y);
if(t > maxn || (t == maxn && a[i] < ans))
{
maxn = t;
ans = a[i];
}
}
t = query(f[(x-1)/si+1][(y-1)/si-1], x, y);
if(t > maxn || (t == maxn && f[(x-1)/si+1][(y-1)/si-1] < ans))
{
maxn = t;
ans = f[(x-1)/si+1][(y-1)/si-1];
}
for(register int i=((x-1)/si)*si+1;i<=y;i++)
{
int t = query(a[i], x, y);
if(t > maxn || (t == maxn && a[i] < ans))
{
maxn = t;
ans = a[i];
}
}
}
printf("%d\n",pos[ans]);
lastans = pos[ans];
}
return 0;
}
by BriMon @ 2018-02-18 15:50:27
别沉啊
by BriMon @ 2018-02-18 15:54:37
。。
by BriMon @ 2018-02-18 15:58:47
大佬呢》》》
by BriMon @ 2018-02-18 21:07:35
召唤大佬
by nekko @ 2018-02-18 21:34:32
RE=TLE or MLE or 数组开小了
by zhoutb2333 @ 2018-02-18 22:10:52
复杂度不对,过不去
by BriMon @ 2018-02-18 22:11:52
我选择放弃orz
by BriMon @ 2018-02-18 22:12:57
还是做入门大水题去吧
by decoqwq @ 2018-02-19 13:52:42
@BriMon 我才对两个点就放弃了QWQ