QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#741578 | #8783. Cherry Picking | zhenghanyun# | WA | 2ms | 6704kb | C++14 | 2.3kb | 2024-11-13 14:40:51 | 2024-11-13 14:40:51 |
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);
}
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;
++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));
}
}
}
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5968kb
input:
5 2 1 2 3 4 5 01101
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 6268kb
input:
5 2 3 4 5 2 1 10101
output:
0
result:
ok answer is '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 6704kb
input:
1 1 1 1
output:
1
result:
ok answer is '1'
Test #4:
score: 0
Accepted
time: 2ms
memory: 5944kb
input:
1 1 1 0
output:
0
result:
ok answer is '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5904kb
input:
5 3 8 3 5 2 7 10101
output:
5
result:
ok answer is '5'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 5904kb
input:
10 3 1 10 2 3 9 3 1 6 9 3 1100110001
output:
3
result:
wrong answer expected '0', found '3'