Submission #387735

# Submission time Handle Problem Language Result Execution time Memory
387735 2021-04-09T06:43:53 Z i_am_noob Shopping (JOI21_shopping) C++17
10 / 100
214 ms 24304 KB
#include "Anna.h"
#include<bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
using namespace std;

#define ll long long
//#define int ll
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
//#define inf 1010000000
#define inf 4000000000000000000
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 826
#endif

namespace {

int n,l,r,res;
int zck;
const int K=201;
vector<int> vec1,vec2;
vector<bool> tree1,tree2;
bool flag;

vector<int> build(vector<bool>& tree){
    vector<int> stk;
    vector<int> pre;
    int cur=0;
    for(auto i: tree){
        if(i){
            pre.pb(sz(stk)?stk.back():-1);
            stk.pb(cur);
            cur++;
        }
        else{
            stk.pop_back();
        }
    }
    return pre;
}

void response(vector<int> id, vector<int> pre, vector<int>& vec){
    int L,R;
    rep(sz(id)) if(id[i]>=l){
        L=i;
        break;
    }
    rep3(i,sz(id)-1,0) if(id[i]<=r){
        R=i;
        break;
    }
    bug(L,R);
    vector<int> tmp1;
    rep(K) tmp1.pb(sz(id)/K);
    rep(sz(id)%K) tmp1[i]++;
    int lpos,rpos,cur=0,y;
    rep(K){
        if(tmp1[i]+cur>L){
            lpos=i;
            break;
        }
        cur+=tmp1[i];
    }
    cur=0;
    rep(K){
        if(tmp1[i]+cur>R){
            rpos=i;
            break;
        }
        cur+=tmp1[i];
    }
    if(rpos<=lpos+1){
        SendA(0);
        flag=0;
        int z=lpos;
        rep(8) SendA(z&1),z>>=1;
        cur=0;
        rep(lpos) cur+=tmp1[i];
        rep(tmp1[lpos]) vec.pb(id[cur+i]);
        if(lpos+1<sz(tmp1)) rep(tmp1[lpos+1]) vec.pb(id[cur+tmp1[lpos]+i]);
        for(auto i: vec) bug(i);
        return;
    }
    rep2(i,lpos+1,rpos) if(pre[i]<lpos+1) y=i;
    SendA(1);
    flag=1;
    int z=y;
    rep(8) SendA(z&1),z>>=1;
    cur=0;
    rep(pre[y]) cur+=tmp1[i];
    if(pre[y]>=0) rep(tmp1[pre[y]]) vec.pb(id[cur+i]);
    bug(pre[y],y);
    bug("A",sz(vec));
    vec.pb(-1);
    rep2(i,y+1,sz(pre)) if(pre[i]<y){
        bug(i);
        cur=0;
        rep1(j,i) cur+=tmp1[j];
        rep1(j,tmp1[i]) vec.pb(id[cur+j]);
        break;
    }
    bug("A",sz(vec));
    for(auto i: vec) bug(i);
}

}  // namespace

void InitA(int N, int L, int R) {
    n=N,l=L,r=R;
}

void ReceiveA(bool x) {
    if(!zck){
        static int cnt=2*K;
        tree1.pb(x);
        cnt--;
        if(cnt<=0){
            vector<int> tmp;
            rep(n) tmp.pb(i);
            vector<int> pre=build(tree1);
            response(tmp,pre,vec1);
            zck++;
        }
    }
    else if(zck==1){
        if(flag){
            static int cnt=20,pos=0;
            pos+=x*(1<<(20-cnt));
            cnt--;
            if(!cnt){
                for(auto& i: vec1) if(i==-1) i=pos;
                flag=0;
            }
        }
        else{
            static int cnt=2*K;
            tree2.pb(x);
            cnt--;
            if(cnt<=0){
                vector<int> pre=build(tree2);
                response(vec1,pre,vec2);
                bug(sz(vec1),sz(vec2));
                zck++;
            }
        }
    }
    else{
        if(flag){
            static int cnt=20,pos=0;
            pos+=x*(1<<(20-cnt));
            cnt--;
            if(!cnt){
                for(auto& i: vec2) if(i==-1) i=pos;
                flag=0;
            }
        }
        else{
            static int cnt=2*sz(vec2);
            tree2.pb(x);
            cnt--;
            if(cnt<=0){
                vector<int> pre=build(tree2);
                rep3(i,sz(vec2)-1,0) if(vec2[i]<=r&&(pre[i]==-1||vec2[pre[i]]<l)){
                    res=vec2[i];
                    break;
                }
            }
        }
    }
}

