求调
  • 板块学术版
  • 楼主loser_wanghan
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/1/19 20:10
  • 上次更新2025/1/20 01:15:14
查看原帖
求调
1158927
loser_wanghan楼主2025/1/19 20:10

站外题

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define int long long
using std::cin, std::cout;

#define lF(i, a, b) for (int i = a, END##i = b; i <= END##i; i++)
#define rF(i, a, b) for (int i = a, END##i = b; i >= END##i; i--)

void Init();
void Solve();

signed main() {
	cin.sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int T = 1;
//	cin >> T;
	while (T--) {
		Init();
		Solve();
	}
	return 0;
}

using LL = long long;
using ULL = unsigned long long;

const int Mod = 10007;
const int Inf = 0x3f3f3f3f;
const LL InfLL = 0x3f3f3f3f3f3f3f3f;

const int N = 1e5 + 10;
int n, m, a[N];

struct Node {
	int sum1, sum2, sum3;
	int tag1, tag2, tag3;
}tr[N << 2];
#define lsp (p << 1)
#define rsp (p << 1 | 1)
void push_up(int p) {
	tr[p].sum1 = (tr[lsp].sum1 + tr[rsp].sum1) % Mod;
	tr[p].sum2 = (tr[lsp].sum2 + tr[rsp].sum2) % Mod;
	tr[p].sum3 = (tr[lsp].sum3 + tr[rsp].sum3) % Mod;
}
void build(int p, int L, int R) {
	tr[p].tag1 = 0;
	tr[p].tag2 = 1;
	tr[p].tag3 = 0;
	if (L == R) {
		tr[p].sum1 = a[L];
		tr[p].sum2 = a[L] * a[L] % Mod;
		tr[p].sum3 = a[L] * a[L] % Mod * a[L] % Mod;
		return;
	}
	int Mid = L + R >> 1;
	build(lsp, L, Mid);
	build(rsp, Mid + 1, R);
	push_up(p);
}
void add_tag(int p, int L, int R, int t, int op) {
	int n = R - L + 1;
	if (op == 1) {
		tr[p].sum3 += n * t * t * t + 3 * t * (tr[p].sum2 + t * tr[p].sum1);
		tr[p].sum3 %= Mod;
		tr[p].sum2 += n * t * t + 2 * t * tr[p].sum1;
		tr[p].sum2 %= Mod;
		tr[p].sum1 += t;
		tr[p].sum1 %= Mod;
		tr[p].tag1 += t;
		tr[p].tag1 %= Mod;
	}
	if (op == 2) {
		tr[p].sum3 *= t * t * t;
		tr[p].sum3 %= Mod;
		tr[p].sum2 *= t * t;
		tr[p].sum2 %= Mod;
		tr[p].sum1 *= t;
		tr[p].sum1 %= Mod;
		tr[p].tag1 *= t;
		tr[p].tag1 %= Mod;
		tr[p].tag2 *= t;
		tr[p].tag2 %= Mod;
	}
	if (op == 3) {
		tr[p].sum1 = n * t % Mod;
		tr[p].sum2 = n * t % Mod * t % Mod;
		tr[p].sum3 = n * t % Mod * t % Mod * t % Mod;
		tr[p].tag1 = 0;
		tr[p].tag2 = 1;
		tr[p].tag3 = t;
	}
}
void push_down(int p, int L, int R, int op) {
	int Mid = L + R >> 1;
	if (op == 1) {
		add_tag(p, 1, n, tr[p].tag1, 1);
		tr[p].tag1 = 0;
	} else if (op == 2) {
		add_tag(p, 1, n, tr[p].tag2, 2);
		tr[p].tag2 = 1;
	} else if (op == 3) {
		add_tag(p, 1, n, tr[p].tag3, 3);
		tr[p].tag3 = 0;
	}
}
void update(int p, int L, int R, int l, int r, int t, int op) {
	if (l <= L && R <= r) {
		add_tag(p, L, R, t, op);
		return;
	}
	int Mid = L + R >> 1;
	push_down(p, L, R, op);
	if (l <= Mid) update(lsp, L, Mid, l, r, t, op);
	if (r > Mid) update(rsp, Mid + 1, R, l, r, t, op);
	push_up(p);
}
int query(int p, int L, int R, int l, int r, int P) {
	if (l <= L && R <= r) {
		if (P == 1) return tr[p].sum1;
		if (P == 2) return tr[p].sum2;
		if (P == 3) return tr[p].sum3;
	}
	int Mid = L + R >> 1, ans = 0;
	push_down(p, L, R, P);
	if (l <= Mid) ans += query(lsp, L, Mid, l, r, P);
	if (r > Mid) ans += query(rsp, Mid + 1, R, l, r, P);
	ans %= Mod;
	return ans;
}

void Init() {
}

void Solve() {
	while (cin >> n >> m, n) {
		build(1, 1, n);
		while (m--) {
			int op; cin >> op;
			if (op == 1) {
				int x, y, c; cin >> x >> y >> c;
				update(1, 1, n, x, y, c, 1);
			} else if (op == 2) {
				int x, y, c; cin >> x >> y >> c;
				update(1, 1, n, x, y, c, 2);
			} else if (op == 3) {
				int x, y, c; cin >> x >> y >> c;
				update(1, 1, n, x, y, c, 3);
			} else if (op == 4) {
				int x, y, p; cin >> x >> y >> p;
				cout << query(1, 1, n, x, y, p) << "\n";
			}
		}
	}
}

样例没过

2025/1/19 20:10
加载中...