WA 76 pt 性感代码在线求调教
  • 板块P1956 Sum
  • 楼主冷却心月明かり
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/11/1 16:08
  • 上次更新2024/11/1 19:39:20
查看原帖
WA 76 pt 性感代码在线求调教
431658
冷却心月明かり楼主2024/11/1 16:08

码风良好(大概)。 Record.

WA 在 Subtask 2\text{Subtask 2} 较大的数据。

#include <bits/stdc++.h>
#define LL long long
#define int long long
using namespace std;
const int N = 1e5 + 10;
int n; LL A[N], K, P;
const LL M = 1e18;
LL tree[N * 70]; int tot, rt, ls[N * 70], rs[N * 70];
void pushup(int p) { tree[p] = max(tree[ls[p]], tree[rs[p]]); }
void update(int &p, LL l, LL r, LL x) {
	if (x > r || x < l) return ;
	if (!p) p = ++ tot;
	if (l == r) { tree[p] = x; return ; }
	LL mid = (l + r) >> 1;
	update(ls[p], l, mid, x); update(rs[p], mid + 1, r, x);
	pushup(p); return ;
}
LL query(int p, LL l, LL r, LL x, LL y) {
	if (x > r || y < l || !p) return -1e18;
	if (x <= l && y >= r) return (tree[p] == -1 ? -1e18 : tree[p]);
	LL mid = (l + r) >> 1;
	return max(query(ls[p], l, mid, x, y), query(rs[p], mid + 1, r, x, y));
}

signed main() {
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> K >> P;
	for (int i = 1; i <= n; i ++) {
		cin >> A[i]; A[i] = (A[i] + A[i - 1]) % P;
	}
	memset(tree, -1, sizeof tree);
	update(rt, 0, P - 1, 0); LL Ans = 1e18;
	for (int i = 1; i <= n; i ++) {
		LL p = (A[i] - K + P) % P, ret = 1e18;
		if (p < A[i]) {
			ret = query(rt, 0, P - 1, 0, p);
			if (ret != -1e18) ret = A[i] - ret;
			else {
				LL t = query(rt, 0, P - 1, A[i] + 1, P - 1);
				if (t != -1e18)
					ret = P - t + A[i]; 
			}
		} else {
			LL t = query(rt, 0, P - 1, A[i] + 1, p);
			if (t != -1e18) ret = P - t + A[i];
		}
		Ans = min(Ans, ret);
		update(rt, 0, P - 1, A[i]);
	}
	cout << Ans;
	return 0;
}
2024/11/1 16:08
加载中...