제출 #1080241

#제출 시각아이디문제언어결과실행 시간메모리
1080241baluteshihInfinite Race (EGOI24_infiniterace2)C++17
100 / 100
135 ms20428 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define SZ(a) ((int)a.size())
#ifdef bbq
#include <experimental/iterator>
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
    cerr << "\e[1;32m(" << s << ") = (";
    int f = 0;
    (..., (cerr << (f++ ? ", " : "") << a));
    cerr << ")\e[0m\n";
}
void orange_(auto s, auto L, auto R) {
    cerr << "\e[1;33m[" << s << "] = [";
    using namespace experimental;
    copy(L, R, make_ostream_joiner(cerr, ", "));
    cerr << "]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n, q;
    cin >> n >> q;
    set<int> front, back;
    int ans = 0;
    while (q--) {
        int x;
        cin >> x;
        if (x > 0) {
            if (front.find(x) != front.end()) {
                for (int i : front)
                    back.insert(i);
                front.clear();
                front.insert(x);
                ++ans;
            }
            else if (back.find(x) != back.end())
                back.erase(x), front.insert(x);
            else
                front.insert(x);
        }
        else {
            x *= -1;
            front.erase(x);
            back.insert(x);
        }
        orange(ALL(front));
        orange(ALL(back));
        debug(ans);
    }
    cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...