QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#615312 | #7967. 二进制 | yzj123# | TL | 4ms | 57036kb | C++20 | 4.1kb | 2024-10-05 18:04:58 | 2024-10-05 18:04:59 |
Judging History
answer
#include <bits/stdc++.h>
#define ls(v) v << 1
#define rs(v) v << 1 | 1
using namespace std;
int read()
{
int res = 0, bj = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-') bj = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
res = res * 10 + ch - '0';
ch = getchar();
}
return res * bj;
}
const int MAXN = 1e6 + 5;
int n;
int a[MAXN];
char s[MAXN];
set<int> pos[MAXN];
int nxt[MAXN], pre[MAXN];
int vis[MAXN];
int sum[MAXN * 4];
void pushup(int v)
{
sum[v] = sum[ls(v)] + sum[rs(v)];
}
void pushdown(int v)
{
if (sum[v] == 0) sum[ls(v)] = sum[rs(v)] = 0;
}
void build(int v, int l, int r)
{
if (l == r)
{
sum[v] = 1;
return;
}
int mid = l + r >> 1;
build(ls(v), l, mid);
build(rs(v), mid + 1, r);
pushup(v);
}
void add(int v, int l, int r, int ql, int qr)
{
if (l > qr || r < ql) return;
if (l >= ql && r <= qr)
{
sum[v] = 0;
return;
}
int mid = l + r >> 1;
pushdown(v);
add(ls(v), l, mid, ql, qr);
add(rs(v), mid + 1, r, ql, qr);
pushup(v);
}
int ask(int v, int l, int r, int ql, int qr)
{
if (l > qr || r < ql) return 0;
if (l >= ql && r <= qr) return sum[v];
int mid = l + r >> 1;
pushdown(v);
int res1 = ask(ls(v), l, mid, ql, qr), res2 = ask(rs(v), mid + 1, r, ql, qr);
return res1 + res2;
}
int main()
{
n = read();
build(1, 1, n);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) nxt[i] = i + 1, pre[i] = i - 1;
nxt[n] = 0;
for (int i = 1; i <= n; i++)
{
int x = 0;
if (s[i] != '0')
{
for (int j = 1; j <= 20 && i + j - 1 <= n; j++)
{
x = x * 2 + s[i + j - 1] - '0';
// cout << "x:" << i << " " << i + j - 1 << " " << x << "\n";
if (x <= n) pos[x].insert(i);
else break;
}
}
}
// for (int i = 1; i <= 10; i++)
// {
// cout << "pos " << i << ": ";
// for (auto x : pos[i]) cout << x << " ";
// cout << "\n";
// }
for (int i = 1; i <= n; i++)
{
// cout << "i:" << i << "\n";
int d = 0, tp = i;
while (tp) d++, tp /= 2;
if (pos[i].size())
{
int st = *(pos[i].begin()), p = st;
cout << ask(1, 1, n, 1, st) << " " << pos[i].size();
cout << "\n";
// cout << " " << d << "\n";
// vis[p] = 1;
// for (int j = 1; j < d; j++) p = nxt[p], vis[p] = 1;
// p = st;
// for (int j = 1; j < 20 && pre[p] != 0; j++)
// {
// p = pre[p];
// int x = 0, l = p;
// for (int k = 1; k <= 20 && l != 0; k++)
// {
// x = x * 10 + s[l] - '0';
// if (vis[l]) pos[x].erase(p);
// l = nxt[l];
// }
// }
// p = st;
// for (int j = 1; j <= d; j++)
// {
// int x = 0, l = p;
// for (int k = 1; k <= d && l != 0; k++)
// {
// x = x * 10 + s[l] - '0';
// pos[x].erase(p);
// l = nxt[l];
// }
// p = nxt[p];
// }
for (int j = 1; j < d; j++) p = nxt[p];
int ed = p;
add(1, 1, n, st, ed);
//向前跳19步
p = st;
for (int j = 1; j < 20 && pre[p] != 0; j++) p = pre[p];
// cout << "step1:" << p << " " << ed << "\n";
int st2 = p, ed2 = pre[st];
while (1)
{
int x = 0, l = p;
if (s[p] != '0')
{
for (int j = 1; j <= 20 && l != 0; j++)
{
x = x * 2 + s[l] - '0';
if (x <= n) pos[x].erase(p);
else break;
l = nxt[l];
}
}
if (p == ed) break;
p = nxt[p];
}
// cout << "ed2:" << ed2 << " " << nxt[ed] << "\n";
nxt[ed2] = nxt[ed];
pre[nxt[ed]] = st2;
p = st2;
if (p != 0)
{
// cout << "step2:" << p << " " << ed2 << "\n";
while (1)
{
int x = 0, l = p;
if (s[p] != '0')
{
for (int j = 1; j <= 20 && l != 0; j++)
{
x = x * 2 + s[l] - '0';
// cout << "x:" << p << " " << l << " " << x << "\n";
if (x <= n) pos[x].insert(p);
else break;
l = nxt[l];
}
}
if (p == ed2) break;
p = nxt[p];
}
}
}
else cout << -1 << " " << 0 << "\n";
// for (int i = 1; i <= 10; i++)
// {
// cout << "pos " << i << ": ";
// for (auto x : pos[i]) cout << x << " ";
// cout << "\n";
// }
// cout << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 57036kb
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
Time Limit Exceeded
input:
1000000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...