QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#179042 | #3097. Shopping | bear0131 | 0 | 1ms | 3720kb | C++20 | 3.6kb | 2023-09-14 17:07:39 | 2023-09-14 17:07:40 |
Anna
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
#include "Anna.h"
namespace {
int qlog[1000100];
const int Bn = 62;
int n, tl, tr;
vi curval;
int curtp = 0;
int l, r, B, bl, cd;
int ans;
vi sep, mnsep;
void calc1(){
//cout << "calc1\n";
//cout << bl << "\n";
int mn = 0x3f3f3f3f, mnid = 0;
rep(i, (int)mnsep.size()){
int curv = 0;
for(int j = i * bl; j < (i+1) * bl; ++j){
//cout << curval[j] << " ";
curv += curval[j] << (j - i);
}
//cout << ": " << curv << "\n";
if(curv < mn) mn = curv, mnid = i;
}
ans = mnsep[mnid];
return ;
}
void reinit(int nl, int nr){
if(nr - nl + 1 <= 100){
curtp = 1;
mnsep.clear();
for(int i = nl; i <= nr; ++i)
mnsep.emplace_back(i);
bl = qlog[(int)mnsep.size()];
return ;
}
l = nl, r = nr;
sep.clear();
B = (r-l+1 + Bn-1) / Bn;
for(int i = l; i <= r; i += B)
++cd, sep.emplace_back(i);
bl = qlog[B];
}
void calc0(){
vi res;
mnsep.clear();
int nl = -1, nr = -1;
int lst = l;
for(int i = 0, p = 0; i < bl * cd; i += bl, ++p){
int curp = 0;
for(int j = i; j < i + bl; ++j)
curp += curval[j] << (j - i);
curp += sep[p];
mnsep.emplace_back(curp);
if(res.empty()){
if(tl <= curp && curp <= tr){
rep(cc, 6) res.emplace_back(1);
curtp = 1;
} else if(curp > tr){
rep(cc, 6) res.emplace_back((p>>cc) & 1);
nl = lst+1, nr = curp-1;
}
}
lst = curp;
}
if(!curtp) reinit(nl, nr);
else bl = qlog[(int)mnsep.size()];
rep(i, 6) SendA(res[i]);
}
}
void InitA(int N, int L, int R){
n = N, tl = L, tr = R;
l = 0, r = N-1;
for(int i = 1; i <= n; ++i) qlog[i] = qlog[i>>1] + 1;
reinit(l, r);
}
void ReceiveA(bool x){
curval.emplace_back((int)x);
//cout << "cur: ";
//rep(i, (int)curval.size())
// cout << curval[i] << " ";
//cout << "\n";
if(curtp == 0){
if((int)curval.size() == bl * cd)
calc0();
} else {
if((int)curval.size() == bl * (r-l+1))
calc1();
}
}
int Answer(){ return ans; }
Bruno
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
#include "Bruno.h"
namespace {
int qlog[1000100];
int n, a[1000100];
const int Bn = 62;
int l, r, B, bl;
vi mnsep;
void calc1(){
bl = qlog[(int)mnsep.size()];
rep(i, (int)mnsep.size()){
int cnt = 0;
rep(j, (int)mnsep.size()) if(a[mnsep[j]] < a[mnsep[i]])
++cnt;
rep(j, bl)
SendB((cnt >> j) & 1);
}
}
void reinit(int nl, int nr){
mnsep.clear();
l = nl, r = nr;
if(nr - nl + 1 <= 100){
for(int i = l; i <= r; ++i)
mnsep.emplace_back(i);
calc1();
return ;
}
B = (r-l+1 + Bn-1) / Bn;
bl = qlog[B];
vi sb;
for(int i = l; i <= r; i += B){
int mnid = i;
for(int j = i; j < i+B && j <= r; ++j) if(a[j] < a[mnid]) mnid = j;
mnsep.emplace_back(mnid);
sb.emplace_back(mnid - i);
}
rep(i, (int)sb.size()) rep(j, bl)
SendB((sb[i] >> j) & 1);
}
vi curval;
void calc0(){
int val = 0;
rep(i, 6) val += curval[i] << i;
if(val == 63){
calc1();
} else {
reinit(mnsep[val]+1, mnsep[val+1]-1);
}
}
}
void InitB(int N, vi P){
n = N;
rep(i, n) a[i] = P[i];
for(int i = 1; i <= n; ++i) qlog[i] = qlog[i>>1] + 1;
reinit(0, n-1);
}
void ReceiveB(bool x){
curval.emplace_back((int)x);
if((int)curval.size() == 6)
calc0();
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 1
Accepted
time: 1ms
memory: 3720kb
input:
-1
output:
-1 0 -1
input:
output:
Accepted: 0 0
result:
ok
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 3620kb
input:
-1
output:
-1 0 0 1 0 -1
input:
output:
Wrong Answer [1]
result:
wrong answer
Subtask #2:
score: 0
Skipped
Subtask #3:
score: 0
Skipped