题意:给你一个函数,用这个函数得到m次区间取max的操作(减少输入),最后问每个点的值
点数n<=100000 , m<=5 * 1000000
解法一:线段树打标记最后统一下放,复杂度O(mlogn + n),由于数据具有随机性,如果当前节点的标记大于现在要放的标记就不操作,O(实际可过)。
解法二:st表打标记最后统一下放,复杂度O(m + nlogn),注意到操作多节点少,可以将线段树的O(N)空间换成st表的O(NlogN)以实现O(1)打标记。
解法二代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cctype>
#define LL long long
#define maxn 100005
using namespace std;
int lg[maxn];
unsigned int x,y,z,w;
inline unsigned int RNG68()
{
x = x ^ (x << 11);
x = x ^ (x >> 4);
x = x ^ (x << 5);
x = x ^ (x >> 14);
w = x ^ (y ^ z);
x = y;
y = z;
z = w;
return z;
}
int f[18][maxn];
int main()
{
int T,n,m,l,r,v,a,b;
for(int sum = 1 , i = 0;sum < maxn; sum <<= 1 , i++) lg[sum] = i;
for(int i = 1; i < maxn; i++) lg[i] = max(lg[i] , lg[i-1]);
for(scanf("%d",&T);T--;)
{
memset(f,0,sizeof f);
scanf("%d%d%d%d%d",&n,&m,&x,&y,&z);
for(int i=1;i<=m;i++)
{
a = RNG68() % n + 1 , b = RNG68() % n + 1;
l = min(a , b) , r= max(a ,b);
v = RNG68() & ((1 << 30) - 1);
int tmp = lg[r - l + 1];
f[tmp][l] = max(f[tmp][l] , v) , f[tmp][r-(1<<tmp)+1] = max(f[tmp][r-(1<<tmp)+1] , v);
}
for(int i=17;i>=1;i--)
for(int j=1;j<=n;j++)
f[i-1][j] = max(f[i-1][j] , f[i][j]),
f[i-1][j+(1<<i-1)] = max(f[i-1][j+(1<<i-1)] , f[i][j]);
LL ans = 0;
for(int i=1;i<=n;i++) ans ^= 1ll * i * f[0][i];
printf("%lld\n",ans);
}
}