답안 #637392

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637392 2022-09-01T15:43:55 Z AlperenT Minerals (JOI19_minerals) C++17
100 / 100
389 ms 6444 KB
#include <bits/stdc++.h>
#include "minerals.h"

using namespace std;

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

int cnt;

set<int> minerals;

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

    return cnt = Query(x);
}

struct Item{
    int x, i;
};

void solve(int l, int r, vector<int> &a, vector<Item> b, bool flag){
    if(l > r) return;
    else if(l == r) Answer(a[l], b[0].x);
    else{
        int m = r - (r - l) * 0.375;

        vector<Item> lft, rght;

        for(int i = m + 1; i <= r; i++) query(a[i]);

        for(auto p : b){
            if(p.i <= m) lft.push_back(p);
            else if(lft.size() == m - l + 1) rght.push_back(p);
            else if(rght.size() == r - m) lft.push_back(p);
            else if(minerals.find(p.x) == minerals.end()){
                int prvcnt = cnt;

                query(p.x);

                if(flag){
                    if(cnt == prvcnt + 1) rght.push_back(p);
                    else lft.push_back(p);
                }
                else{
                    if(cnt == prvcnt + 1) lft.push_back(p);
                    else rght.push_back(p);
                }
            }
            else{
                int prvcnt = cnt;

                query(p.x);

                if(flag){
                    if(cnt == prvcnt - 1) rght.push_back(p);
                    else lft.push_back(p);
                }
                else{
                    if(cnt == prvcnt - 1) lft.push_back(p);
                    else rght.push_back(p);
                }
            }
        }

        solve(l, m, a, lft, flag);
        solve(m + 1, r, a, rght, !flag);
    }
}

void Solve(int n) {
    vector<int> nums, a, c1, c2, indxs;
    vector<Item> tmp, b;

    nums.assign(n * 2, 0);
    iota(nums.begin(), nums.end(), 1);

    shuffle(nums.begin(), nums.end(), rng);

    for(int i = 0; i < n; i++){
        int prvcnt = cnt;

        query(nums[i]);

        if(cnt == prvcnt + 1) tmp.push_back({nums[i], i});
        else b.push_back({nums[i], i});
    }

    for(auto p : tmp){
        int prvcnt = cnt;

        query(p.x);

        if(cnt == prvcnt - 1) c1.push_back(p.x);
        else{
            a.push_back(p.x);
            indxs.push_back(p.i);
        }
    }

    for(auto &p : b) p.i = upper_bound(indxs.begin(), indxs.end(), p.i) - indxs.begin() - 1;

    solve(0, (int)a.size() - 1, a, b, false);

    a.clear(), b.clear(), tmp.clear(), indxs.clear();

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

        query(nums[i]);

        if(cnt == prvcnt + 1) tmp.push_back({nums[i], i});
        else b.push_back({nums[i], i});
    }

    for(auto p : tmp){
        int prvcnt = cnt;

        query(p.x);

        if(cnt == prvcnt - 1) c2.push_back(p.x);
        else{
            a.push_back(p.x);
            indxs.push_back(p.i);
        }
    }

    for(auto &p : b) p.i = upper_bound(indxs.begin(), indxs.end(), p.i) - indxs.begin() - 1;

    solve(0, (int)a.size() - 1, a, b, false);

    a = c1;

    b.clear();

    for(auto x : c2) b.push_back({x, (int)a.size()});

    solve(0, (int)a.size() - 1, a, b, false);
}

Compilation message

minerals.cpp: In function 'void solve(int, int, std::vector<int>&, std::vector<Item>, bool)':
minerals.cpp:35:32: warning: comparison of integer expressions of different signedness: 'std::vector<Item>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |             else if(lft.size() == m - l + 1) rght.push_back(p);
      |                     ~~~~~~~~~~~^~~~~~~~~~~~
minerals.cpp:36:33: warning: comparison of integer expressions of different signedness: 'std::vector<Item>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |             else if(rght.size() == r - m) lft.push_back(p);
      |                     ~~~~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 464 KB Output is correct
