QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378807 | #8573. Slothful Secretary | ucup-team180# | WA | 1109ms | 46204kb | C++14 | 2.3kb | 2024-04-06 14:44:46 | 2024-04-06 14:44:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000;
struct monoid{
long long mn;
int cnt;
monoid(): mn(INF), cnt(0){
}
monoid(long long x): mn(x), cnt(1){
}
};
monoid op(monoid L, monoid R){
monoid ans;
ans.mn = min(L.mn, R.mn);
ans.cnt = (ans.mn == L.mn ? L.cnt : 0) + (ans.mn == R.mn ? R.cnt : 0);
return ans;
}
struct lazy_segment_tree{
int N;
vector<monoid> ST;
vector<int> lazy;
lazy_segment_tree(int n){
N = 1;
while (N < n){
N *= 2;
}
ST = vector<monoid>(N * 2 - 1);
for (int i = 0; i < n; i++){
ST[N - 1 + i] = monoid(0);
}
for (int i = N - 2; i >= 0; i--){
ST[i] = op(ST[i * 2 + 1], ST[i * 2 + 2]);
}
lazy = vector<int>(N * 2 - 1, 0);
}
void push(int i){
if (i < N - 1){
lazy[i * 2 + 1] += lazy[i];
lazy[i * 2 + 2] += lazy[i];
}
ST[i].mn += lazy[i];
lazy[i] = 0;
}
void range_add(int L, int R, int x, int i, int l, int r){
push(i);
if (r <= L || R <= l){
} else if (L <= l && r <= R){
lazy[i] = x;
push(i);
} else {
int m = (l + r) / 2;
range_add(L, R, x, i * 2 + 1, l, m);
range_add(L, R, x, i * 2 + 2, m, r);
ST[i] = op(ST[i * 2 + 1], ST[i * 2 + 2]);
}
}
void range_add(int L, int R, int x){
range_add(L, R, x, 0, 0, N);
}
int get(){
push(0);
return ST[0].mn == 0 ? ST[0].cnt : 0;
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<int> in(n);
for (int i = 0; i < n; i++){
in[i] = i;
}
vector<int> S(n);
for (int i = 0; i < n; i++){
S[i] = i;
}
lazy_segment_tree ST(n);
set<pair<int, int>> st;
for (int i = 0; i < q; i++){
int u, v;
cin >> u >> v;
u--;
v--;
if (st.count(make_pair(u, v)) == 1){
swap(u, v);
st.erase(make_pair(u, v));
} else {
st.insert(make_pair(u, v));
}
int r = upper_bound(S.begin(), S.end(), in[u]) - S.begin() - 1;
S[r]++;
in[u]++;
ST.range_add(r, n, 1);
int l = lower_bound(S.begin(), S.end(), in[v]) - S.begin();
S[l]--;
in[v]--;
ST.range_add(l, n, -1);
cout << ST.get() << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1109ms
memory: 46204kb
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...
result:
wrong answer 17729th numbers differ - expected: '473471', found: '0'