跳到正文

题解

题解:P11660 我终将成为你的倒影

yzq_yzq约 5 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 5 分钟
题目
P11660

版本

  1. v1当前

场切了,强制在线感觉很唐,还有这题目背景不会被 Ban 吗。

令 bb 的值域为 V=500V=500 ,仔细读题发现贡献其实是二位偏序的形式,然后有 VV 组序列都要查,然后二维偏序的值域为 VV 。

这东西强制在线主席树显然不够开,再加上看过了唐诗 T1 于是考虑分块,散块暴力即可,大块考虑预处理,块内考虑预处理的时候差分,然后前缀和滚回去就可以一次 O(V+B)O(V+B) 就算好块内答案,最后复杂度是 V×(nB×(V+B))V\times(\frac n B \times (V +B)) 的。

空间开销比较大,假如不够开块长取大点就行了。

挂个丑陋的赛时代码:

C++
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; ++i)
#define drep(i, x, y) for (int i = x; i >= y; --i)
#define ll long long
#define pb push_back
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
const int N = 100050, M = 505, V = 10;
#define ull unsigned ll
#define ppc(x) __builtin_popcountll(x)
int n, m, a[N], res[M][205][M], c[M], sq, pos[N], L[N], R[N], s[N];
// (x + a) / b = (y + a) / b
int main() {
	IOS; cin >> n >> m;
	rep(i, 1, n) cin >> a[i]; int lst = 0;
//	if(n <= 100) {
//		while(m--) {
//			int l, r, x, y; cin >> l >> r >> x >> y;
//			l ^= lst, r ^= lst, x ^= lst, y ^= lst, x %= y;
//			int ans = 0;
//			rep(i, l, r - 1) ans += ((a[i] + x) / y == (a[i + 1] + x) / y);
//			cout << ans << '\n'; lst = ans;
//		}
//		return 0;
//	}
	sq = M - 1;
	rep(i, 1, n) pos[i] = (i - 1) / sq + 1;
	rep(i, 1, pos[n]) L[i] = (i - 1) * sq + 1, R[i] = min(n - 1, i * sq);
	rep(i, 1, n) s[i] = s[i - 1] + (a[i] == a[i + 1]);
	rep(b, 1, 500) {
		rep(i, 1, pos[n]) {
			rep(j, 0, b) c[j] = 0;
			int x, y;
			rep(j, L[i], R[i]) {
				if(abs(a[j] - a[j + 1]) >= b) continue;
				x = a[j], y = a[j + 1];
				if(x == y) c[0]++;
				else {
					if(x > y) swap(x, y);
					if(x / b == y / b) {
						x %= b, y %= b;
						c[0]++, c[b - y]--, c[b - x]++;
					} else {
						// x / b < y / b
						c[b - x % b]++;
						c[b - y % b]--;
					}
				}
			}
			res[b][i][0] = c[0];
			rep(j, 1, b) c[j] += c[j - 1], res[b][i][j] = c[j];
		}
	}
	while(m--) {
		int l, r, x, y; cin >> l >> r >> x >> y;
		l ^= lst, r ^= lst, x ^= lst, y ^= lst, x %= y, --r;
//		cout << "true : " << l << " " << r << " " << x << " " << y << " \n";
		assert(l <= r && y < M);
		lst = 0;
		if(pos[l] == pos[r]) {
			rep(i, l, r) lst += ((a[i] + x) / y == (a[i + 1] + x) / y);
		} else {
			rep(i, l, R[pos[l]]) lst += ((a[i] + x) / y == (a[i + 1] + x) / y);
			rep(i, L[pos[r]], r) lst += ((a[i] + x) / y == (a[i + 1] + x) / y);
			rep(i, pos[l] + 1, pos[r] - 1) lst += res[y][i][x];
		}
		cout << lst << '\n';
	}
	return 0;
}
原文