QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#564250#3850. DJ DarkoFortitudeWA 419ms39536kbC++234.2kb2024-09-14 21:30:142024-09-14 21:30:15

Judging History

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

  • [2024-09-14 21:30:15]
  • 评测
  • 测评结果:WA
  • 用时:419ms
  • 内存:39536kb
  • [2024-09-14 21:30:14]
  • 提交

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) {
	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];
		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});
				}
				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: 419ms
memory: 39536kb

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
1668900457
0
1668900457
1203955356
0
0
-893932302
0
0
757538374
757538374
511700037
0
0
0
0
0
0
0
0
0
0
0
0
0
-611960024
0
0
0
-258956513
0
0
0
0
0
-894055877
-894055877
0
-787574832
-894055877
-1780885549
96757019
96757019
27171536
27171536
0
0
0
0
0
0
0
-1...

result:

wrong answer 5th lines differ - expected: '874061694', found: '1668900457'