Submission #623111

# Submission time Handle Problem Language Result Execution time Memory
623111 2022-08-05T08:14:20 Z AlperenT Minerals (JOI19_minerals) C++17
90 / 100
279 ms 14692 KB
#include <bits/stdc++.h>
#include "minerals.h"

using namespace std;

const int N = 50000 + 5;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, ans[N], ptr, cnt;

vector<int> a, b;

set<int> cur;

int query(int x){
    if(cur.find(x) != cur.end()) cur.erase(x);
    else cur.insert(x);

    return cnt = Query(x);
}

struct SegTree{
    vector<int> tree[N * 4];

    void build(int v = 1, int l = 1, int r = n, bool flag = false){
        if(l == r) ans[l] = tree[v].front();
        else{
            int m = l + (r - l) / 2;

            if(ptr < m){
                while(ptr < m){
                    ptr++;
                    query(a[ptr - 1]);
                }
            }
            else{
                ptr = r;

                while(ptr > m){
                    query(a[ptr - 1]);
                    ptr--;
                }
            }

            for(auto x : tree[v]){
                if(tree[v * 2].size() == (m - l + 1)) tree[v * 2 + 1].push_back(x);
                else if(tree[v * 2 + 1].size() == (r - (m + 1) + 1)) tree[v * 2].push_back(x);
                else{
                    if(cur.find(x) == cur.end()){
                        int prevcnt = cnt;

                        query(x);

                        if(prevcnt + 1 == cnt) tree[v * 2 + 1].push_back(x);
                        else tree[v * 2].push_back(x);
                    }
                    else{
                        int prevcnt = cnt;

                        query(x);

                        if(prevcnt == cnt) tree[v * 2].push_back(x);
                        else tree[v * 2 + 1].push_back(x);
                    }
                }
            }

            build(v * 2 + 1, m + 1, r, flag ^ 1);
            build(v * 2, l, m, flag ^ 1);
        }
    }
};

SegTree sgt;

void Solve(int N_) {
    n = N_;

    for(int i = 1; i <= n * 2; i++){
        int prvcnt = cnt;

        query(i);

        if(cnt == prvcnt + 1) a.push_back(i);
        else b.push_back(i);
    }

    ptr = 1 + (n - 1) / 2;

    for(auto x : b) sgt.tree[1].push_back(x);

    sgt.build();

    for(int i = 1; i <= n; i++) Answer(a[i - 1], ans[i]);
}

Compilation message

minerals.cpp: In member function 'void SegTree::build(int, int, int, bool)':
minerals.cpp:47:39: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |                 if(tree[v * 2].size() == (m - l + 1)) tree[v * 2 + 1].push_back(x);
      |                    ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
minerals.cpp:48:48: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |                 else if(tree[v * 2 + 1].size() == (r - (m + 1) + 1)) tree[v * 2].push_back(x);
      |                         ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5200 KB Output is correct
