Submission #623072

# Submission time Handle Problem Language Result Execution time Memory
623072 2022-08-05T07:03:09 Z AlperenT Minerals (JOI19_minerals) C++17
75 / 100
43 ms 12128 KB
#include <bits/stdc++.h>
#include "minerals.h"

using namespace std;

const int N = 50000 + 5;

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

vector<int> a, b;

int query(int 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--;
                }
            }

            if(l + 1 == r){
                if(flag){
                    int prvcnt = cnt;

                    query(tree[v][0]);

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

                    query(tree[v][0]);

                    if(cnt == prvcnt + 1) tree[v * 2 + 1].push_back(tree[v][0]), tree[v * 2].push_back(tree[v][1]);
                    else tree[v * 2].push_back(tree[v][0]), tree[v * 2 + 1].push_back(tree[v][1]);
                }
            }
            else{
                if(flag){
                    for(auto x : tree[v]){
                        int prvcnt = cnt;

                        query(x);

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

                        query(x);

                        if(cnt == prvcnt + 1) tree[v * 2 + 1].push_back(x);
                        else tree[v * 2].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{
            query(i);
            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]);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5072 KB Output is correct
2 Correct 5 ms 5200 KB Output is correct
3 Correct 5 ms 5456 KB Output is correct
4 Correct 8 ms 6096 KB Output is correct
5 Correct 16 ms 7248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 5 ms 5200 KB Output is correct
7 Correct 5 ms 5456 KB Output is correct
8 Correct 8 ms 6096 KB Output is correct
9 Correct 16 ms 7248 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 10 ms 6608 KB Output is correct
12 Correct 14 ms 7240 KB Output is correct
13 Correct 12 ms 7288 KB Output is correct
14 Correct 12 ms 7256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 5 ms 5200 KB Output is correct
7 Correct 5 ms 5456 KB Output is correct
8 Correct 8 ms 6096 KB Output is correct
9 Correct 16 ms 7248 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 10 ms 6608 KB Output is correct
12 Correct 14 ms 7240 KB Output is correct
13 Correct 12 ms 7288 KB Output is correct
14 Correct 12 ms 7256 KB Output is correct
15 Correct 38 ms 11908 KB Output is correct
16 Correct 38 ms 11940 KB Output is correct
17 Correct 34 ms 11872 KB Output is correct
18 Correct 34 ms 11756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 5 ms 5200 KB Output is correct
7 Correct 5 ms 5456 KB Output is correct
8 Correct 8 ms 6096 KB Output is correct
9 Correct 16 ms 7248 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 10 ms 6608 KB Output is correct
12 Correct 14 ms 7240 KB Output is correct
13 Correct 12 ms 7288 KB Output is correct
14 Correct 12 ms 7256 KB Output is correct
15 Correct 38 ms 11908 KB Output is correct
16 Correct 38 ms 11940 KB Output is correct
17 Correct 34 ms 11872 KB Output is correct
18 Correct 34 ms 11756 KB Output is correct
19 Correct 43 ms 12020 KB Output is correct
20 Correct 34 ms 12128 KB Output is correct
21 Correct 30 ms 11980 KB Output is correct
22 Correct 36 ms 11852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 5 ms 5200 KB Output is correct
7 Correct 5 ms 5456 KB Output is correct
8 Correct 8 ms 6096 KB Output is correct
9 Correct 16 ms 7248 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 10 ms 6608 KB Output is correct
12 Correct 14 ms 7240 KB Output is correct
13 Correct 12 ms 7288 KB Output is correct
14 Correct 12 ms 7256 KB Output is correct
15 Correct 38 ms 11908 KB Output is correct
16 Correct 38 ms 11940 KB Output is correct
17 Correct 34 ms 11872 KB Output is correct
18 Correct 34 ms 11756 KB Output is correct
19 Correct 43 ms 12020 KB Output is correct
20 Correct 34 ms 12128 KB Output is correct
21 Correct 30 ms 11980 KB Output is correct
22 Correct 36 ms 11852 KB Output is correct
23 Incorrect 42 ms 11712 KB Wrong Answer [2]
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 5 ms 5200 KB Output is correct
7 Correct 5 ms 5456 KB Output is correct
8 Correct 8 ms 6096 KB Output is correct
9 Correct 16 ms 7248 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 10 ms 6608 KB Output is correct
12 Correct 14 ms 7240 KB Output is correct
13 Correct 12 ms 7288 KB Output is correct
14 Correct 12 ms 7256 KB Output is correct
15 Correct 38 ms 11908 KB Output is correct
16 Correct 38 ms 11940 KB Output is correct
17 Correct 34 ms 11872 KB Output is correct
18 Correct 34 ms 11756 KB Output is correct
19 Correct 43 ms 12020 KB Output is correct
20 Correct 34 ms 12128 KB Output is correct
21 Correct 30 ms 11980 KB Output is correct
22 Correct 36 ms 11852 KB Output is correct
23 Incorrect 42 ms 11712 KB Wrong Answer [2]
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 5 ms 5200 KB Output is correct
7 Correct 5 ms 5456 KB Output is correct
8 Correct 8 ms 6096 KB Output is correct
9 Correct 16 ms 7248 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 10 ms 6608 KB Output is correct
12 Correct 14 ms 7240 KB Output is correct
13 Correct 12 ms 7288 KB Output is correct
14 Correct 12 ms 7256 KB Output is correct
15 Correct 38 ms 11908 KB Output is correct
16 Correct 38 ms 11940 KB Output is correct
17 Correct 34 ms 11872 KB Output is correct
18 Correct 34 ms 11756 KB Output is correct
19 Correct 43 ms 12020 KB Output is correct
20 Correct 34 ms 12128 KB Output is correct
21 Correct 30 ms 11980 KB Output is correct
22 Correct 36 ms 11852 KB Output is correct
23 Incorrect 42 ms 11712 KB Wrong Answer [2]
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 5 ms 5200 KB Output is correct
7 Correct 5 ms 5456 KB Output is correct
8 Correct 8 ms 6096 KB Output is correct
9 Correct 16 ms 7248 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 10 ms 6608 KB Output is correct
12 Correct 14 ms 7240 KB Output is correct
13 Correct 12 ms 7288 KB Output is correct
14 Correct 12 ms 7256 KB Output is correct
15 Correct 38 ms 11908 KB Output is correct
16 Correct 38 ms 11940 KB Output is correct
17 Correct 34 ms 11872 KB Output is correct
18 Correct 34 ms 11756 KB Output is correct
19 Correct 43 ms 12020 KB Output is correct
20 Correct 34 ms 12128 KB Output is correct
21 Correct 30 ms 11980 KB Output is correct
22 Correct 36 ms 11852 KB Output is correct
23 Incorrect 42 ms 11712 KB Wrong Answer [2]
24 Halted 0 ms 0 KB -