Submission #1083441

# Submission time Handle Problem Language Result Execution time Memory
1083441 2024-09-03T06:44:58 Z tosivanmak Minerals (JOI19_minerals) C++17
90 / 100
32 ms 2996 KB
#include "minerals.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
mt19937 rng((ll)chrono::steady_clock::now().time_since_epoch().count());
random_device rd;
mt19937 g(rd());
ll rnd(ll u, ll v){
    return uniform_int_distribution<ll>(u,v)(rng);
}
int mp[86005];
bool used[86005];
int cnt=0;
int machine=0;
bool inside[86005];
map<ll,ll>hv;
int query_num=0;
 
ll fp[43005],sp[43005];
bool pref[86005];
ll timer=1,timer2=1;
void dc(ll l, ll r){
    if(l==r)return;
    ll mid=(l+r-1)>>1;
    ll last_qry;
    bool noonlef=0;
    for(int i=l;i<=mid;i++){
        last_qry=Query(fp[i]); pref[fp[i]]^=1;
        if(pref[fp[i]]==0)noonlef=1;
    }
    // cout<<"dc "<<l<<" "<<r<<" "<<noonlef<<'\n';
    vector<ll>lef,righ;
    ll brkid;
    for(int i=l;i<=r-1;i++){
        ll curq=Query(sp[i]);
        pref[sp[i]]^=1;
        bool remov=0;
        if(!pref[sp[i]])remov=1;
        if(remov){
            if(curq==last_qry){
                if(noonlef)righ.push_back(sp[i]);
                else lef.push_back(sp[i]);
            }
            else{
                if(noonlef)lef.push_back(sp[i]);
                else righ.push_back(sp[i]);
            }
        }
        else{
            if(curq==last_qry){
                if(noonlef)righ.push_back(sp[i]);
                else lef.push_back(sp[i]);
            }
            else{
                if(noonlef)lef.push_back(sp[i]);
                else righ.push_back(sp[i]);
            }
        }
        if(lef.size()==mid-l+1||righ.size()==r-(mid+1)+1){
            brkid=i; break;
        }
        last_qry=curq;
    }
    if(lef.size()!=mid-l+1){
        for(int i=brkid+1;i<=r;i++){
            lef.push_back(sp[i]);
        }
    }
    else{
        for(int i=brkid+1;i<=r;i++){
            righ.push_back(sp[i]);
        }
    }
    shuffle(lef.begin(),lef.end(),g);
    shuffle(righ.begin(),righ.end(),g);
    for(int i=0;i<lef.size();i++){
        sp[l+i]=lef[i];
    }
    for(int i=0;i<righ.size();i++){
        sp[mid+1+i]=righ[i];
    }
    dc(l,mid); dc(mid+1,r);
}
void Solve(int n){
    int prev=0;
    for(int i=1;i<=2*n;i++){
        int cur=Query(i);
        if(cur==prev+1){
            fp[timer++]=i;
        }
        else{
            sp[timer2++]=i;
        }
        prev=cur;
    }
    for(int i=1;i<=2*n;i++)pref[i]=1;
    dc(1,n);
    for(int i=1;i<=n;i++){
        Answer(fp[i],sp[i]);
    }
}

Compilation message

