QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#853793#3299. Advertisement Matchingrlc202204WA 2ms12076kbC++173.1kb2025-01-11 19:17:232025-01-11 19:17:33

Judging History

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

  • [2025-01-11 19:17:33]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12076kb
  • [2025-01-11 19:17:23]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2.5e5 + 5;
typedef long long ll;
#define debug(x) cout << #x << "=" << x << endl 

ll val[N << 2] = {0};
ll tag[N << 2] = {0};
#define ls (x << 1)
#define rs (x << 1 | 1)
#define mid ((lx + rx) >> 1)
void pushup(int x) {
	val[x] = max(val[ls], val[rs]);
}
void pushdown(int x) {
	if (tag[x] == 0ll)	
		return;
	val[ls] += tag[x], tag[ls] += tag[x];
	val[rs] += tag[x], tag[rs] += tag[x];
	tag[x] = 0ll;
}
void build(int x, int lx, int rx, ll *a) {
	if (lx + 1 == rx) {
		val[x] = a[lx];
		return;
	}
	build(ls, lx, mid, a), build(rs, mid, rx, a);
	pushup(x);
}
void upd(int x, int lx, int rx, int l, int r, ll v) {
	if (rx <= l || r <= lx)
		return;
	if (l <= lx && rx <= r) {
		val[x] += v;
		tag[x] += v;
		return;
	}
	pushdown(x);
	upd(ls, lx, mid, l, r, v), upd(rs, mid, rx, l, r, v);
	pushup(x);
}
#undef ls
#undef rs
#undef mid

int n, m;
int a[N] = {0};
int b[N] = {0};
int ca[N] = {0}, cb[N] = {0};
ll res[N] = {0};
ll ta, tb;
bool cmp(int x, int y) {
	return x > y;
}

void calc() {
	/*
	for (int i = 1; i <= n; i++)
		cout << ca[i] << " ";
	cout << endl;
	for (int j = 1; j <= m; j++)
		cout << cb[j] << " ";
	cout << endl;
	*/
	ll sum = tb, ans = 0;
	for (int i = 1, j = m; i <= n; i++) {
		while (j >= 1 && cb[j] < i)
			sum -= cb[j], j--;
		sum += ca[i];
		res[i] = sum - 1ll * j * i;
		ans = max(ans, res[i]);
	//	debug(i), debug(res[i]);
	}
	ll mn = min({ta, tb, ta + tb - ans});
	if (mn == ta)
		printf("1\n");
	else
		printf("0\n");
}

int main() {
	scanf("%d%d", &n, &m);
	ta = tb = 0ll;
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]), ca[i] = a[i], ta += a[i];
	for (int j = 1; j <= m; j++)
		scanf("%d", &b[j]), cb[j] = b[j], tb += b[j];
	sort(ca + 1, ca + n + 1, cmp);
	sort(cb + 1, cb + m + 1, cmp);
	ll sum = tb;
	for (int i = 1, j = m; i <= n; i++) {
		while (j >= 1 && cb[j] < i)
			sum -= cb[j], j--;
		sum += ca[i];
		res[i] = sum - 1ll * j * i;
//		debug(i), debug(res[i]);
	}
	build(1, 1, n + 1, res);
	int q;
	scanf("%d", &q);
	for (int i = 1, op, j; i <= q; i++) {
		scanf("%d%d", &op, &j);
		if (op == 1) {
			int pos = lower_bound(ca + 1, ca + n + 1, a[j], greater<int>()) - ca;
			a[j]++, ca[pos]++;
			ta++;
	//		debug(pos);
			upd(1, 1, n + 1, pos, n + 1, 1);
		}
		else if (op == 2) {
			int pos = (ca[n] == a[j] ? n : upper_bound(ca + 1, ca + n + 1, a[j], greater<int>()) - ca - 1);
			a[j]--, ca[pos]--;
			ta--;
			upd(1, 1, n + 1, pos, n + 1, -1); 
		}
		else if (op == 3) {
		//	debug(b[j]);
			int pos = lower_bound(cb + 1, cb + m + 1, b[j], greater<int>()) - cb;
			upd(1, 1, n + 1, 1, min(n + 1, cb[pos]), 1); 	
			b[j]++, cb[pos]++;
			tb++;
		//	debug(pos);
	
		}
		else {
			int pos = (cb[m] == b[j] ? m : upper_bound(cb + 1, cb + m + 1, b[j], greater<int>()) - cb - 1);
			upd(1, 1, n + 1, 1, min(n + 1, cb[pos]), -1); 
			b[j]--, cb[pos]--;
			tb--;
		}
	//	calc();
		ll ans = min({ta, tb, ta + tb - val[1]});
	//	cout << val[1] << endl;
	//	cout << ans << " " << ta << " " << tb << endl;
		if (ans == ta)
			printf("1\n");
		else
			printf("0\n");
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 12072kb

input:

5 5
1 5 2 4 3
3 3 3 3 3
5
4 2
3 5
2 2
1 1
1 4

output:

0
1
1
1
0

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 9948kb

input:

100 100
13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 1...

output:

1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 100 lines

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 12076kb

input:

100 100
42 28 42 64 42 29 72 64 72 29 28 72 28 72 29 42 64 42 72 29 64 29 72 28 42 64 72 64 28 42 72 42 29 64 72 64 72 29 72 29 64 42 64 72 29 28 42 64 72 64 72 28 42 64 64 42 64 64 28 28 72 29 28 64 28 64 64 72 64 28 42 29 64 42 64 42 72 64 64 64 28 64 42 72 64 29 64 29 64 64 72 29 29 28 42 72 64 7...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

wrong answer 44th lines differ - expected: '0', found: '1'