Submission #997590

# Submission time Handle Problem Language Result Execution time Memory
997590 2024-06-12T14:27:36 Z TimDee Minerals (JOI19_minerals) C++17
80 / 100
172 ms 11244 KB
#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0; i<(n); ++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int query(int x) {
    return Query(x+1);
}
void Solve(int n) {

    vector<int> in(2*n), c(2*n);
    vector<int> f,s;

    int last=0;
    vector<int> p; forn(i,2*n) p.pb(i);
    shuffle(p.begin(),p.end(),rng);
    forn(i,2*n) {
        if (last==n) {
            s.pb(p[i]); continue;
        }
        int z = query(p[i]);
        if (z > last) f.pb(p[i]);
        else s.pb(p[i]); 
        in[p[i]]=1;
        last = z;
    }

    forn(i,n) c[f[i]]=i;

    vector<pi> v(n);
    forn(i,n) v[i]={0,n-1};

    multiset<int> st;
    forn(i,n) st.insert(n/2);

    vector<vector<int>> ok(n);
    forn(i,n) ok[n/2].pb(i);

    set<int> alive;
    forn(i,n) alive.insert(i);

    vector<vector<int>> other(n);

    int dir = -1;
    int pos=n-1;
    int q2=0;
    while (st.size()) {
        ++q2;

        if (dir == 1) {

            for(auto&x:ok[pos]) {
                st.erase(st.find(pos));
                int l=v[x].f, r=v[x].s;
                if (l==r) continue;
                int m=(l+r+1)>>1;
                int q = query(s[x]);
                int z = -1;
                if (r-l==1) {
                    z = l;
                }
                if (in[s[x]]) {
                    if (q < last) {
                        l = m;
                    } else {
                        r = m-1;
                    }
                } else {
                    if (q > last) {
                        l = m;
                    } else {
                        r = m-1;
                    }
                }
                in[s[x]]^=1;
                last = q;
                v[x] = {l,r};
                m = (l+r+1)>>1;
                if (z!=-1) {
                    int a=other[z][0],b=other[z][1];
                    if (x==a) {
                        if (r==z) v[b]={z+1,z+1};
                        else v[b]={z,z};
                    } else {
                        if (r==z) v[a]={z+1,z+1};
                        else v[a]={z,z};
                    }
                    alive.erase(z);
                    alive.erase(z+1);
                }
                if (l!=r) {
                    ok[m].pb(x);
                    st.insert(m);
                }
                if (r-l==1) {
                    other[l].pb(x);
                }
            }
            ok[pos].clear();

            auto it = st.lower_bound(pos);
            if (it==st.end()) {
                dir*=-1;
                continue;
            }

            last = query(f[pos]);
            auto it2 = alive.upper_bound(pos);
            pos = *it2;

        } else {

            auto it3 = st.upper_bound(pos);
            if (it3!=st.end()) {
                auto it2 = alive.upper_bound(pos);
                pos = *it2;
                dir *= -1; continue;
            }

            last = query(f[pos]);

            for(auto&x:ok[pos]) {
                st.erase(st.find(pos));
                int l=v[x].f, r=v[x].s;
                if (l==r) continue;
                int m=(l+r+1)>>1;
                int q = query(s[x]);
                int z = -1;
                if (r-l==1) {
                    z = l;
                }
                if (in[s[x]]) {
                    if (q < last) {
                        l = m;
                    } else {
                        r = m-1;
                    }
                } else {
                    if (q > last) {
                        l = m;
                    } else {
                        r = m-1;
                    }
                }
                in[s[x]]^=1;
                last = q;
                v[x] = {l,r};
                m = (l+r+1)>>1;
                if (z!=-1) {
                    int a=other[z][0],b=other[z][1];
                    if (x==a) {
                        if (r==z) v[b]={z+1,z+1};
                        else v[b]={z,z};
                    } else {
                        if (r==z) v[a]={z+1,z+1};
                        else v[a]={z,z};
                    }
                    alive.erase(z);
                    alive.erase(z+1);
                }
                if (l!=r) {
                    ok[m].pb(x);
                    st.insert(m);
                }
                if (r-l==1) {
                    other[l].pb(x);
                }
            }
            ok[pos].clear();

            auto it = st.lower_bound(pos);
            if (it == st.begin()) {
                dir *= -1;
                continue;
            }

            auto it2 = alive.lower_bound(pos);
            --it2;
            pos = *it2;
        }
    }
    //cout<<"? "<<q2<<"  ";

    forn(i,n) Answer(s[i]+1,f[v[i].f]+1);

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 5 ms 856 KB Output is correct
3 Correct 12 ms 1240 KB Output is correct
4 Correct 23 ms 2136 KB Output is correct
5 Correct 50 ms 3880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 5 ms 856 KB Output is correct
7 Correct 12 ms 1240 KB Output is correct
8 Correct 23 ms 2136 KB Output is correct
9 Correct 50 ms 3880 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 33 ms 2904 KB Output is correct
12 Correct 50 ms 3916 KB Output is correct
13 Correct 62 ms 3864 KB Output is correct
14 Correct 54 ms 4008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 5 ms 856 KB Output is correct
7 Correct 12 ms 1240 KB Output is correct
8 Correct 23 ms 2136 KB Output is correct
9 Correct 50 ms 3880 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 33 ms 2904 KB Output is correct
12 Correct 50 ms 3916 KB Output is correct
13 Correct 62 ms 3864 KB Output is correct
14 Correct 54 ms 4008 KB Output is correct
15 Correct 154 ms 10752 KB Output is correct
16 Correct 153 ms 10692 KB Output is correct
17 Correct 151 ms 10584 KB Output is correct
18 Correct 162 ms 10564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 5 ms 856 KB Output is correct
7 Correct 12 ms 1240 KB Output is correct
8 Correct 23 ms 2136 KB Output is correct
9 Correct 50 ms 3880 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 33 ms 2904 KB Output is correct
12 Correct 50 ms 3916 KB Output is correct
13 Correct 62 ms 3864 KB Output is correct
14 Correct 54 ms 4008 KB Output is correct
15 Correct 154 ms 10752 KB Output is correct
16 Correct 153 ms 10692 KB Output is correct
17 Correct 151 ms 10584 KB Output is correct
18 Correct 162 ms 10564 KB Output is correct
19 Correct 158 ms 10768 KB Output is correct
20 Correct 158 ms 10948 KB Output is correct
21 Correct 161 ms 10928 KB Output is correct
22 Correct 155 ms 10696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 5 ms 856 KB Output is correct
7 Correct 12 ms 1240 KB Output is correct
8 Correct 23 ms 2136 KB Output is correct
9 Correct 50 ms 3880 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 33 ms 2904 KB Output is correct
12 Correct 50 ms 3916 KB Output is correct
13 Correct 62 ms 3864 KB Output is correct
14 Correct 54 ms 4008 KB Output is correct
15 Correct 154 ms 10752 KB Output is correct
16 Correct 153 ms 10692 KB Output is correct
17 Correct 151 ms 10584 KB Output is correct
18 Correct 162 ms 10564 KB Output is correct
19 Correct 158 ms 10768 KB Output is correct
20 Correct 158 ms 10948 KB Output is correct
21 Correct 161 ms 10928 KB Output is correct
22 Correct 155 ms 10696 KB Output is correct
23 Correct 167 ms 11208 KB Output is correct
24 Correct 172 ms 11244 KB Output is correct
25 Correct 162 ms 11156 KB Output is correct
26 Correct 165 ms 11056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 5 ms 856 KB Output is correct
7 Correct 12 ms 1240 KB Output is correct
8 Correct 23 ms 2136 KB Output is correct
9 Correct 50 ms 3880 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 33 ms 2904 KB Output is correct
12 Correct 50 ms 3916 KB Output is correct
13 Correct 62 ms 3864 KB Output is correct
14 Correct 54 ms 4008 KB Output is correct
15 Correct 154 ms 10752 KB Output is correct
16 Correct 153 ms 10692 KB Output is correct
17 Correct 151 ms 10584 KB Output is correct
18 Correct 162 ms 10564 KB Output is correct
19 Correct 158 ms 10768 KB Output is correct
20 Correct 158 ms 10948 KB Output is correct
21 Correct 161 ms 10928 KB Output is correct
22 Correct 155 ms 10696 KB Output is correct
23 Correct 167 ms 11208 KB Output is correct
24 Correct 172 ms 11244 KB Output is correct
25 Correct 162 ms 11156 KB Output is correct
26 Correct 165 ms 11056 KB Output is correct
27 Incorrect 167 ms 11120 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 5 ms 856 KB Output is correct
7 Correct 12 ms 1240 KB Output is correct
8 Correct 23 ms 2136 KB Output is correct
9 Correct 50 ms 3880 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 33 ms 2904 KB Output is correct
12 Correct 50 ms 3916 KB Output is correct
13 Correct 62 ms 3864 KB Output is correct
14 Correct 54 ms 4008 KB Output is correct
15 Correct 154 ms 10752 KB Output is correct
16 Correct 153 ms 10692 KB Output is correct
17 Correct 151 ms 10584 KB Output is correct
18 Correct 162 ms 10564 KB Output is correct
19 Correct 158 ms 10768 KB Output is correct
20 Correct 158 ms 10948 KB Output is correct
21 Correct 161 ms 10928 KB Output is correct
22 Correct 155 ms 10696 KB Output is correct
23 Correct 167 ms 11208 KB Output is correct
24 Correct 172 ms 11244 KB Output is correct
25 Correct 162 ms 11156 KB Output is correct
26 Correct 165 ms 11056 KB Output is correct
27 Incorrect 167 ms 11120 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 5 ms 856 KB Output is correct
7 Correct 12 ms 1240 KB Output is correct
8 Correct 23 ms 2136 KB Output is correct
9 Correct 50 ms 3880 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 33 ms 2904 KB Output is correct
12 Correct 50 ms 3916 KB Output is correct
13 Correct 62 ms 3864 KB Output is correct
14 Correct 54 ms 4008 KB Output is correct
15 Correct 154 ms 10752 KB Output is correct
16 Correct 153 ms 10692 KB Output is correct
17 Correct 151 ms 10584 KB Output is correct
18 Correct 162 ms 10564 KB Output is correct
19 Correct 158 ms 10768 KB Output is correct
20 Correct 158 ms 10948 KB Output is correct
21 Correct 161 ms 10928 KB Output is correct
22 Correct 155 ms 10696 KB Output is correct
23 Correct 167 ms 11208 KB Output is correct
24 Correct 172 ms 11244 KB Output is correct
25 Correct 162 ms 11156 KB Output is correct
26 Correct 165 ms 11056 KB Output is correct
27 Incorrect 167 ms 11120 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -