QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#741612#8783. Cherry Pickingzhenghanyun#WA 1ms6048kbC++142.3kb2024-11-13 14:46:512024-11-13 14:46:58

Judging History

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

  • [2024-11-13 14:46:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6048kb
  • [2024-11-13 14:46:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 1e5 + 5;

struct node {
	mutable int l, r, op, len;

	node() {}
	node(int l, int r, int op, int len): l(l), r(r), op(op), len(len) {}

	inline bool operator<(const node &rhs) const {
		return l < rhs.l;
	}
};

int n, k, cnt, ans, a[N], p[N];

string s;

vector <int> vec[N];
set <node> st;

inline void ins(node t) {
	if (t.l > t.r) {
		return;
	}
	st.insert(t);
	if (t.op == 1 && t.len >= k) {
		++cnt;
	}
}

inline void del(node t) {
	st.erase(t);
	if (t.op == 1 && t.len >= k) {
		--cnt;
	}
}

int tree[N];

inline int lowbit(int p) {
	return p & (-p);
}

inline void add(int p, int val) {
	while (p <= n) {
		tree[p] += val;
		p += lowbit(p);
	}
}

inline int get_sum(int p) {
	int res = 0;
	while (p) {
		res += tree[p];
		p ^= lowbit(p);
	}
	return res;
}

inline int query(int l, int r) {
	return get_sum(r) - get_sum(l - 1);
}

inline void INS(int p, int op) {
	auto it = st.upper_bound(node(p, 0, 0, 0));
	if (it != st.end() && it -> op == op && it -> l == p + 1) {
		--it -> l;
		++it -> len;
		if (it -> len == k && op == 1) {
			++cnt;
		}
	} else {
		if (it == st.begin()) {
			ins(node(p, p, op, 1));
		} else {
			--it;
			if (it -> op == op && it -> r + 1 == p) {
				++it -> r;
				++it -> len;
				if (it -> len == k && op == 1) {
					++cnt;
				}
			} else {
				ins(node(p, p, op, 1));
			}
		}
	}
}

int main() {
	#ifdef LOCAL
		assert(freopen("test.in", "r", stdin));
		assert(freopen("test.out", "w", stdout));
	#endif
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		vec[a[i]].emplace_back(i);
	}
	cin >> s;
	for (int i = 1e5; i; --i) {
		for (auto p: vec[i]) {
			add(p, 1);
			int op = s[p - 1] - '0';
			auto it = st.upper_bound(node(p, 0, 0, 0));
			if (it == st.begin()) {
				INS(p, op);
				continue;
			}
			node t = *--it;
			if (it -> r < p) {
				INS(p, op);
				continue;
			}
			del(t);
			if (op == t.op) {
				++t.len;
				ins(t);
			} else {
				ins(node(t.l, p - 1, t.op, query(t.l, p - 1)));
				ins(node(p + 1, t.r, t.op, query(p + 1, t.r)));
				INS(p, op);
			}
		}
		if (cnt) {
			ans = i;
			break;
		}
	}
	cout << ans << "\n";
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 6036kb

input:

5 2
1 2 3 4 5
01101

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5916kb

input:

5 2
3 4 5 2 1
10101

output:

0

result:

ok answer is '0'

Test #3:

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

input:

1 1
1
1

output:

1

result:

ok answer is '1'

Test #4:

score: 0
Accepted
time: 1ms
memory: 6048kb

input:

1 1
1
0

output:

0

result:

ok answer is '0'

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 5916kb

input:

5 3
8 3 5 2 7
10101

output:

0

result:

wrong answer expected '5', found '0'