Submission #710721

# Submission time Handle Problem Language Result Execution time Memory
710721 2023-03-15T17:06:31 Z victor_gao Minerals (JOI19_minerals) C++17
100 / 100
59 ms 3064 KB
#include"minerals.h"
#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int>arr;
bool alive[100015],vis[100015];
int n;
void Merge(int l,int r,vector<int>have,bool stay1){
    //cerr<<l<<" "<<r<<" "<<stay1<<'\n';
    if (l==r){
        Answer(arr[l-1],have[0]);
        return;
    }
    int mid=l+(r-l+1)*0.37,last;
    vector<int>L,R;
    if (!stay1){
        for (int i=l-1;i<mid;i++){
            last=Query(arr[i]);
            alive[arr[i]]^=1;
        }
    }
    else {
        mid=r-(mid-l);
        if (mid==r) mid--;
        for (int i=mid;i<r;i++){
            last=Query(arr[i]);
            alive[arr[i]]^=1;
        }
    }
    for (auto i:have){
        if (L.size()==(mid-l+1)){
            R.push_back(i);
            continue;
        }
        if (R.size()==(r-mid)){
            L.push_back(i);
            continue;
        }
        int now=Query(i);
        alive[i]^=1;
        bool ty=(now==last);
        if (ty)
            L.push_back(i);
        else R.push_back(i);
        last=now;
    }
    Merge(mid+1,r,R,0);
    Merge(l,mid,L,1);
}
void Solve(int N){
    n=N;
    vector<int>qry;
    int last=-1;
    for (int i=1;i<=2*N;i++){
        if (arr.size()==N){
            qry.push_back(i);
            continue;
        }
        int now=Query(i);
        alive[i]^=1;
        if (now==last)
            qry.push_back(i);
        else {
            arr.push_back(i);
            last=now;
        }
    }
    shuffle(arr.begin(),arr.end(),rng);
    shuffle(qry.begin(),qry.end(),rng);
    Merge(1,N,qry,1);
}
/*
g++ -std=gnu++14 -O2 -o grader grader.cpp minerals.cpp
./grader.exe
./rand.exe

4
1 5
2 6
3 4
7 8
*/

Compilation message