2 Correct 9 ms 592 KB Output is correct
3 Correct 18 ms 848 KB Output is correct
4 Correct 44 ms 1408 KB Output is correct
5 Correct 94 ms 2380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 4 ms 464 KB Output is correct
6 Correct 9 ms 592 KB Output is correct
7 Correct 18 ms 848 KB Output is correct
8 Correct 44 ms 1408 KB Output is correct
9 Correct 94 ms 2380 KB Output is correct
10 Correct 4 ms 464 KB Output is correct
11 Correct 57 ms 1704 KB Output is correct
12 Correct 100 ms 2432 KB Output is correct
13 Correct 101 ms 2460 KB Output is correct
14 Correct 118 ms 2368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 4 ms 464 KB Output is correct
6 Correct 9 ms 592 KB Output is correct
7 Correct 18 ms 848 KB Output is correct
8 Correct 44 ms 1408 KB Output is correct
9 Correct 94 ms 2380 KB Output is correct
10 Correct 4 ms 464 KB Output is correct
11 Correct 57 ms 1704 KB Output is correct
12 Correct 100 ms 2432 KB Output is correct
13 Correct 101 ms 2460 KB Output is correct
14 Correct 118 ms 2368 KB Output is correct
15 Correct 330 ms 5648 KB Output is correct
16 Correct 309 ms 5760 KB Output is correct
17 Correct 313 ms 5624 KB Output is correct
18 Correct 300 ms 5472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 4 ms 464 KB Output is correct
6 Correct 9 ms 592 KB Output is correct
7 Correct 18 ms 848 KB Output is correct
8 Correct 44 ms 1408 KB Output is correct
9 Correct 94 ms 2380 KB Output is correct
10 Correct 4 ms 464 KB Output is correct
11 Correct 57 ms 1704 KB Output is correct
12 Correct 100 ms 2432 KB Output is correct
13 Correct 101 ms 2460 KB Output is correct
14 Correct 118 ms 2368 KB Output is correct
15 Correct 330 ms 5648 KB Output is correct
16 Correct 309 ms 5760 KB Output is correct
17 Correct 313 ms 5624 KB Output is correct
18 Correct 300 ms 5472 KB Output is correct
19 Correct 324 ms 5756 KB Output is correct
20 Correct 320 ms 5896 KB Output is correct
21 Correct 324 ms 5788 KB Output is correct
22 Correct 331 ms 5592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 4 ms 464 KB Output is correct
6 Correct 9 ms 592 KB Output is correct
7 Correct 18 ms 848 KB Output is correct
8 Correct 44 ms 1408 KB Output is correct
9 Correct 94 ms 2380 KB Output is correct
10 Correct 4 ms 464 KB Output is correct
11 Correct 57 ms 1704 KB Output is correct
12 Correct 100 ms 2432 KB Output is correct
13 Correct 101 ms 2460 KB Output is correct
14 Correct 118 ms 2368 KB Output is correct
15 Correct 330 ms 5648 KB Output is correct
16 Correct 309 ms 5760 KB Output is correct
17 Correct 313 ms 5624 KB Output is correct
18 Correct 300 ms 5472 KB Output is correct
19 Correct 324 ms 5756 KB Output is correct
20 Correct 320 ms 5896 KB Output is correct
21 Correct 324 ms 5788 KB Output is correct
22 Correct 331 ms 5592 KB Output is correct
23 Correct 340 ms 6100 KB Output is correct
24 Correct 317 ms 5868 KB Output is correct
25 Correct 326 ms 5912 KB Output is correct
26 Correct 328 ms 5796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 4 ms 464 KB Output is correct
6 Correct 9 ms 592 KB Output is correct
7 Correct 18 ms 848 KB Output is correct
8 Correct 44 ms 1408 KB Output is correct
9 Correct 94 ms 2380 KB Output is correct
10 Correct 4 ms 464 KB Output is correct
11 Correct 57 ms 1704 KB Output is correct
12 Correct 100 ms 2432 KB Output is correct
13 Correct 101 ms 2460 KB Output is correct
14 Correct 118 ms 2368 KB Output is correct
15 Correct 330 ms 5648 KB Output is correct
16 Correct 309 ms 5760 KB Output is correct
17 Correct 313 ms 5624 KB Output is correct
18 Correct 300 ms 5472 KB Output is correct
19 Correct 324 ms 5756 KB Output is correct
20 Correct 320 ms 5896 KB Output is correct
21 Correct 324 ms 5788 KB Output is correct
22 Correct 331 ms 5592 KB Output is correct
23 Correct 340 ms 6100 KB Output is correct
24 Correct 317 ms 5868 KB Output is correct
25 Correct 326 ms 5912 KB Output is correct
26 Correct 328 ms 5796 KB Output is correct
27 Correct 379 ms 6168 KB Output is correct
28 Correct 340 ms 6136 KB Output is correct
29 Correct 333 ms 6152 KB Output is correct
30 Correct 376 ms 5960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 4 ms 464 KB Output is correct
6 Correct 9 ms 592 KB Output is correct
7 Correct 18 ms 848 KB Output is correct
8 Correct 44 ms 1408 KB Output is correct
9 Correct 94 ms 2380 KB Output is correct
10 Correct 4 ms 464 KB Output is correct
11 Correct 57 ms 1704 KB Output is correct
12 Correct 100 ms 2432 KB Output is correct
13 Correct 101 ms 2460 KB Output is correct
14 Correct 118 ms 2368 KB Output is correct
15 Correct 330 ms 5648 KB Output is correct
16 Correct 309 ms 5760 KB Output is correct
17 Correct 313 ms 5624 KB Output is correct
18 Correct 300 ms 5472 KB Output is correct
19 Correct 324 ms 5756 KB Output is correct
20 Correct 320 ms 5896 KB Output is correct
21 Correct 324 ms 5788 KB Output is correct
22 Correct 331 ms 5592 KB Output is correct
23 Correct 340 ms 6100 KB Output is correct
24 Correct 317 ms 5868 KB Output is correct
25 Correct 326 ms 5912 KB Output is correct
26 Correct 328 ms 5796 KB Output is correct
27 Correct 379 ms 6168 KB Output is correct
28 Correct 340 ms 6136 KB Output is correct
29 Correct 333 ms 6152 KB Output is correct
30 Correct 376 ms 5960 KB Output is correct
31 Correct 359 ms 6444 KB Output is correct
32 Correct 339 ms 6244 KB Output is correct
33 Correct 382 ms 6224 KB Output is correct
34 Correct 373 ms 6028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 4 ms 464 KB Output is correct
6 Correct 9 ms 592 KB Output is correct
7 Correct 18 ms 848 KB Output is correct
8 Correct 44 ms 1408 KB Output is correct
9 Correct 94 ms 2380 KB Output is correct
10 Correct 4 ms 464 KB Output is correct
11 Correct 57 ms 1704 KB Output is correct
12 Correct 100 ms 2432 KB Output is correct
13 Correct 101 ms 2460 KB Output is correct
14 Correct 118 ms 2368 KB Output is correct
15 Correct 330 ms 5648 KB Output is correct
16 Correct 309 ms 5760 KB Output is correct
17 Correct 313 ms 5624 KB Output is correct
18 Correct 300 ms 5472 KB Output is correct
19 Correct 324 ms 5756 KB Output is correct
20 Correct 320 ms 5896 KB Output is correct
21 Correct 324 ms 5788 KB Output is correct
22 Correct 331 ms 5592 KB Output is correct
23 Correct 340 ms 6100 KB Output is correct
24 Correct 317 ms 5868 KB Output is correct
25 Correct 326 ms 5912 KB Output is correct
26 Correct 328 ms 5796 KB Output is correct
27 Correct 379 ms 6168 KB Output is correct
28 Correct 340 ms 6136 KB Output is correct
29 Correct 333 ms 6152 KB Output is correct
30 Correct 376 ms 5960 KB Output is correct
31 Correct 359 ms 6444 KB Output is correct
32 Correct 339 ms 6244 KB Output is correct
33 Correct 382 ms 6224 KB Output is correct
34 Correct 373 ms 6028 KB Output is correct
35 Correct 371 ms 6428 KB Output is correct
36 Correct 371 ms 6328 KB Output is correct
37 Correct 389 ms 6332 KB Output is correct
38 Correct 362 ms 6192 KB Output is correct