int Answer() {
    bug(res,sz(vec1),sz(vec2));
    return res;
}
#include "Bruno.h"
#include<bits/stdc++.h>
using namespace std;

#define ll long long
//#define int ll
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define inf 1010000000
//#define inf 4000000000000000000
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 826
#endif

namespace {

int n;
int zck;
bool flag;
vector<int> a,vec1,vec2,minvec;
const int K=201;

vector<bool> build(vector<int>& vec){
    vector<bool> res;
    vector<int> stk;
    for(auto i: vec){
        while(sz(stk)&&i<stk.back()) res.pb(0),stk.pop_back();
        res.pb(1),stk.pb(i);
    }
    rep(sz(stk)) res.pb(0);
    assert(sz(res)==2*sz(vec));
    return res;
}

vector<int> Get(vector<int>& id, int val){
    vector<int> tmp1;
    rep(K) tmp1.pb(sz(id)/K);
    rep(sz(id)%K) tmp1[i]++;
    int cur;
    vector<int> res;
    if(sz(id)<100) for(auto i: id) bug(i);
    if(flag){
        bug(sz(id));
        cur=0;
        rep(val) cur+=tmp1[i];
        int minn=n+1,minid;
        rep2(i,cur,cur+tmp1[val]) if(a[id[i]]<minn) minn=a[id[i]],minid=id[i];
        int z=minid;
        rep(20) SendB(z&1),z>>=1;
        rep3(i,val-1,0) if(minvec[i]<minvec[val]){
            cur=0;
            rep1(j,i) cur+=tmp1[j];
            rep2(j,cur,cur+tmp1[i]) res.pb(id[j]);
            bug(i);
            break;
        }
        bug("B",sz(res));
        res.pb(minid);
        bug(val);
        rep2(i,val+1,sz(minvec)) if(minvec[i]<minvec[val]){
            bug(i);
            cur=0;
            rep1(j,i) cur+=tmp1[j];
            rep2(j,cur,cur+tmp1[i]) res.pb(id[j]);
            break;
        }
        bug("B",sz(res));
    }
    else{
        cur=0;
        rep(val) cur+=tmp1[i];
        rep2(i,cur,cur+tmp1[val]) res.pb(id[i]);
        if(val+1<sz(tmp1)) rep2(i,cur+tmp1[val],cur+tmp1[val]+tmp1[val+1]) res.pb(id[i]);

    }
    for(auto i: res) bug(i);
    return res;
}

vector<bool> tree1,tree2;

}  // namespace



void InitB(int N, vector<int> A) {
    n=N,a=A;
    vector<int> tmp1;
    rep(K) tmp1.pb(n/K);
    rep(n%K) tmp1[i]++;
    int cur=0;
    rep(K){
        int minn=inf;
        rep2(j,cur,cur+tmp1[i]) minn=min(minn,a[j]);
        minvec.pb(minn);
        cur+=tmp1[i];
    }
    tree1=build(minvec);
    bug(sz(tree1));
    for(auto i: tree1) SendB(i);
}

