QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#741536 | #8783. Cherry Picking | zhenghanyun# | WA | 1ms | 6352kb | C++14 | 2.2kb | 2024-11-13 14:34:31 | 2024-11-13 14:34:32 |
Judging History
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);
}
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);
}
st.insert(node(1, n, 0, 0));
cin >> s;
for (int i = 1e5; i; --i) {
for (auto p: vec[i]) {
add(p, 1);
int op = s[p - 1] - '0';
node t = *--st.upper_bound(node(p, 0, 0, 0));
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)));
auto it = st.upper_bound(node(p, 0, 0, 0));
if (it != st.end() && it -> op == op) {
--it -> l;
++it -> len;
if (it -> len == k) {
++cnt;
}
} else {
if (it == st.begin()) {
ins(node(p, p, op, 1));
} else {
--it;
if (it -> op == op) {
++it -> r;
++it -> len;
if (it -> len == k) {
++cnt;
}
} else {
ins(node(p, p, op, 1));
}
}
}
}
}
if (cnt) {
ans = i;
break;
}
}
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5976kb
input:
5 2 1 2 3 4 5 01101
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 6352kb
input:
5 2 3 4 5 2 1 10101
output:
0
result:
ok answer is '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5908kb
input:
1 1 1 1
output:
1
result:
ok answer is '1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5940kb
input:
1 1 1 0
output:
0
result:
ok answer is '0'
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 6200kb
input:
5 3 8 3 5 2 7 10101
output:
0
result:
wrong answer expected '5', found '0'