40分求调
查看原帖
40分求调
287512
Mandrill楼主2024/10/7 10:54

rt

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int neg[N], n, q, a[N];
int main() {
	// freopen("potion.in", "r", stdin);
	// freopen("potion.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		if (a[i] < 0)
			for (int j = i; j <= n; ++j)
				neg[j]++;
	}
	for (int ques = 1; ques <= q; ++ques) {
		int x, y, z; cin >> x >> y >> z;
		if (x == 1) {
			int i = y, k = z;
			a[i] = k;
			if (k < 0)
				for (int j = i; j <= n; ++j)
					neg[j]++;
		}
		if (x == 2) {
			int l = y, r = z;
			if (r - l + 1 > 61) {
				cout << "Too large" << endl;
				continue;
			}
			if ((neg[r] - neg[l - 1]) % 2 == 0) {
				long long ans = 1;
				for (int i = l; i <= r; ++i) {
					ans *= a[i];
					if (ans > 1073741824) {
						ans = -114514;
						break;
					}
				}
				if (ans <= 0 || ans > 1073741824) cout << "Too large" << endl;
				else cout << ans << endl;
			}
			else {
				long long ans1 = 1, ans2 = 1, ans;
				for (int i = l + 1; i <= r; ++i)
					if ((neg[r] - neg[i - 1]) % 2 == 0) {
						for (int j = i; j <= r; ++j) {
							ans1 *= a[j];
							if (ans1 > 1073741824) {
								ans1 = -114514;
								break;
							}
						}
						break;
					}
				for (int i = r - 1; i >= l; i--)
					if ((neg[i] - neg[l - 1]) % 2 == 0) {
						for (int j = l; j <= i; ++j) {
							ans2 *= a[j];
							if (ans2 > 1073741824) {
								ans2 = -114514;
								break;
							}
						}
						break;
					}
				if (ans1 == -114514 || ans2 == -114514) ans = -114514;
				else ans = max(ans1, ans2);
				if (ans <= 0 || ans > 1073741824) cout << "Too large" << endl;
				else cout << ans << endl;
			}
		}
	}
	return 0;
}

2024/10/7 10:54
加载中...