minerals.cpp: In function 'void dc(long long int, long long int)':
minerals.cpp:60:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   60 |         if(lef.size()==mid-l+1||righ.size()==r-(mid+1)+1){
      |            ~~~~~~~~~~^~~~~~~~~
minerals.cpp:60:44: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   60 |         if(lef.size()==mid-l+1||righ.size()==r-(mid+1)+1){
      |                                 ~~~~~~~~~~~^~~~~~~~~~~~~
minerals.cpp:65:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   65 |     if(lef.size()!=mid-l+1){
      |        ~~~~~~~~~~^~~~~~~~~
minerals.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for(int i=0;i<lef.size();i++){
      |                 ~^~~~~~~~~~~
minerals.cpp:80:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for(int i=0;i<righ.size();i++){
      |                 ~^~~~~~~~~~~~
minerals.cpp:71:24: warning: 'brkid' may be used uninitialized in this function [-Wmaybe-uninitialized]
   71 |         for(int i=brkid+1;i<=r;i++){
      |                   ~~~~~^~
minerals.cpp:41:13: warning: 'last_qry' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |             if(curq==last_qry){
      |             ^~
# 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 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 5 ms 856 KB Output is correct
5 Correct 10 ms 1348 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 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 5 ms 856 KB Output is correct
9 Correct 10 ms 1348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1076 KB Output is correct
12 Correct 9 ms 1288 KB Output is correct
13 Correct 8 ms 1356 KB Output is correct
14 Correct 10 ms 1268 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 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 5 ms 856 KB Output is correct
9 Correct 10 ms 1348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1076 KB Output is correct
12 Correct 9 ms 1288 KB Output is correct
13 Correct 8 ms 1356 KB Output is correct
14 Correct 10 ms 1268 KB Output is correct
15 Correct 24 ms 2708 KB Output is correct
16 Correct 27 ms 2640 KB Output is correct
17 Correct 27 ms 2648 KB Output is correct
18 Correct 22 ms 2496 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 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 5 ms 856 KB Output is correct
9 Correct 10 ms 1348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1076 KB Output is correct
12 Correct 9 ms 1288 KB Output is correct
13 Correct 8 ms 1356 KB Output is correct
14 Correct 10 ms 1268 KB Output is correct
15 Correct 24 ms 2708 KB Output is correct
16 Correct 27 ms 2640 KB Output is correct
17 Correct 27 ms 2648 KB Output is correct
18 Correct 22 ms 2496 KB Output is correct
19 Correct 26 ms 2812 KB Output is correct
20 Correct 25 ms 2852 KB Output is correct
21 Correct 28 ms 2860 KB Output is correct
22 Correct 22 ms 2556 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 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 5 ms 856 KB Output is correct
9 Correct 10 ms 1348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1076 KB Output is correct
12 Correct 9 ms 1288 KB Output is correct
13 Correct 8 ms 1356 KB Output is correct
14 Correct 10 ms 1268 KB Output is correct
15 Correct 24 ms 2708 KB Output is correct
16 Correct 27 ms 2640 KB Output is correct
17 Correct 27 ms 2648 KB Output is correct
18 Correct 22 ms 2496 KB Output is correct
19 Correct 26 ms 2812 KB Output is correct
20 Correct 25 ms 2852 KB Output is correct
21 Correct 28 ms 2860 KB Output is correct
22 Correct 22 ms 2556 KB Output is correct
23 Correct 32 ms 2888 KB Output is correct
24 Correct 30 ms 2832 KB Output is correct
25 Correct 24 ms 2828 KB Output is correct
26 Correct 22 ms 2648 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 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 5 ms 856 KB Output is correct
9 Correct 10 ms 1348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1076 KB Output is correct
12 Correct 9 ms 1288 KB Output is correct
13 Correct 8 ms 1356 KB Output is correct
14 Correct 10 ms 1268 KB Output is correct
15 Correct 24 ms 2708 KB Output is correct
16 Correct 27 ms 2640 KB Output is correct
17 Correct 27 ms 2648 KB Output is correct
18 Correct 22 ms 2496 KB Output is correct
19 Correct 26 ms 2812 KB Output is correct
20 Correct 25 ms 2852 KB Output is correct
21 Correct 28 ms 2860 KB Output is correct
22 Correct 22 ms 2556 KB Output is correct
23 Correct 32 ms 2888 KB Output is correct
24 Correct 30 ms 2832 KB Output is correct
25 Correct 24 ms 2828 KB Output is correct
26 Correct 22 ms 2648 KB Output is correct
27 Correct 32 ms 2996 KB Output is correct
28 Correct 25 ms 2896 KB Output is correct
29 Correct 24 ms 2912 KB Output is correct
30 Correct 26 ms 2824 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 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 5 ms 856 KB Output is correct
9 Correct 10 ms 1348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1076 KB Output is correct
12 Correct 9 ms 1288 KB Output is correct
13 Correct 8 ms 1356 KB Output is correct
14 Correct 10 ms 1268 KB Output is correct
15 Correct 24 ms 2708 KB Output is correct
16 Correct 27 ms 2640 KB Output is correct
17 Correct 27 ms 2648 KB Output is correct
18 Correct 22 ms 2496 KB Output is correct
19 Correct 26 ms 2812 KB Output is correct
20 Correct 25 ms 2852 KB Output is correct
21 Correct 28 ms 2860 KB Output is correct
22 Correct 22 ms 2556 KB Output is correct
23 Correct 32 ms 2888 KB Output is correct
24 Correct 30 ms 2832 KB Output is correct
25 Correct 24 ms 2828 KB Output is correct
26 Correct 22 ms 2648 KB Output is correct
27 Correct 32 ms 2996 KB Output is correct
28 Correct 25 ms 2896 KB Output is correct
29 Correct 24 ms 2912 KB Output is correct
30 Correct 26 ms 2824 KB Output is correct
31 Correct 26 ms 2896 KB Output is correct
32 Correct 26 ms 2948 KB Output is correct
33 Correct 23 ms 2992 KB Output is correct
34 Correct 23 ms 2868 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 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 5 ms 856 KB Output is correct
9 Correct 10 ms 1348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1076 KB Output is correct
12 Correct 9 ms 1288 KB Output is correct
13 Correct 8 ms 1356 KB Output is correct
14 Correct 10 ms 1268 KB Output is correct
15 Correct 24 ms 2708 KB Output is correct
16 Correct 27 ms 2640 KB Output is correct
17 Correct 27 ms 2648 KB Output is correct
18 Correct 22 ms 2496 KB Output is correct
19 Correct 26 ms 2812 KB Output is correct
20 Correct 25 ms 2852 KB Output is correct
21 Correct 28 ms 2860 KB Output is correct
22 Correct 22 ms 2556 KB Output is correct
23 Correct 32 ms 2888 KB Output is correct
24 Correct 30 ms 2832 KB Output is correct
25 Correct 24 ms 2828 KB Output is correct
26 Correct 22 ms 2648 KB Output is correct
27 Correct 32 ms 2996 KB Output is correct
28 Correct 25 ms 2896 KB Output is correct
29 Correct 24 ms 2912 KB Output is correct
30 Correct 26 ms 2824 KB Output is correct
31 Correct 26 ms 2896 KB Output is correct
32 Correct 26 ms 2948 KB Output is correct
33 Correct 23 ms 2992 KB Output is correct
34 Correct 23 ms 2868 KB Output is correct
35 Incorrect 26 ms 2916 KB Wrong Answer [2]
36 Halted 0 ms 0 KB -