void ReceiveB(bool y) {
    if(!zck){
        flag=y;
        zck++;
    }
    else if(zck==1){
        static int cnt=8,val=0;
        val+=y*(1<<(8-cnt));
        cnt--;
        if(!cnt){
            vector<int> tmp,tmp1;
            rep(n) tmp.pb(i);
            vec1=Get(tmp,val);
            rep(K) tmp1.pb(sz(vec1)/K);
            rep(sz(vec1)%K) tmp1[i]++;
            minvec.clear();
            int cur=0;
            rep(K){
                int minn=inf;
                rep2(j,cur,cur+tmp1[i]) minn=min(minn,a[vec1[j]]);
                minvec.pb(minn);
                cur+=tmp1[i];
            }
            tree2=build(minvec);
            bug(sz(tree2));
            for(auto i: tree2) SendB(i);
            zck++;
        }
    }
    else if(zck==2){
        flag=y;
        zck++;
    }
    else{
        static int cnt=8,val=0;
        val+=y*(1<<(8-cnt));
        cnt--;
        if(!cnt){
            vec2=Get(vec1,val);
            minvec.clear();
            for(auto i: vec2) minvec.pb(a[i]);
            tree2=build(minvec);
            bug(sz(tree2),sz(vec1),sz(vec2));
            for(auto i: tree2) SendB(i);
            zck++;
        }
    }
}

Compilation message

Anna.cpp: In function 'void {anonymous}::response(std::vector<int>, std::vector<int>, std::vector<int>&)':
Anna.cpp:26:18: warning: statement has no effect [-Wunused-value]
   26 | #define bug(...) 826
      |                  ^~~
Anna.cpp:65:5: note: in expansion of macro 'bug'
   65 |     bug(L,R);
      |     ^~~
Anna.cpp:26:18: warning: statement has no effect [-Wunused-value]
   26 | #define bug(...) 826
      |                  ^~~
Anna.cpp:94:26: note: in expansion of macro 'bug'
   94 |         for(auto i: vec) bug(i);
      |                          ^~~
Anna.cpp:94:18: warning: unused variable 'i' [-Wunused-variable]
   94 |         for(auto i: vec) bug(i);
      |                  ^
Anna.cpp:26:18: warning: statement has no effect [-Wunused-value]
   26 | #define bug(...) 826
      |                  ^~~
Anna.cpp:105:5: note: in expansion of macro 'bug'
  105 |     bug(pre[y],y);
      |     ^~~
Anna.cpp:26:18: warning: statement has no effect [-Wunused-value]
   26 | #define bug(...) 826
      |                  ^~~
Anna.cpp:106:5: note: in expansion of macro 'bug'
  106 |     bug("A",sz(vec));
      |     ^~~
Anna.cpp:26:18: warning: statement has no effect [-Wunused-value]
   26 | #define bug(...) 826
      |                  ^~~
Anna.cpp:109:9: note: in expansion of macro 'bug'
  109 |         bug(i);
      |         ^~~
Anna.cpp:26:18: warning: statement has no effect [-Wunused-value]
   26 | #define bug(...) 826
      |                  ^~~
Anna.cpp:115:5: note: in expansion of macro 'bug'
  115 |     bug("A",sz(vec));
      |     ^~~
Anna.cpp:26:18: warning: statement has no effect [-Wunused-value]
   26 | #define bug(...) 826
      |                  ^~~
Anna.cpp:116:22: note: in expansion of macro 'bug'
  116 |     for(auto i: vec) bug(i);
      |                      ^~~
Anna.cpp:116:14: warning: unused variable 'i' [-Wunused-variable]
  116 |     for(auto i: vec) bug(i);
      |              ^
Anna.cpp: In function 'void ReceiveA(bool)':
Anna.cpp:26:18: warning: statement has no effect [-Wunused-value]
   26 | #define bug(...) 826
      |                  ^~~
Anna.cpp:155:17: note: in expansion of macro 'bug'
  155 |                 bug(sz(vec1),sz(vec2));
      |                 ^~~
Anna.cpp: In function 'int Answer()':
Anna.cpp:26:18: warning: statement has no effect [-Wunused-value]
   26 | #define bug(...) 826
      |                  ^~~
Anna.cpp:186:5: note: in expansion of macro 'bug'
  186 |     bug(res,sz(vec1),sz(vec2));
      |     ^~~
