Submission #997642

# Submission time Handle Problem Language Result Execution time Memory
997642 2024-06-12T15:48:05 Z TimDee Minerals (JOI19_minerals) C++17
90 / 100
161 ms 9936 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, q3=0;
    while (st.size()) {
        ++q2;
        //cout<<pos<<' '<<dir<<'\n';
        //for(auto&x:st) cout<<x<<' '; cout<<'\n';
        //for(auto&x:alive) cout<<x<<' '; cout<<'\n';
        //cout<<'\n';
        //cout.flush();

        if (dir == 1) {

            vector<int> lq,rq;
            for(auto&x:ok[pos]) {
                st.erase(st.find(pos));
                int l=v[x].f, r=v[x].s;
                //cout<<"? "<<pos<<' '<<x<<' '<<l<<' '<<r<<'\n';
                int m=(l+r+1)>>1;
                if (lq.size() == m-l) {
                    rq.pb(x); continue;
                }
                if (rq.size() == r-m+1) {
                    lq.pb(x); continue;
                }
                int q = query(s[x]); q3++;
                if (q != last) {
                    rq.pb(x);
                } else {
                    lq.pb(x);
                }
                in[s[x]]^=1;
                last = q;
            }
            ok[pos].clear();
            for(auto&x:lq) {
                int l=v[x].f, r=v[x].s;
                int m=(l+r+1)>>1;
                r=m-1;
                m = (l+r+1)>>1;
                v[x] = {l,r};
                if (l==r) {
                    alive.erase(l);
                } else {
                    st.insert(m);
                    ok[m].pb(x);
                }
            }
            for(auto&x:rq) {
                int l=v[x].f, r=v[x].s;
                int m=(l+r+1)>>1;
                l=m;
                m = (l+r+1)>>1;
                v[x] = {l,r};
                if (l==r) {
                    alive.erase(l);
                } else {
                    st.insert(m);
                    ok[m].pb(x);
                }
            }

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

            if (alive.count(pos)) last = query(f[pos]);
            ++pos;

        } else {

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

            if (alive.count(pos)) last = query(f[pos]);

            vector<int> lq,rq;
            for(auto&x:ok[pos]) {
                st.erase(st.find(pos));
                int l=v[x].f, r=v[x].s;
                //cout<<"? "<<pos<<' '<<x<<' '<<l<<' '<<r<<'\n';
                int m=(l+r+1)>>1;
                if (lq.size() == m-l) {
                    rq.pb(x); continue;
                }
                if (rq.size() == r-m+1) {
                    lq.pb(x); continue;
                }
                int q = query(s[x]); q3++;
                if (q != last) {
                    l = m;
                    rq.pb(x);
                } else {
                    r = m-1;
                    lq.pb(x);
                }
                in[s[x]]^=1;
                last = q;
            }
            ok[pos].clear();
            for(auto&x:lq) {
                int l=v[x].f, r=v[x].s;
                int m=(l+r+1)>>1;
                r=m-1;
                m = (l+r+1)>>1;
                v[x] = {l,r};
                if (l==r) {
                    alive.erase(l);
                } else {
                    st.insert(m);
                    ok[m].pb(x);
                }
            }
            for(auto&x:rq) {
                int l=v[x].f, r=v[x].s;
                int m=(l+r+1)>>1;
                l=m;
                m = (l+r+1)>>1;
                v[x] = {l,r};
                if (l==r) {
                    alive.erase(l);
                } else {
                    st.insert(m);
                    ok[m].pb(x);
                }
            }

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

            --pos;
        }
    }
    //cout<<"? "<<q2<<' '<<q3<<"  ";

    //forn(i,n) cout<<s[i]+1<<' '<<f[v[i].f]+1<<'\n';
    forn(i,n) Answer(s[i]+1,f[v[i].f]+1);

}

Compilation message

