Submission #1010819

# Submission time Handle Problem Language Result Execution time Memory
1010819 2024-06-29T11:58:28 Z vjudge1 Queue (CEOI06_queue) C++17
48 / 100
301 ms 15712 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)

const int inf = 1e9;
int main() {
    //ios_base::sync_with_stdio(0);cin.tie(0);

    int n;
    cin >> n;
    map<int, int> Nxt, Prv;
    set<array<int, 2>> st;
    st.insert({0, inf + 1});

    while (n--) {
        int a, b;
        cin >> a >> b;

        auto ind = st.upper_bound({a, 2 * inf});
        ind--;
        auto cur = *ind;
        if (a >= cur[0] && a <= cur[1]) {
            st.erase(ind);
            if (a - 1 >= cur[0]) {
                st.insert({cur[0], a - 1});
            }
            if (a + 1 <= cur[1]) {
                st.insert({a + 1, cur[1]});
            }
        }

        swap(a, b);
        ind = st.upper_bound({a, 2 * inf});
        ind--;
        cur = *ind;
        if (a >= cur[0] && a <= cur[1]) {
            st.erase(ind);
            if (a - 1 >= cur[0]) {
                st.insert({cur[0], a - 1});
            }
            if (a + 1 <= cur[1]) {
                st.insert({a + 1, cur[1]});
            }
        }
        swap(a, b);

        if (!Prv[a]) {
            Prv[a] = a - 1;
        }
        if (!Prv[b]) {
            Prv[b] = b - 1;
        }
        if (!Nxt[a]) {
            Nxt[a] = a + 1;
        }
        if (!Nxt[b]) {
            Nxt[b] = b + 1;
        }
        Nxt[Prv[a]] = Nxt[a], Prv[Nxt[a]] = Prv[a];
        Nxt[Prv[b]] = a, Prv[a] = Prv[b];
        Nxt[a] = b, Prv[b] = a;
    }
    vector<array<int, 2>> Pos, Val;
    int q;
    cin >> q;
    int temp = 0;
    while (q--) {
        char kind;
        int cur;
        cin >> kind >> cur;
        if (kind == 'P') {
            Val.push_back({cur, temp});
        }
        else {
            Pos.push_back({cur, temp});
        }
        temp++;
    }

    int pos = 0, val = 0;
    sort(all(Pos));
    sort(all(Val));

    if (!Nxt[0]) {
        Nxt[0] = 1;
    }
    if (!Nxt[inf]) {
        Nxt[inf] = inf + 1;
    }
    vector<array<int, 2>> Ans;
    int cur_val = 0, cur_ind = 0;
    bool jump = 0;
    int last = -1;
    while (cur_val <= inf) {
        //cout << cur_val << ' '  << cur_ind << endl;
        while (pos < Pos.size() && Pos[pos][0] <= cur_ind) {
            Ans.push_back({Pos[pos][1], cur_val - (cur_ind - Pos[pos][0])});
            pos++;
        }
        while (val < Val.size() && Val[val][0] == cur_val || (Val[val][0] < cur_val && Val[val][0] > last && jump)) {
            Ans.push_back({Val[val][1], cur_ind - (cur_val - Val[val][0])});
            val++;
        }

        if (Nxt.count(cur_val)) {
            cur_val = Nxt[cur_val];
            cur_ind++;
            jump = 0;
            last = cur_val;
            continue;
        }
        auto ind = st.upper_bound({cur_val,  2 * inf});
        ind--;
        auto cur = *ind;
        if (cur_val < cur[0] || cur_val > cur[1]) {
            break;
        }
        cur_ind += cur[1] - cur_val;
        cur_val = cur[1];
        last = cur_val;
        jump = 1;
    }
    while (pos < Pos.size() && Pos[pos][0] <= cur_ind) {
        Ans.push_back({Pos[pos][1], cur_val - (cur_ind - Pos[pos][0])});
        pos++;
    }
    while (val < Val.size() && Val[val][0] <= cur_val) {
        Ans.push_back({Val[val][1], cur_ind - (cur_val - Val[val][0])});
        val++;
    }

    sort(all(Ans));
    for (int i = 0; i < Ans.size(); i++) {
        cout << Ans[i][1] << endl;
    }

}

Compilation message

queue.cpp: In function 'int main()':
queue.cpp:101:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         while (pos < Pos.size() && Pos[pos][0] <= cur_ind) {
      |                ~~~~^~~~~~~~~~~~
queue.cpp:105:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |         while (val < Val.size() && Val[val][0] == cur_val || (Val[val][0] < cur_val && Val[val][0] > last && jump)) {
      |                ~~~~^~~~~~~~~~~~
queue.cpp:105:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  105 |         while (val < Val.size() && Val[val][0] == cur_val || (Val[val][0] < cur_val && Val[val][0] > last && jump)) {
      |                ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
queue.cpp:128:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |     while (pos < Pos.size() && Pos[pos][0] <= cur_ind) {
      |            ~~~~^~~~~~~~~~~~
queue.cpp:132:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  132 |     while (val < Val.size() && Val[val][0] <= cur_val) {
      |            ~~~~^~~~~~~~~~~~
queue.cpp:138:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |     for (int i = 0; i < Ans.size(); i++) {
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 348 KB Partially correct
2 Partially correct 1 ms 348 KB Partially correct
3 Partially correct 2 ms 344 KB Partially correct
4 Partially correct 3 ms 604 KB Partially correct
5 Partially correct 30 ms 2016 KB Partially correct
6 Partially correct 37 ms 2900 KB Partially correct
7 Partially correct 49 ms 3536 KB Partially correct
8 Partially correct 63 ms 5280 KB Partially correct
9 Partially correct 103 ms 5544 KB Partially correct
10 Partially correct 76 ms 6000 KB Partially correct
11 Partially correct 213 ms 9812 KB Partially correct
12 Partially correct 176 ms 7652 KB Partially correct
13 Partially correct 228 ms 10064 KB Partially correct
14 Partially correct 230 ms 10264 KB Partially correct
15 Partially correct 236 ms 10404 KB Partially correct
16 Partially correct 224 ms 10272 KB Partially correct
17 Partially correct 41 ms 956 KB Partially correct
18 Partially correct 57 ms 1632 KB Partially correct
19 Partially correct 90 ms 2256 KB Partially correct
20 Partially correct 160 ms 3220 KB Partially correct
21 Incorrect 172 ms 10956 KB Unexpected end of file - int32 expected
22 Partially correct 244 ms 12732 KB Partially correct
23 Partially correct 301 ms 15712 KB Partially correct
24 Partially correct 289 ms 15568 KB Partially correct
25 Partially correct 289 ms 10980 KB Partially correct