Anna.cpp: In function 'void {anonymous}::response(std::vector<int>, std::vector<int>, std::vector<int>&)':
Anna.cpp:69:9: warning: 'lpos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   69 |     int lpos,rpos,cur=0,y;
      |         ^~~~
Anna.cpp:108:25: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
  108 |     rep2(i,y+1,sz(pre)) if(pre[i]<y){
      |                         ^~
Anna.cpp:12:37: warning: 'rpos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   12 | #define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
      |                                     ^
Anna.cpp:69:14: note: 'rpos' was declared here
   69 |     int lpos,rpos,cur=0,y;
      |              ^~~~
Anna.cpp:71:9: warning: 'L' may be used uninitialized in this function [-Wmaybe-uninitialized]
   71 |         if(tmp1[i]+cur>L){
      |         ^~
Anna.cpp:79:9: warning: 'R' may be used uninitialized in this function [-Wmaybe-uninitialized]
   79 |         if(tmp1[i]+cur>R){
      |         ^~

Bruno.cpp: In function 'std::vector<int> {anonymous}::Get(std::vector<int>&, int)':
Bruno.cpp:25:18: warning: statement has no effect [-Wunused-value]
   25 | #define bug(...) 826
      |                  ^~~
Bruno.cpp:54:36: note: in expansion of macro 'bug'
   54 |     if(sz(id)<100) for(auto i: id) bug(i);
      |                                    ^~~
Bruno.cpp:54:29: warning: unused variable 'i' [-Wunused-variable]
   54 |     if(sz(id)<100) for(auto i: id) bug(i);
      |                             ^
Bruno.cpp:25:18: warning: statement has no effect [-Wunused-value]
   25 | #define bug(...) 826
      |                  ^~~
Bruno.cpp:56:9: note: in expansion of macro 'bug'
   56 |         bug(sz(id));
      |         ^~~
Bruno.cpp:25:18: warning: statement has no effect [-Wunused-value]
   25 | #define bug(...) 826
      |                  ^~~
Bruno.cpp:67:13: note: in expansion of macro 'bug'
   67 |             bug(i);
      |             ^~~
Bruno.cpp:25:18: warning: statement has no effect [-Wunused-value]
   25 | #define bug(...) 826
      |                  ^~~
Bruno.cpp:70:9: note: in expansion of macro 'bug'
   70 |         bug("B",sz(res));
      |         ^~~
Bruno.cpp:25:18: warning: statement has no effect [-Wunused-value]
   25 | #define bug(...) 826
      |                  ^~~
Bruno.cpp:72:9: note: in expansion of macro 'bug'
   72 |         bug(val);
      |         ^~~
Bruno.cpp:25:18: warning: statement has no effect [-Wunused-value]
   25 | #define bug(...) 826
      |                  ^~~
Bruno.cpp:74:13: note: in expansion of macro 'bug'
   74 |             bug(i);
      |             ^~~
Bruno.cpp:25:18: warning: statement has no effect [-Wunused-value]
   25 | #define bug(...) 826
      |                  ^~~
Bruno.cpp:80:9: note: in expansion of macro 'bug'
   80 |         bug("B",sz(res));
      |         ^~~
Bruno.cpp:25:18: warning: statement has no effect [-Wunused-value]
   25 | #define bug(...) 826
      |                  ^~~
Bruno.cpp:89:22: note: in expansion of macro 'bug'
   89 |     for(auto i: res) bug(i);
      |                      ^~~
Bruno.cpp:89:14: warning: unused variable 'i' [-Wunused-variable]
   89 |     for(auto i: res) bug(i);
      |              ^
Bruno.cpp: In function 'void InitB(int, std::vector<int>)':
Bruno.cpp:25:18: warning: statement has no effect [-Wunused-value]
   25 | #define bug(...) 826
      |                  ^~~
Bruno.cpp:112:5: note: in expansion of macro 'bug'
  112 |     bug(sz(tree1));
      |     ^~~
Bruno.cpp: In function 'void ReceiveB(bool)':
Bruno.cpp:25:18: warning: statement has no effect [-Wunused-value]
   25 | #define bug(...) 826
      |                  ^~~
Bruno.cpp:140:13: note: in expansion of macro 'bug'
  140 |             bug(sz(tree2));
      |             ^~~
Bruno.cpp:25:18: warning: statement has no effect [-Wunused-value]
   25 | #define bug(...) 826
      |                  ^~~
Bruno.cpp:158:13: note: in expansion of macro 'bug'
  158 |             bug(sz(tree2),sz(vec1),sz(vec2));
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 480 KB Output is correct
2 Correct 9 ms 476 KB Output is correct
3 Correct 9 ms 484 KB Output is correct
4 Correct 5 ms 488 KB Output is correct
5 Correct 8 ms 448 KB Output is correct
6 Correct 7 ms 544 KB Output is correct
7 Correct 6 ms 592 KB Output is correct
8 Correct 8 ms 476 KB Output is correct
9 Correct 5 ms 592 KB Output is correct
10 Correct 9 ms 500 KB Output is correct
11 Correct 8 ms 496 KB Output is correct
12 Correct 9 ms 500 KB Output is correct
13 Correct 8 ms 516 KB Output is correct
14 Correct 6 ms 524 KB Output is correct
15 Correct 11 ms 596 KB Output is correct
16 Correct 8 ms 592 KB Output is correct
17 Correct 6 ms 492 KB Output is correct
18 Correct 11 ms 596 KB Output is correct
19 Correct 6 ms 448 KB Output is correct
20 Correct 9 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 480 KB Output is correct
2 Correct 9 ms 476 KB Output is correct
3 Correct 9 ms 484 KB Output is correct
4 Correct 5 ms 488 KB Output is correct
5 Correct 8 ms 448 KB Output is correct
6 Correct 7 ms 544 KB Output is correct
7 Correct 6 ms 592 KB Output is correct
8 Correct 8 ms 476 KB Output is correct
9 Correct 5 ms 592 KB Output is correct
10 Correct 9 ms 500 KB Output is correct
11 Correct 8 ms 496 KB Output is correct
12 Correct 9 ms 500 KB Output is correct
13 Correct 8 ms 516 KB Output is correct
14 Correct 6 ms 524 KB Output is correct
15 Correct 11 ms 596 KB Output is correct
16 Correct 8 ms 592 KB Output is correct
17 Correct 6 ms 492 KB Output is correct
18 Correct 11 ms 596 KB Output is correct
19 Correct 6 ms 448 KB Output is correct
20 Correct 9 ms 592 KB Output is correct
21 Correct 10 ms 700 KB Output is correct
22 Correct 9 ms 740 KB Output is correct
23 Correct 11 ms 732 KB Output is correct
24 Correct 10 ms 688 KB Output is correct
25 Correct 10 ms 708 KB Output is correct
26 Correct 9 ms 772 KB Output is correct
27 Correct 10 ms 688 KB Output is correct
28 Correct 9 ms 768 KB Output is correct
29 Correct 12 ms 772 KB Output is correct
30 Correct 11 ms 788 KB Output is correct
31 Correct 10 ms 676 KB Output is correct
32 Correct 12 ms 692 KB Output is correct
33 Correct 13 ms 700 KB Output is correct
34 Correct 10 ms 816 KB Output is correct
35 Correct 12 ms 680 KB Output is correct
36 Correct 15 ms 696 KB Output is correct
37 Correct 13 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 23952 KB Output is correct
2 Correct 162 ms 24212 KB Output is correct
3 Correct 194 ms 24268 KB Output is correct
4 Correct 214 ms 24292 KB Output is correct
5 Correct 188 ms 24304 KB Output is correct
6 Correct 177 ms 24200 KB Output is correct
7 Incorrect 22 ms 8148 KB Wrong Answer [2]
8 Halted 0 ms 0 KB -