minerals.cpp: In function 'void Solve(int)':
minerals.cpp:68:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   68 |                 if (lq.size() == m-l) {
      |                     ~~~~~~~~~~^~~~~~
minerals.cpp:71:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   71 |                 if (rq.size() == r-m+1) {
      |                     ~~~~~~~~~~^~~~~~~~
minerals.cpp:137:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  137 |                 if (lq.size() == m-l) {
      |                     ~~~~~~~~~~^~~~~~
minerals.cpp:140:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  140 |                 if (rq.size() == r-m+1) {
      |                     ~~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 4 ms 856 KB Output is correct
3 Correct 9 ms 1304 KB Output is correct
4 Correct 21 ms 2176 KB Output is correct
5 Correct 46 ms 3672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 4 ms 856 KB Output is correct
7 Correct 9 ms 1304 KB Output is correct
8 Correct 21 ms 2176 KB Output is correct
9 Correct 46 ms 3672 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 29 ms 2572 KB Output is correct
12 Correct 45 ms 3672 KB Output is correct
13 Correct 54 ms 3712 KB Output is correct
14 Correct 43 ms 3664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 4 ms 856 KB Output is correct
7 Correct 9 ms 1304 KB Output is correct
8 Correct 21 ms 2176 KB Output is correct
9 Correct 46 ms 3672 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 29 ms 2572 KB Output is correct
12 Correct 45 ms 3672 KB Output is correct
13 Correct 54 ms 3712 KB Output is correct
14 Correct 43 ms 3664 KB Output is correct
15 Correct 141 ms 9340 KB Output is correct
16 Correct 148 ms 9164 KB Output is correct
17 Correct 127 ms 9416 KB Output is correct
18 Correct 135 ms 9160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 4 ms 856 KB Output is correct
7 Correct 9 ms 1304 KB Output is correct
8 Correct 21 ms 2176 KB Output is correct
9 Correct 46 ms 3672 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 29 ms 2572 KB Output is correct
12 Correct 45 ms 3672 KB Output is correct
13 Correct 54 ms 3712 KB Output is correct
14 Correct 43 ms 3664 KB Output is correct
15 Correct 141 ms 9340 KB Output is correct
16 Correct 148 ms 9164 KB Output is correct
17 Correct 127 ms 9416 KB Output is correct
18 Correct 135 ms 9160 KB Output is correct
19 Correct 144 ms 9416 KB Output is correct
20 Correct 145 ms 9572 KB Output is correct
21 Correct 131 ms 9416 KB Output is correct
22 Correct 138 ms 9412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 4 ms 856 KB Output is correct
7 Correct 9 ms 1304 KB Output is correct
8 Correct 21 ms 2176 KB Output is correct
9 Correct 46 ms 3672 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 29 ms 2572 KB Output is correct
12 Correct 45 ms 3672 KB Output is correct
13 Correct 54 ms 3712 KB Output is correct
14 Correct 43 ms 3664 KB Output is correct
15 Correct 141 ms 9340 KB Output is correct
16 Correct 148 ms 9164 KB Output is correct
17 Correct 127 ms 9416 KB Output is correct
18 Correct 135 ms 9160 KB Output is correct
19 Correct 144 ms 9416 KB Output is correct
20 Correct 145 ms 9572 KB Output is correct
21 Correct 131 ms 9416 KB Output is correct
22 Correct 138 ms 9412 KB Output is correct
23 Correct 151 ms 9672 KB Output is correct
24 Correct 151 ms 9756 KB Output is correct
25 Correct 137 ms 9764 KB Output is correct
26 Correct 134 ms 9532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 4 ms 856 KB Output is correct
7 Correct 9 ms 1304 KB Output is correct
8 Correct 21 ms 2176 KB Output is correct
9 Correct 46 ms 3672 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 29 ms 2572 KB Output is correct
12 Correct 45 ms 3672 KB Output is correct
13 Correct 54 ms 3712 KB Output is correct
14 Correct 43 ms 3664 KB Output is correct
15 Correct 141 ms 9340 KB Output is correct
16 Correct 148 ms 9164 KB Output is correct
17 Correct 127 ms 9416 KB Output is correct
18 Correct 135 ms 9160 KB Output is correct
19 Correct 144 ms 9416 KB Output is correct
20 Correct 145 ms 9572 KB Output is correct
21 Correct 131 ms 9416 KB Output is correct
22 Correct 138 ms 9412 KB Output is correct
23 Correct 151 ms 9672 KB Output is correct
24 Correct 151 ms 9756 KB Output is correct
25 Correct 137 ms 9764 KB Output is correct
26 Correct 134 ms 9532 KB Output is correct
27 Correct 146 ms 9928 KB Output is correct
28 Correct 149 ms 9836 KB Output is correct
29 Correct 131 ms 9764 KB Output is correct
30 Correct 136 ms 9672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 4 ms 856 KB Output is correct
7 Correct 9 ms 1304 KB Output is correct
8 Correct 21 ms 2176 KB Output is correct
9 Correct 46 ms 3672 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 29 ms 2572 KB Output is correct
12 Correct 45 ms 3672 KB Output is correct
13 Correct 54 ms 3712 KB Output is correct
14 Correct 43 ms 3664 KB Output is correct
15 Correct 141 ms 9340 KB Output is correct
16 Correct 148 ms 9164 KB Output is correct
17 Correct 127 ms 9416 KB Output is correct
18 Correct 135 ms 9160 KB Output is correct
19 Correct 144 ms 9416 KB Output is correct
20 Correct 145 ms 9572 KB Output is correct
21 Correct 131 ms 9416 KB Output is correct
22 Correct 138 ms 9412 KB Output is correct
23 Correct 151 ms 9672 KB Output is correct
24 Correct 151 ms 9756 KB Output is correct
25 Correct 137 ms 9764 KB Output is correct
26 Correct 134 ms 9532 KB Output is correct
27 Correct 146 ms 9928 KB Output is correct
28 Correct 149 ms 9836 KB Output is correct
29 Correct 131 ms 9764 KB Output is correct
30 Correct 136 ms 9672 KB Output is correct
31 Correct 157 ms 9928 KB Output is correct
32 Correct 161 ms 9928 KB Output is correct
33 Correct 140 ms 9928 KB Output is correct
34 Correct 144 ms 9936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 4 ms 856 KB Output is correct
7 Correct 9 ms 1304 KB Output is correct
8 Correct 21 ms 2176 KB Output is correct
9 Correct 46 ms 3672 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 29 ms 2572 KB Output is correct
12 Correct 45 ms 3672 KB Output is correct
13 Correct 54 ms 3712 KB Output is correct
14 Correct 43 ms 3664 KB Output is correct
15 Correct 141 ms 9340 KB Output is correct
16 Correct 148 ms 9164 KB Output is correct
17 Correct 127 ms 9416 KB Output is correct
18 Correct 135 ms 9160 KB Output is correct
19 Correct 144 ms 9416 KB Output is correct
20 Correct 145 ms 9572 KB Output is correct
21 Correct 131 ms 9416 KB Output is correct
22 Correct 138 ms 9412 KB Output is correct
23 Correct 151 ms 9672 KB Output is correct
24 Correct 151 ms 9756 KB Output is correct
25 Correct 137 ms 9764 KB Output is correct
26 Correct 134 ms 9532 KB Output is correct
27 Correct 146 ms 9928 KB Output is correct
28 Correct 149 ms 9836 KB Output is correct
29 Correct 131 ms 9764 KB Output is correct
30 Correct 136 ms 9672 KB Output is correct
31 Correct 157 ms 9928 KB Output is correct
32 Correct 161 ms 9928 KB Output is correct
33 Correct 140 ms 9928 KB Output is correct
34 Correct 144 ms 9936 KB Output is correct
35 Incorrect 158 ms 9928 KB Wrong Answer [2]
36 Halted 0 ms 0 KB -