题目链接

定义一种操作f(u, v) = u^u+1^.......^v。 (u<=v), 给n个数, q个询问, 每个询问给出一个区间[l, r], 求这个区间里的f(a[i], a[j]) (l<=i<=j<=r)的最大值。

一开始竟然用n^2m的方法, 真是有点脑残..

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
int a[], ans[], b[], dp[];
struct node
{
int l, r;
}q[];
int main()
{
int n, m;
cin>>n>>m;
for(int i = ; i<=n; i++) {
scanf("%d", &a[i]);
}
for(int i = ; i<=; i++) {
b[i] = i^b[i-];
}
for(int i = ; i<m; i++) {
scanf("%d%d", &q[i].l, &q[i].r);
}
for(int i = ; i<=n; i++) {
dp[i] = a[i];
for(int j = i+; j<=n; j++) {
int minn = min(a[i], a[j]);
int maxx = max(a[i], a[j]);
int num = b[maxx]^b[minn-];
dp[j] = max(dp[j-], num);
}
for(int j = ; j<m; j++) {
if(i>=q[j].l&&i<=q[j].r) {
ans[j] = max(ans[j], dp[q[j].r]);
}
}
}
for(int i = ; i<m; i++)
printf("%d\n", ans[i]);
return ;
}
04-15 20:37