2 Correct 9 ms 5328 KB Output is correct
3 Correct 18 ms 5668 KB Output is correct
4 Correct 38 ms 6496 KB Output is correct
5 Correct 83 ms 7908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 5 ms 5200 KB Output is correct
6 Correct 9 ms 5328 KB Output is correct
7 Correct 18 ms 5668 KB Output is correct
8 Correct 38 ms 6496 KB Output is correct
9 Correct 83 ms 7908 KB Output is correct
10 Correct 6 ms 5200 KB Output is correct
11 Correct 61 ms 7140 KB Output is correct
12 Correct 80 ms 7924 KB Output is correct
13 Correct 58 ms 8132 KB Output is correct
14 Correct 60 ms 7856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 5 ms 5200 KB Output is correct
6 Correct 9 ms 5328 KB Output is correct
7 Correct 18 ms 5668 KB Output is correct
8 Correct 38 ms 6496 KB Output is correct
9 Correct 83 ms 7908 KB Output is correct
10 Correct 6 ms 5200 KB Output is correct
11 Correct 61 ms 7140 KB Output is correct
12 Correct 80 ms 7924 KB Output is correct
13 Correct 58 ms 8132 KB Output is correct
14 Correct 60 ms 7856 KB Output is correct
15 Correct 243 ms 13820 KB Output is correct
16 Correct 243 ms 13800 KB Output is correct
17 Correct 158 ms 14120 KB Output is correct
18 Correct 133 ms 13592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 5 ms 5200 KB Output is correct
6 Correct 9 ms 5328 KB Output is correct
7 Correct 18 ms 5668 KB Output is correct
8 Correct 38 ms 6496 KB Output is correct
9 Correct 83 ms 7908 KB Output is correct
10 Correct 6 ms 5200 KB Output is correct
11 Correct 61 ms 7140 KB Output is correct
12 Correct 80 ms 7924 KB Output is correct
13 Correct 58 ms 8132 KB Output is correct
14 Correct 60 ms 7856 KB Output is correct
15 Correct 243 ms 13820 KB Output is correct
16 Correct 243 ms 13800 KB Output is correct
17 Correct 158 ms 14120 KB Output is correct
18 Correct 133 ms 13592 KB Output is correct
19 Correct 267 ms 13952 KB Output is correct
20 Correct 253 ms 13904 KB Output is correct
21 Correct 150 ms 14148 KB Output is correct
22 Correct 137 ms 13768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 5 ms 5200 KB Output is correct
6 Correct 9 ms 5328 KB Output is correct
7 Correct 18 ms 5668 KB Output is correct
8 Correct 38 ms 6496 KB Output is correct
9 Correct 83 ms 7908 KB Output is correct
10 Correct 6 ms 5200 KB Output is correct
11 Correct 61 ms 7140 KB Output is correct
12 Correct 80 ms 7924 KB Output is correct
13 Correct 58 ms 8132 KB Output is correct
14 Correct 60 ms 7856 KB Output is correct
15 Correct 243 ms 13820 KB Output is correct
16 Correct 243 ms 13800 KB Output is correct
17 Correct 158 ms 14120 KB Output is correct
18 Correct 133 ms 13592 KB Output is correct
19 Correct 267 ms 13952 KB Output is correct
20 Correct 253 ms 13904 KB Output is correct
21 Correct 150 ms 14148 KB Output is correct
22 Correct 137 ms 13768 KB Output is correct
23 Correct 253 ms 14012 KB Output is correct
24 Correct 272 ms 14004 KB Output is correct
25 Correct 153 ms 14336 KB Output is correct
26 Correct 156 ms 13932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 5 ms 5200 KB Output is correct
6 Correct 9 ms 5328 KB Output is correct
7 Correct 18 ms 5668 KB Output is correct
8 Correct 38 ms 6496 KB Output is correct
9 Correct 83 ms 7908 KB Output is correct
10 Correct 6 ms 5200 KB Output is correct
11 Correct 61 ms 7140 KB Output is correct
12 Correct 80 ms 7924 KB Output is correct
13 Correct 58 ms 8132 KB Output is correct
14 Correct 60 ms 7856 KB Output is correct
15 Correct 243 ms 13820 KB Output is correct
16 Correct 243 ms 13800 KB Output is correct
17 Correct 158 ms 14120 KB Output is correct
18 Correct 133 ms 13592 KB Output is correct
19 Correct 267 ms 13952 KB Output is correct
20 Correct 253 ms 13904 KB Output is correct
21 Correct 150 ms 14148 KB Output is correct
22 Correct 137 ms 13768 KB Output is correct
23 Correct 253 ms 14012 KB Output is correct
24 Correct 272 ms 14004 KB Output is correct
25 Correct 153 ms 14336 KB Output is correct
26 Correct 156 ms 13932 KB Output is correct
27 Correct 264 ms 14472 KB Output is correct
28 Correct 278 ms 14340 KB Output is correct
29 Correct 154 ms 14528 KB Output is correct
30 Correct 141 ms 14256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 5 ms 5200 KB Output is correct
6 Correct 9 ms 5328 KB Output is correct
7 Correct 18 ms 5668 KB Output is correct
8 Correct 38 ms 6496 KB Output is correct
9 Correct 83 ms 7908 KB Output is correct
10 Correct 6 ms 5200 KB Output is correct
11 Correct 61 ms 7140 KB Output is correct
12 Correct 80 ms 7924 KB Output is correct
13 Correct 58 ms 8132 KB Output is correct
14 Correct 60 ms 7856 KB Output is correct
15 Correct 243 ms 13820 KB Output is correct
16 Correct 243 ms 13800 KB Output is correct
17 Correct 158 ms 14120 KB Output is correct
18 Correct 133 ms 13592 KB Output is correct
19 Correct 267 ms 13952 KB Output is correct
20 Correct 253 ms 13904 KB Output is correct
21 Correct 150 ms 14148 KB Output is correct
22 Correct 137 ms 13768 KB Output is correct
23 Correct 253 ms 14012 KB Output is correct
24 Correct 272 ms 14004 KB Output is correct
25 Correct 153 ms 14336 KB Output is correct
26 Correct 156 ms 13932 KB Output is correct
27 Correct 264 ms 14472 KB Output is correct
28 Correct 278 ms 14340 KB Output is correct
29 Correct 154 ms 14528 KB Output is correct
30 Correct 141 ms 14256 KB Output is correct
31 Correct 277 ms 14508 KB Output is correct
32 Correct 276 ms 14596 KB Output is correct
33 Correct 165 ms 14692 KB Output is correct
34 Correct 148 ms 14272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 5 ms 5200 KB Output is correct
6 Correct 9 ms 5328 KB Output is correct
7 Correct 18 ms 5668 KB Output is correct
8 Correct 38 ms 6496 KB Output is correct
9 Correct 83 ms 7908 KB Output is correct
10 Correct 6 ms 5200 KB Output is correct
11 Correct 61 ms 7140 KB Output is correct
12 Correct 80 ms 7924 KB Output is correct
13 Correct 58 ms 8132 KB Output is correct
14 Correct 60 ms 7856 KB Output is correct
15 Correct 243 ms 13820 KB Output is correct
16 Correct 243 ms 13800 KB Output is correct
17 Correct 158 ms 14120 KB Output is correct
18 Correct 133 ms 13592 KB Output is correct
19 Correct 267 ms 13952 KB Output is correct
20 Correct 253 ms 13904 KB Output is correct
21 Correct 150 ms 14148 KB Output is correct
22 Correct 137 ms 13768 KB Output is correct
23 Correct 253 ms 14012 KB Output is correct
24 Correct 272 ms 14004 KB Output is correct
25 Correct 153 ms 14336 KB Output is correct
26 Correct 156 ms 13932 KB Output is correct
27 Correct 264 ms 14472 KB Output is correct
28 Correct 278 ms 14340 KB Output is correct
29 Correct 154 ms 14528 KB Output is correct
30 Correct 141 ms 14256 KB Output is correct
31 Correct 277 ms 14508 KB Output is correct
32 Correct 276 ms 14596 KB Output is correct
33 Correct 165 ms 14692 KB Output is correct
34 Correct 148 ms 14272 KB Output is correct
35 Incorrect 279 ms 14012 KB Wrong Answer [2]
36 Halted 0 ms 0 KB -