minerals.cpp: In function 'void Merge(int, int, std::vector<int>, bool)':
minerals.cpp:31:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |         if (L.size()==(mid-l+1)){
      |             ~~~~~~~~^~~~~~~~~~~
minerals.cpp:35:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |         if (R.size()==(r-mid)){
      |             ~~~~~~~~^~~~~~~~~
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:55:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   55 |         if (arr.size()==N){
      |             ~~~~~~~~~~^~~
minerals.cpp: In function 'void Merge(int, int, std::vector<int>, bool)':
minerals.cpp:42:9: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |         if (ty)
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 4 ms 464 KB Output is correct
4 Correct 9 ms 820 KB Output is correct
5 Correct 15 ms 1232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 4 ms 464 KB Output is correct
8 Correct 9 ms 820 KB Output is correct
9 Correct 15 ms 1232 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 11 ms 948 KB Output is correct
12 Correct 16 ms 1320 KB Output is correct
13 Correct 16 ms 1276 KB Output is correct
14 Correct 13 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 4 ms 464 KB Output is correct
8 Correct 9 ms 820 KB Output is correct
9 Correct 15 ms 1232 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 11 ms 948 KB Output is correct
12 Correct 16 ms 1320 KB Output is correct
13 Correct 16 ms 1276 KB Output is correct
14 Correct 13 ms 1236 KB Output is correct
15 Correct 45 ms 2768 KB Output is correct
16 Correct 44 ms 2684 KB Output is correct
17 Correct 36 ms 2676 KB Output is correct
18 Correct 36 ms 2524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 4 ms 464 KB Output is correct
8 Correct 9 ms 820 KB Output is correct
9 Correct 15 ms 1232 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 11 ms 948 KB Output is correct
12 Correct 16 ms 1320 KB Output is correct
13 Correct 16 ms 1276 KB Output is correct
14 Correct 13 ms 1236 KB Output is correct
15 Correct 45 ms 2768 KB Output is correct
16 Correct 44 ms 2684 KB Output is correct
17 Correct 36 ms 2676 KB Output is correct
18 Correct 36 ms 2524 KB Output is correct
19 Correct 43 ms 2784 KB Output is correct
20 Correct 39 ms 2732 KB Output is correct
21 Correct 40 ms 2728 KB Output is correct
22 Correct 59 ms 2676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 4 ms 464 KB Output is correct
8 Correct 9 ms 820 KB Output is correct
9 Correct 15 ms 1232 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 11 ms 948 KB Output is correct
12 Correct 16 ms 1320 KB Output is correct
13 Correct 16 ms 1276 KB Output is correct
14 Correct 13 ms 1236 KB Output is correct
15 Correct 45 ms 2768 KB Output is correct
16 Correct 44 ms 2684 KB Output is correct
17 Correct 36 ms 2676 KB Output is correct
18 Correct 36 ms 2524 KB Output is correct
19 Correct 43 ms 2784 KB Output is correct
20 Correct 39 ms 2732 KB Output is correct
21 Correct 40 ms 2728 KB Output is correct
22 Correct 59 ms 2676 KB Output is correct
23 Correct 40 ms 2792 KB Output is correct
24 Correct 40 ms 2900 KB Output is correct
25 Correct 45 ms 2828 KB Output is correct
26 Correct 42 ms 2752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 4 ms 464 KB Output is correct
8 Correct 9 ms 820 KB Output is correct
9 Correct 15 ms 1232 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 11 ms 948 KB Output is correct
12 Correct 16 ms 1320 KB Output is correct
13 Correct 16 ms 1276 KB Output is correct
14 Correct 13 ms 1236 KB Output is correct
15 Correct 45 ms 2768 KB Output is correct
16 Correct 44 ms 2684 KB Output is correct
17 Correct 36 ms 2676 KB Output is correct
18 Correct 36 ms 2524 KB Output is correct
19 Correct 43 ms 2784 KB Output is correct
20 Correct 39 ms 2732 KB Output is correct
21 Correct 40 ms 2728 KB Output is correct
22 Correct 59 ms 2676 KB Output is correct
23 Correct 40 ms 2792 KB Output is correct
24 Correct 40 ms 2900 KB Output is correct
25 Correct 45 ms 2828 KB Output is correct
26 Correct 42 ms 2752 KB Output is correct
27 Correct 56 ms 2968 KB Output is correct
28 Correct 45 ms 2892 KB Output is correct
29 Correct 41 ms 2928 KB Output is correct
30 Correct 40 ms 2768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 4 ms 464 KB Output is correct
8 Correct 9 ms 820 KB Output is correct
9 Correct 15 ms 1232 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 11 ms 948 KB Output is correct
12 Correct 16 ms 1320 KB Output is correct
13 Correct 16 ms 1276 KB Output is correct
14 Correct 13 ms 1236 KB Output is correct
15 Correct 45 ms 2768 KB Output is correct
16 Correct 44 ms 2684 KB Output is correct
17 Correct 36 ms 2676 KB Output is correct
18 Correct 36 ms 2524 KB Output is correct
19 Correct 43 ms 2784 KB Output is correct
20 Correct 39 ms 2732 KB Output is correct
21 Correct 40 ms 2728 KB Output is correct
22 Correct 59 ms 2676 KB Output is correct
23 Correct 40 ms 2792 KB Output is correct
24 Correct 40 ms 2900 KB Output is correct
25 Correct 45 ms 2828 KB Output is correct
26 Correct 42 ms 2752 KB Output is correct
27 Correct 56 ms 2968 KB Output is correct
28 Correct 45 ms 2892 KB Output is correct
29 Correct 41 ms 2928 KB Output is correct
30 Correct 40 ms 2768 KB Output is correct
31 Correct 49 ms 3064 KB Output is correct
32 Correct 53 ms 2928 KB Output is correct
33 Correct 46 ms 2960 KB Output is correct
34 Correct 46 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 4 ms 464 KB Output is correct
8 Correct 9 ms 820 KB Output is correct
9 Correct 15 ms 1232 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 11 ms 948 KB Output is correct
12 Correct 16 ms 1320 KB Output is correct
13 Correct 16 ms 1276 KB Output is correct
14 Correct 13 ms 1236 KB Output is correct
15 Correct 45 ms 2768 KB Output is correct
16 Correct 44 ms 2684 KB Output is correct
17 Correct 36 ms 2676 KB Output is correct
18 Correct 36 ms 2524 KB Output is correct
19 Correct 43 ms 2784 KB Output is correct
20 Correct 39 ms 2732 KB Output is correct
21 Correct 40 ms 2728 KB Output is correct
22 Correct 59 ms 2676 KB Output is correct
23 Correct 40 ms 2792 KB Output is correct
24 Correct 40 ms 2900 KB Output is correct
25 Correct 45 ms 2828 KB Output is correct
26 Correct 42 ms 2752 KB Output is correct
27 Correct 56 ms 2968 KB Output is correct
28 Correct 45 ms 2892 KB Output is correct
29 Correct 41 ms 2928 KB Output is correct
30 Correct 40 ms 2768 KB Output is correct
31 Correct 49 ms 3064 KB Output is correct
32 Correct 53 ms 2928 KB Output is correct
33 Correct 46 ms 2960 KB Output is correct
34 Correct 46 ms 2796 KB Output is correct
35 Correct 45 ms 2996 KB Output is correct
36 Correct 43 ms 3032 KB Output is correct
37 Correct 44 ms 3008 KB Output is correct
38 Correct 53 ms 2868 KB Output is correct