QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#300887 | #7967. 二进制 | defyers# | WA | 338ms | 140368kb | C++20 | 3.0kb | 2024-01-08 23:25:59 | 2024-01-08 23:25:59 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
using ll = long long;
using LL = long long;
const int N = 1 << 20;
struct BIT{
int bit[N];
void add(int p, int x){ for(int i = p; i < N; i += i & -i) bit[i] += x; }
int qry(int p){ int ret = 0; for(int i = p; i; i -= i & -i) ret += bit[i]; return ret; }
int bs(int v){ int ret = 0, s = 0; for(int j = 19; j >= 0; j--) if(ret + (1 << j) < N && s + bit[ret + (1 << j)] < v) ret += (1 << j), s += bit[ret]; return ret + 1; }
} bit;
int n;
bool a[N];
int l[N], r[N];
vector<int> S[N], T[N];
int L[20], R[20];
void rem(int x){
int sl = 0, sr = 0;
for(int y = l[x], tr = 0; y != 0 && tr < 20; tr++){
L[tr] = y; y = l[y]; sl++;
}
for(int y = r[x], tr = 0; y != n + 1 && tr < 20; tr++){
R[tr] = y; y = r[y]; sr++;
}
for(int i = sl - 1; i >= 0; i--){
if(!a[L[i]]) continue;
int v = 1;
for(int j = i - 1; j >= 0; j--){
v = v * 2 + a[L[j]];
}
// NOT choose middle
int u = v;
for(int j = 0; j < sr; j++){
u = u * 2 + a[R[j]];
if(u >= N) break;
S[u].push_back(L[i]);
}
// DOES choose middle
u = v * 2 + a[x];
if(u < N) T[u].push_back(L[i]);
// cout << "R " << u << ' ' << L[i] << endl;
for(int j = 0; j < sr; j++){
u = u * 2 + a[R[j]];
if(u >= N) break;
// cout << "ADD " << u << ' ' << L[i] << endl;
T[u].push_back(L[i]);
}
}
if(a[x]){
int u = a[x];
T[u].push_back(x);
for(int j = 0; j < sr; j++){
u = u * 2 + a[R[j]];
if(u >= N) break;
T[u].push_back(x);
}
}
bit.add(x, 1);
l[r[x]] = l[x];
r[l[x]] = r[x];
}
int len(int l){
int x = 0;
while(l){
x++;
l /= 2;
}
return x;
}
void solve(int TC) {
cin >> n;
for(int i = 0; i <= n + 1; i++){
l[i] = i - 1;
r[i] = i + 1;
}
l[0] = 0, r[n + 1] = n + 1;
string s; cin >> s;
for(int i = 1; i <= n; i++){
a[i + 1] = s[i] == '1';
}
for(int i = 1; i <= n; i++){
if(a[i] == 0) continue;
int v = 0;
for(int j = i; j < i + 20 && j <= n; j++){
v = v * 2 + a[j];
S[v].push_back(i);
}
}
// for(int l = 1; l <= n; l++){
// for(auto u : S[l]) cout << u << ' '; cout << '\n';
// }
for(int l = 1; l <= n; l++){
sort(S[l].begin(), S[l].end());
sort(T[l].begin(), T[l].end());
int cnt = S[l].size() - T[l].size();
if(cnt == 0){
cout << -1 << ' ' << 0 << '\n';
}else{
int idx = 0;
assert(cnt > 0);
// cout << "S T" << endl;
// for(auto x : S[l]) cout << x << ' '; cout << '\n';
// for(auto x : T[l]) cout << x << ' '; cout << '\n';
while(idx < T[l].size() && S[l][idx] == T[l][idx]){
++idx;
}
int pos = S[l][idx];
cout << pos - bit.qry(S[l][idx] - 1) << ' ' << cnt << '\n';
for(int j = 0; j < len(l); j++){
rem(pos); pos = r[pos];
}
}
S[l].clear(); T[l].clear();
}
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(10);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve(i);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 7ms
memory: 52760kb
input:
20 01001101101101110010
output:
2 11 5 5 4 5 11 1 4 2 7 1 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0
result:
ok 20 lines
Test #2:
score: -100
Wrong Answer
time: 338ms
memory: 140368kb
input:
1000000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
2 999999 -1 0 2 999997 -1 0 -1 0 -1 0 2 999994 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 2 999990 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 2 999985 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 ...
result:
wrong answer 1st lines differ - expected: '1 1000000', found: '2 999999'