QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425342 | #8573. Slothful Secretary | ucup-team3215 | RE | 0ms | 0kb | C++23 | 3.7kb | 2024-05-30 09:01:34 | 2024-05-30 09:01:34 |
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pl = pair<ll, ll>;
constexpr ll INF = 1e9 + 7;
constexpr ll mod = 1e9 + 7;
constexpr ld eps = 1e-9;
const ld PI = acos(-1);
struct s_tr {
vector<pl> mn;
vector<ll> s, t;
vector<ll> to_push;
s_tr(const vector<ll> &a) {
ll n = a.size();
mn.resize(4 * n, {INF, 0});
s.resize(4 * n, 0);
t.resize(4 * n, 0);
to_push.resize(4 * n, 0);
build(0, 0, n, a);
}
void build(ll v, ll l, ll r, const vector<ll> &a) {
if (l + 1 == r) {
s[v] = t[v] = a[l];
mn[v] = {0, 1};
return;
}
ll m = (r + l) / 2;
build(v * 2 + 1, l, m, a);
build(v * 2 + 2, m, r, a);
mn[v] = min(mn[v * 2 + 1], mn[v * 2 + 2]);
if (mn[v * 2 + 1].first == mn[v * 2 + 2].first)mn[v].second = mn[v * 2 + 1].second + mn[v * 2 + 2].second;
s[v] = min(s[v * 2 + 1], s[v * 2 + 2]);
t[v] = max(t[v * 2 + 1], t[v * 2 + 2]);
}
void sets(ll v, ll x) {
mn[v].first += x;
to_push[v] += x;
}
void push(ll v) {
sets(v * 2 + 1, to_push[v]);
sets(v * 2 + 2, to_push[v]);
to_push[v] = 0;
}
ll first(ll v, ll l, ll r, ll x) {
if (l + 1 == r) {
return l;
}
ll m = (r + l) / 2;
push(v);
if (t[v * 2 + 1] >= x) {
return first(v * 2 + 1, l, m, x);
}
return first(v * 2 + 2, m, r, x);
}
ll last(ll v, ll l, ll r, ll x) {
if (l + 1 == r) {
return l;
}
ll m = (r + l) / 2;
push(v);
if (s[v * 2 + 2] <= x) {
return last(v * 2 + 2, m, r, x);
}
return last(v * 2 + 1, l, m, x);
}
void add(ll v, ll l, ll r, ll k, ll x) {
if (l + 1 == r) {
s[v] += x;
t[v] += x;
return;
}
ll m = (r + l) / 2;
push(v);
if (k < m) {
add(v * 2 + 1, l, m, k, x);
} else add(v * 2 + 2, m, r, k, x);
s[v] = min(s[v * 2 + 1], s[v * 2 + 2]);
t[v] = max(t[v * 2 + 1], t[v * 2 + 2]);
}
void upd(ll v, ll l, ll r, ll lq, ll rq, ll x) {
if (l >= rq || lq >= r) {
return;
}
if (l >= lq && r <= rq) {
sets(v, x);
return;
}
ll m = (r + l) / 2;
push(v);
upd(v * 2 + 1, l, m, lq, rq, x);
upd(v * 2 + 2, m, r, lq, rq, x);
mn[v] = min(mn[v * 2 + 1], mn[v * 2 + 2]);
if (mn[v * 2 + 1].first == mn[v * 2 + 2].first)mn[v].second = mn[v * 2 + 1].second + mn[v * 2 + 2].second;
}
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
ll n, q;
cin >> n >> q;
vector<ll> a(n);
iota(a.begin(), a.end(), 0);
s_tr tree(a);
map<pl, ll> w;
while (q--) {
ll x, y;
cin >> x >> y;
--x, --y;
swap(x, y);
if (!w.count(pl{x, y})) {
w[pl{x, y}] = 0;
}
if(w[pl{x, y}])swap(x,y);
w[pl{x, y}] ^= 1;
{
int pos = tree.first(0, 0, n, a[x]);
tree.add(0, 0, n, pos, -1);
tree.upd(0, 0, n, pos, n, -1);
--a[x];
}
{
int pos = tree.last(0, 0, n, a[y]);
tree.add(0, 0, n, pos, 1);
tree.upd(0, 0, n, pos, n, 1);
++a[y];
}
auto it = tree.mn[0];
assert(it.first == 0);
cout << it.second << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
500000 500000 111236 111238 400537 400538 14798 14799 480138 480140 99901 99904 169041 169045 20969 20970 111098 111100 245492 245493 25296 25300 21736 21739 415491 415495 222594 222595 162236 162238 362422 362425 422694 422695 339973 339974 241678 241680 192401 192403 125627 125629 261473 261474 10...
output:
499998 499998 499998 499996 499993 499989 499989 499987 499987 499983 499980 499976 499976 499974 499971 499971 499971 499969 499967 499965 499965 499961 499961 499961 499961 499961 499961 499958 499955 499952 499949 499947 499947 499945 499942 499940 499938 499936 499934 499930 499926 499924 499920...