QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#564260#3850. DJ DarkoFortitudeWA 441ms39568kbC++234.4kb2024-09-14 21:35:282024-09-14 21:35:30

Judging History

你现在查看的是最新测评结果

  • [2024-09-14 21:35:30]
  • 评测
  • 测评结果:WA
  • 用时:441ms
  • 内存:39568kb
  • [2024-09-14 21:35:28]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define int long long
using namespace std;
using ll = long long;
using pii = pair <int, int>;
const int N = 2e5 + 5;
const ll inf = 1e18;
int n, q;
ll a[N], b[N], t[N * 4], lz1[N * 4], lz2[N * 4];
ll p[N];
void push(int v) {
	assert(!lz2[v] || lz1[v] == -inf);
	if (lz2[v]) {
		lz2[2 * v] += lz2[v];
		lz2[2 * v + 1] += lz2[v];
		lz1[2 * v] = lz1[2 * v + 1] = -inf;
		t[2 * v] += lz2[v];
		t[2 * v + 1] += lz2[v];
		lz2[v] = 0;
	}
	if (lz1[v] != -inf) {
		lz1[2 * v] = lz1[2 * v + 1] = lz1[v];
		lz2[2 * v] = lz2[2 * v + 1] = 0;
		t[v * 2] = t[v * 2 + 1] = lz1[v];
		lz1[v] = -inf;
	}
}
void assign(int l, int r, ll x, int v = 1, int tl = 1, int tr = n) {
	if (l > tr || r < tl)
		return;
	if (l <= tl && tr <= r) {
		t[v] = x;
		lz1[v] = x;
		lz2[v] = 0;
		return;
	}
	int tm = (tl + tr) / 2;
	push(v);
	assign(l, r, x, v * 2, tl, tm);
	assign(l, r, x, v * 2 + 1, tm + 1, tr);
}
void add(int l, int r, int x, int v = 1, int tl = 1, int tr = n) {
	if (l > tr || r < tl)
		return;
	if (l <= tl && tr <= r) {
		t[v] += x;
		if (lz1[v] != -inf)
			lz1[v] += x;
		else 
			lz2[v] += x;
		return;
	}
	int tm = (tl + tr) / 2;
	push(v);
	add(l, r, x, v * 2, tl, tm);
	add(l, r, x, v * 2 + 1, tm + 1, tr);
}
ll get(int x, int v = 1, int tl = 1, int tr = n) {
	if (tl == tr) 
		return t[v];
	int tm = (tl + tr) / 2;
	push(v);
	if (x <= tm)
		return get(x, v * 2, tl, tm);
	return get(x, v * 2 + 1, tm + 1, tr);
}
main() {
	ios :: sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> q;
	for (int i = 1; i <= 4 * n; ++i)
		lz1[i] = -inf;
	set <pii> st;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		assign(i, i, a[i]);
		st.insert({i, i});
	}
	for (int i = 1; i <= n; ++i) {
		cin >> b[i];
		p[i] = p[i - 1] + b[i];
	}
	while (q--) {
		int tp;
		cin >> tp;
		if (tp == 1) {
			int l, r, x;
			cin >> l >> r >> x;
			
			auto lb = st.lower_bound({l, 0});
			auto rb = st.lower_bound({r + 1, 0});
			rb--;
			bool flag = 0;
			if (lb != st.begin()) {
				--lb;
				flag = (lb == rb);
				++lb;
			}
			if (flag) {
				lb--;
				auto [L, R] = *lb;
				st.erase(lb);
				if (L < l)
					st.insert({L, l - 1});
				if (r < R)
					st.insert({r + 1, R});
				st.insert({l, r});
			}
			else {
				if (lb != st.begin()) {
					lb--;
					if (lb -> s >= l) {
						auto [L, R] = *lb;
						//[lb -> f, l - 1]
						//[l, lb -> s]
						st.erase(lb);
						st.insert({l, R});
						if (L < l) st.insert({L, l - 1});
					}
				}
				rb = st.lower_bound({r + 1, 0});
				rb--;
				auto [L, R] = *rb;
				st.erase(rb);
				st.insert({L, r});
				if (r < R)
					st.insert({r + 1, R});
			}
			add(l, r, x);
		}
		else {
			int l, r;
			cin >> l >> r;
			vector <pii> vec;
			vector <ll> vals;
			{
				auto lb = st.lower_bound({l, 0});
				auto rb = st.lower_bound({r + 1, 0});
				rb--;
				
				bool flag = 0;
				if (lb != st.begin()) {
					--lb;
					flag = (lb == rb);
					++lb;
				}
				if (flag) {
					--lb;
					auto [L, R] = *lb;
					st.erase(lb);
					if (L < l)
						st.insert({L, l - 1});
					if (r < R)
						st.insert({r + 1, R});
					vec.pb({l, r});
				}
				else {
					if (lb != st.begin()) {
						lb--;
						if (lb -> s >= l) {
							auto [L, R] = *lb;
							//[lb -> f, l - 1]
							//[l, lb -> s]
							vec.pb({l, R});
							st.erase(lb);
							if (L < l) st.insert({L, l - 1});
						}
					}
					rb = st.lower_bound({r + 1, 0});
					rb--;
					auto [L, R] = *rb;
					vec.pb({L, r});
					st.erase(rb);
					if (r < R)
						st.insert({r + 1, R});
				}
			}
			auto lb = st.lower_bound({l, 0});
			while (lb != st.end() && lb -> s <= r) {
				vec.pb(*lb);
				lb = st.erase(lb);
			}
			st.insert({l, r});
			ll tot = p[r] - p[l - 1], z = 0;
			for (auto [i, j] : vec) {
				vals.pb(get(i));
				z += j - i + 1;
			}
			assert(z == r - l + 1);
			vector <int> order;
			for (int i = 0; i < sz(vec); ++i) 
				order.pb(i);
			sort(all(order), [&] (int x, int y) {
				return vals[x] < vals[y];
			});
			ll cur = 0, x = -1;
			for (auto i : order) {
				auto [L, R] = vec[i];
				cur += p[R] - p[L - 1];
				if (cur >= (tot + 1) / 2) {
					x = vals[i];
					break;
				}
			}
			cout << x << '\n';
			assign(l, r, x);
		}
		
		
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 441ms
memory: 39568kb

input:

200000 200000
185413631 745038744 881479208 394948467 101727403 796960399 284541402 80768155 286582974 546327406 197495962 552359542 727479505 437895671 143092948 7626834 741609268 540494577 298656274 548860413 41137417 210529949 658779847 161355446 486548926 602900245 119414972 310187428 238177860 ...

output:

462406736
1749348519
1749348519
467651597
874061694
874061694
874061694
874061694
544422388
874061694
-893932302
41023278
41023278
798561652
798561652
798561652
798561652
798561652
798561652
798561652
41023278
546589476
546589476
546589476
1428518677
458072075
458072075
458072075
458072075
-15388794...

result:

wrong answer 9th lines differ - expected: '-1521749', found: '544422388'