QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#620023 | #5278. Mex and Cards | MCdyc | WA | 0ms | 3808kb | C++20 | 3.7kb | 2024-10-07 16:20:25 | 2024-10-07 16:20:31 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using i64 = long long;
using a3 = array<i64, 3>;
const i64 INF = 1ll << 30;
struct SegTree
{
#define ls (p << 1)
#define rs ((p << 1) | 1)
#define mid ((l + r) >> 1)
int n;
vector<i64> tr, val, L, R;
SegTree(int N = 0) : n(N)
{
tr.resize(n << 2 | 1);
val.resize(n << 2 | 1);
L.resize(n << 2 | 1);
R.resize(n << 2 | 1);
}
void update(int p, int l, int r)
{
tr[p] = tr[ls];
val[p] = val[ls];
L[p] = L[ls];
R[p] = R[ls];
if (tr[ls] == mid - l + 1 && tr[rs])
{
auto [len, mex, lmt] = query(R[ls], rs, mid + 1, r);
tr[p] += len;
val[p] += mex;
R[p] = lmt;
}
}
void add(int x, int k, int p, int l, int r)
{
if (l == r)
{
val[p] += k;
if (val[p] == 0)
{
tr[p] = 0;
L[p] = R[p] = 0;
}
else
{
tr[p] = 1;
L[p] = R[p] = val[p];
}
// cout << p << ' ' << l << ' ' << r << ' ' << tr[p] << ' ' << val[p] << ' ' << L[p] << ' ' << R[p] << endl;
return;
}
if (x <= mid)
add(x, k, ls, l, mid);
if (mid + 1 <= x)
add(x, k, rs, mid + 1, r);
update(p, l, r);
// cout << p << ' ' << l << ' ' << r << ' ' << tr[p] << ' ' << val[p] << ' ' << L[p] << ' ' << R[p] << endl;
}
a3 query(i64 limit, int p, int l, int r)
{
if (L[p] <= limit)
return {tr[p], val[p], R[p]};
else if (R[p] >= limit)
return {r - l + 1, limit * (r - l + 1ll), limit};
else if (l == r)
if (tr[p])
return {1, limit, limit};
else
return {0, 0, 0};
auto [len_ls, mex_ls, lmt_ls] = query(limit, ls, l, mid);
auto [len_rs, mex_rs, lmt_rs] = query(lmt_ls, rs, mid + 1, r);
if (len_ls == mid - l + 1 && lmt_rs)
{
len_ls += len_rs;
mex_ls += mex_rs;
lmt_ls = lmt_rs;
}
return {len_ls, mex_ls, lmt_ls};
}
// int find_less_than(int s, int t, int x, int p, int l, int r)
// {
// if (minn[p] >= x)
// return t + 1;
// if (t < l || s > r)
// return t + 1;
// int res = INF;
// if (s <= mid && minn[ls] < x)
// res = min(res, find_less_than(s, t, x, ls, l, mid));
// if (mid + 1 <= t && minn[rs] < x)
// res = min(res, find_less_than(s, t, x, rs, mid + 1, r));
// return res;
// }
};
void solve()
{
int n;
cin >> n;
SegTree tr(n);
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
tr.add(i, x, 1, 1, n);
// cout << endl;
}
cout << tr.val[1] << endl;
int q;
cin >> q;
while (q--)
{
int op, x;
cin >> op >> x;
x++;
if (x <= n)
{
if (op == 1)
tr.add(x, 1, 1, 1, n);
else
tr.add(x, -1, 1, 1, n);
}
// cout << endl;
cout << tr.val[1] << endl;
}
// while (q--)
// {
// int l, r, x;
// cin >> l >> r >> x;
// cout << tr.find_less_than(x, l, r, 1, 1, n) << endl;
// }
// cout << "Yes\n";
}
int main()
{
ios::sync_with_stdio(NULL);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
input:
5 2 1 3 0 2 6 1 0 1 1 2 4 1 3 2 1 2 1
output:
4 5 7 7 9 7 3
result:
ok 7 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
1 0 0
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
10 3 8 1 4 10 3 10 9 7 10 20 2 5 1 4 1 2 1 4 1 3 1 3 1 0 2 8 1 5 1 4 1 0 1 3 1 8 1 6 1 4 1 1 1 5 1 9 1 6 2 7
output:
14 14 14 22 22 22 22 24 24 24 24 26 26 26 26 26 26 26 26 26 26
result:
ok 21 numbers
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3808kb
input:
10 9 8 7 5 5 4 3 2 1 1 20 2 4 1 8 2 6 1 2 1 2 2 5 2 2 1 0 1 6 1 6 2 9 1 2 2 7 2 8 2 3 1 9 1 7 1 4 2 6 1 7
output:
45 44 45 44 45 45 44 44 45 46 46 45 45 44 43 42 43 44 44 44 45
result:
wrong answer 14th numbers differ - expected: '43', found: '44'