QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#564241#3850. DJ DarkoFortitude#WA 427ms36436kbC++234.2kb2024-09-14 21:25:462024-09-14 21:25:47

Judging History

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

  • [2024-09-14 21:25:47]
  • 评测
  • 测评结果:WA
  • 用时:427ms
  • 内存:36436kb
  • [2024-09-14 21:25:46]
  • 提交

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
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) {
	if (lz2[v]) {
		lz2[2 * v] += lz2[v];
		lz2[2 * v + 1] += lz2[v];
		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];
		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;
		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;
		lz2[v] += x;
		if (lz1[v] != -inf)
			lz1[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);
}
int 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});
				}
				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];
			for (auto [i, j] : vec) {
				vals.pb(get(i));
			}
			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 = 0;
			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;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 427ms
memory: 36436kb

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
1648748099
467651597
1201433969
0
1201433969
307214679
0
0
-893932302
-205760183
81936194
398500387
398500387
296658058
0
1692374913
0
1692374913
-1544433150
797856174
0
-839878190
-753742765
192932966
-497819228
-497819228
0
-318573549
0
0
0
-701733071
0
0
0
-462353951
0
-23042...

result:

wrong answer 3rd lines differ - expected: '1749348519', found: '1648748099'