QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#853757#3299. Advertisement Matchingrlc202204WA 0ms12048kbC++172.5kb2025-01-11 19:00:562025-01-11 19:00:57

Judging History

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

  • [2025-01-11 19:00:57]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:12048kb
  • [2025-01-11 19:00:56]
  • 提交

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};

bool cmp(int x, int y) {
	return x > y;
}

int main() {
	scanf("%d%d", &n, &m);
	ll ta = 0ll, 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 += a[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, 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, 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) {
			int pos = lower_bound(cb, cb + m + 1, b[j], greater<int>()) - cb;
			b[j]++, cb[pos]++;
			tb++;
			upd(1, 1, n + 1, 1, min(n + 1, cb[pos]), 1); 
		}
		else {
			int pos = (cb[m] == b[j] ? m : upper_bound(cb, cb + m + 1, b[j], greater<int>()) - cb - 1);
			b[j]--, cb[pos]--;
			tb--;
			upd(1, 1, n + 1, 1, min(n + 1, cb[pos]), -1); 
		}
		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;
} 

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 12036kb

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: -100
Wrong Answer
time: 0ms
memory: 12048kb

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
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
0

result:

wrong answer 2nd lines differ - expected: '1', found: '0'