답안 #1083440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083440 2024-09-03T06:43:48 Z tosivanmak Minerals (JOI19_minerals) C++17
100 / 100
35 ms 3144 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;
    
    if(mid>=l+2400)mid-=1080;
    else if(mid>=l+1200)mid-=540;
    else if(mid>=l+610)mid-=275;
    else if(mid>=l+308)mid-=137;
    else if(mid>=l+154)mid-=60;
    else if(mid>=l+76)mid-=30;
    else if(mid>=l+72)mid-=29;
    else if(mid>=l+68)mid-=28;
    else if(mid>=l+64)mid-=27;
    else if(mid>=l+56)mid-=23;
    else if(mid>=l+52)mid-=21;
    else if(mid>=l+50)mid-=19;
    else if(mid>=l+44)mid-=17;
    else if(mid>=l+40)mid-=13;
    else if(mid>=l+38)mid-=10;
    else if(mid>=l+30)mid-=8;
    else if(mid>=l+24)mid-=7;
    else if(mid>=l+20)mid-=6;
    else if(mid>=l+17)mid-=5;
    else if(mid>=l+13)mid-=4;
    else if(mid>=l+10)mid-=3;
    else if(mid>=l+8)mid-=2;
    else if(mid>=l+2)mid--;
    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:84: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]
   84 |         if(lef.size()==mid-l+1||righ.size()==r-(mid+1)+1){
      |            ~~~~~~~~~~^~~~~~~~~
minerals.cpp:84: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]
   84 |         if(lef.size()==mid-l+1||righ.size()==r-(mid+1)+1){
      |                                 ~~~~~~~~~~~^~~~~~~~~~~~~
minerals.cpp:89: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]
   89 |     if(lef.size()!=mid-l+1){
      |        ~~~~~~~~~~^~~~~~~~~
minerals.cpp:101:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     for(int i=0;i<lef.size();i++){
      |                 ~^~~~~~~~~~~
minerals.cpp:104:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |     for(int i=0;i<righ.size();i++){
      |                 ~^~~~~~~~~~~~
minerals.cpp:95:24: warning: 'brkid' may be used uninitialized in this function [-Wmaybe-uninitialized]
   95 |         for(int i=brkid+1;i<=r;i++){
      |                   ~~~~~^~
minerals.cpp:65:13: warning: 'last_qry' may be used uninitialized in this function [-Wmaybe-uninitialized]
   65 |             if(curq==last_qry){
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 9 ms 1368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 9 ms 1368 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1112 KB Output is correct
12 Correct 13 ms 1368 KB Output is correct
13 Correct 9 ms 1448 KB Output is correct
14 Correct 9 ms 1348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 9 ms 1368 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1112 KB Output is correct
12 Correct 13 ms 1368 KB Output is correct
13 Correct 9 ms 1448 KB Output is correct
14 Correct 9 ms 1348 KB Output is correct
15 Correct 25 ms 2756 KB Output is correct
16 Correct 24 ms 2668 KB Output is correct
17 Correct 24 ms 2732 KB Output is correct
18 Correct 23 ms 2672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 9 ms 1368 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1112 KB Output is correct
12 Correct 13 ms 1368 KB Output is correct
13 Correct 9 ms 1448 KB Output is correct
14 Correct 9 ms 1348 KB Output is correct
15 Correct 25 ms 2756 KB Output is correct
16 Correct 24 ms 2668 KB Output is correct
17 Correct 24 ms 2732 KB Output is correct
18 Correct 23 ms 2672 KB Output is correct
19 Correct 26 ms 2812 KB Output is correct
20 Correct 25 ms 2832 KB Output is correct
21 Correct 26 ms 2812 KB Output is correct
22 Correct 28 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 9 ms 1368 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1112 KB Output is correct
12 Correct 13 ms 1368 KB Output is correct
13 Correct 9 ms 1448 KB Output is correct
14 Correct 9 ms 1348 KB Output is correct
15 Correct 25 ms 2756 KB Output is correct
16 Correct 24 ms 2668 KB Output is correct
17 Correct 24 ms 2732 KB Output is correct
18 Correct 23 ms 2672 KB Output is correct
19 Correct 26 ms 2812 KB Output is correct
20 Correct 25 ms 2832 KB Output is correct
21 Correct 26 ms 2812 KB Output is correct
22 Correct 28 ms 2652 KB Output is correct
23 Correct 27 ms 2896 KB Output is correct
24 Correct 26 ms 2820 KB Output is correct
25 Correct 25 ms 2972 KB Output is correct
26 Correct 24 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 9 ms 1368 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1112 KB Output is correct
12 Correct 13 ms 1368 KB Output is correct
13 Correct 9 ms 1448 KB Output is correct
14 Correct 9 ms 1348 KB Output is correct
15 Correct 25 ms 2756 KB Output is correct
16 Correct 24 ms 2668 KB Output is correct
17 Correct 24 ms 2732 KB Output is correct
18 Correct 23 ms 2672 KB Output is correct
19 Correct 26 ms 2812 KB Output is correct
20 Correct 25 ms 2832 KB Output is correct
21 Correct 26 ms 2812 KB Output is correct
22 Correct 28 ms 2652 KB Output is correct
23 Correct 27 ms 2896 KB Output is correct
24 Correct 26 ms 2820 KB Output is correct
25 Correct 25 ms 2972 KB Output is correct
26 Correct 24 ms 2648 KB Output is correct
27 Correct 27 ms 2996 KB Output is correct
28 Correct 31 ms 2896 KB Output is correct
29 Correct 25 ms 3108 KB Output is correct
30 Correct 25 ms 2904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 9 ms 1368 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1112 KB Output is correct
12 Correct 13 ms 1368 KB Output is correct
13 Correct 9 ms 1448 KB Output is correct
14 Correct 9 ms 1348 KB Output is correct
15 Correct 25 ms 2756 KB Output is correct
16 Correct 24 ms 2668 KB Output is correct
17 Correct 24 ms 2732 KB Output is correct
18 Correct 23 ms 2672 KB Output is correct
19 Correct 26 ms 2812 KB Output is correct
20 Correct 25 ms 2832 KB Output is correct
21 Correct 26 ms 2812 KB Output is correct
22 Correct 28 ms 2652 KB Output is correct
23 Correct 27 ms 2896 KB Output is correct
24 Correct 26 ms 2820 KB Output is correct
25 Correct 25 ms 2972 KB Output is correct
26 Correct 24 ms 2648 KB Output is correct
27 Correct 27 ms 2996 KB Output is correct
28 Correct 31 ms 2896 KB Output is correct
29 Correct 25 ms 3108 KB Output is correct
30 Correct 25 ms 2904 KB Output is correct
31 Correct 28 ms 3028 KB Output is correct
32 Correct 33 ms 2896 KB Output is correct
33 Correct 26 ms 3004 KB Output is correct
34 Correct 35 ms 3144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 9 ms 1368 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1112 KB Output is correct
12 Correct 13 ms 1368 KB Output is correct
13 Correct 9 ms 1448 KB Output is correct
14 Correct 9 ms 1348 KB Output is correct
15 Correct 25 ms 2756 KB Output is correct
16 Correct 24 ms 2668 KB Output is correct
17 Correct 24 ms 2732 KB Output is correct
18 Correct 23 ms 2672 KB Output is correct
19 Correct 26 ms 2812 KB Output is correct
20 Correct 25 ms 2832 KB Output is correct
21 Correct 26 ms 2812 KB Output is correct
22 Correct 28 ms 2652 KB Output is correct
23 Correct 27 ms 2896 KB Output is correct
24 Correct 26 ms 2820 KB Output is correct
25 Correct 25 ms 2972 KB Output is correct
26 Correct 24 ms 2648 KB Output is correct
27 Correct 27 ms 2996 KB Output is correct
28 Correct 31 ms 2896 KB Output is correct
29 Correct 25 ms 3108 KB Output is correct
30 Correct 25 ms 2904 KB Output is correct
31 Correct 28 ms 3028 KB Output is correct
32 Correct 33 ms 2896 KB Output is correct
33 Correct 26 ms 3004 KB Output is correct
34 Correct 35 ms 3144 KB Output is correct
35 Correct 29 ms 3056 KB Output is correct
36 Correct 28 ms 3100 KB Output is correct
37 Correct 26 ms 3060 KB Output is correct
38 Correct 31 ms 2868 KB Output is correct