分块入门题 0pts TLE WA 求调。
  • 板块P4135 作诗
  • 楼主An_Aholic
  • 当前回复5
  • 已保存回复5
  • 发布时间2023/8/10 01:18
  • 上次更新2024/11/1 22:15:56
查看原帖
分块入门题 0pts TLE WA 求调。
792031
An_Aholic楼主2023/8/10 01:18

如题,第一个点是 WA,其他的都是 TLE。感觉应该是啥很离谱的问题,很长时间没做题回来被爆杀。

#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
int a[100005], TLEWA[1000][1000], qwq[100005];
unordered_map<int, int> seele;
unordered_map<int, vector<int> > sing;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, c, m, x=0, bl=200, qwasd=0, l, r, as, df, seeleAKIOI, seeleAKNOI, sc84bbs;
	cin >> n >> c >> m;
	for (int i=1; i<=n; i++) qwq[i] = (i-1)/bl+1;
	for (int i=1; i<=n; i++) cin >> a[i];
	for (int i=1; i<=(n+bl-1)/bl; i++) {
		seele.clear();
		qwasd = seeleAKIOI = 0;
		for (int j=i; j<=(n+bl-1)/bl; j++) {
			for (int k=(j-1)*bl+1; k<=j*bl && k<=n; k++) {
				seele[a[k]]++;
				qwasd += (seele[a[k]] != 1) * (!(seele[a[k]] % 2) * 2 - 1);
			}
			TLEWA[i][j] = qwasd;
		}
	}
	for (int i=1; i<=n; i++) sing[a[i]].push_back(i);
	for (int i=1; i<=m; i++) {
		cin >> l >> r;
		l = (l + x) % n + 1;
		r = (r + x) % n + 1;
		if (l > r) swap(l, r);
		sc84bbs = TLEWA[qwq[l]+1][qwq[r]-1];
		qwasd = 0;
		for (int j=l; qwq[j] == (l-1)/bl+1 && j<=r; j++) {
			df = upper_bound(sing[a[j]].begin(), sing[a[j]].end(), r) - lower_bound(sing[a[j]].begin(), sing[a[j]].end(), l);
			as = max(0l, upper_bound(sing[a[j]].begin(), sing[a[j]].end(), (qwq[r]-1)*bl) - lower_bound(sing[a[j]].begin(), sing[a[j]].end(), qwq[l]*bl+1));
			qwasd += (*lower_bound(sing[a[j]].begin(), sing[a[j]].end(), l) == j) * (as ? (!(df & 1) * 2 - 1) * ((as ^ df) & 1) : !(df & 1));
		}
		sc84bbs += qwasd;
		qwasd = 0;
		for (int j=r; qwq[l] != qwq[r] && qwq[j] == (r-1)/bl+1 && j>=l; j--) {
			df = upper_bound(sing[a[j]].begin(), sing[a[j]].end(), r) - lower_bound(sing[a[j]].begin(), sing[a[j]].end(), l);
			as = max(0l, upper_bound(sing[a[j]].begin(), sing[a[j]].end(), (qwq[r]-1)*bl) - lower_bound(sing[a[j]].begin(), sing[a[j]].end(), qwq[l]*bl+1));
			qwasd += (*lower_bound(sing[a[j]].begin(), sing[a[j]].end(), l) == j) * (as ? (!(df & 1) * 2 - 1) * ((as ^ df) & 1) : !(df & 1));
		}
		sc84bbs += qwasd;
		cout << sc84bbs << endl;
		x = sc84bbs;
	}
}
2023/8/10 01:18
加载中...