QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#467831 | #7967. 二进制 | propane | TL | 185ms | 158064kb | C++20 | 3.9kb | 2024-07-08 17:43:22 | 2024-07-08 17:43:23 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
using LL = long long;
priority_queue<int, vector<int>, greater<int> > q[1 << 20], del[1 << 20];
int cnt[1 << 20];
int l[1 << 20], r[1 << 20];
int tr[1 << 20];
int lowbit(int x){
return x & -x;
}
void modify(int x, int v){
while(x < (1 << 20)){
tr[x] += v;
x += lowbit(x);
}
}
int query(int x){
int ans = 0;
while(x){
ans += tr[x];
x -= lowbit(x);
}
return ans;
}
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n;
string str;
cin >> n >> str;
str = " " + str;
for(int i = 1; i <= n; i++){
l[i] = i - 1;
r[i] = i + 1;
}
r[0] = 1;
l[n + 1] = n;
for(int i = 1; i <= n; i++){
modify(i, 1);
}
for(int len = 1; len <= __lg(n) + 1; len++){
int L = (1 << (len - 1)), R = min((1 << len) - 1, n);
const int mask = (1 << len) - 1;
{
int j = r[0], val = 0;
for(int _ = 0; _ + 1 < len and j <= n; _++){
val = val * 2 + str[j] - '0';
j = r[j];
}
for(int i = r[0]; j <= n; i = r[i]){
val = val * 2 + str[j] - '0';
val &= mask;
if (val >= L and val <= R){
q[val].push(i);
cnt[val] += 1;
}
j = r[j];
}
}
for(int i = L; i <= R; i++){
if (cnt[i] == 0){
cout << -1 << ' ' << 0 << '\n';
continue;
}
while(!q[i].empty() and !del[i].empty()){
int t1 = q[i].top();
int t2 = del[i].top();
if (t1 == t2){
q[i].pop();
del[i].pop();
}
}
cout << query(q[i].top()) << ' ' << cnt[i] << '\n';
// cout << query(*s[i].begin()) << ' ' << s[i].size() << '\n';
// int tt = query(*s[i].begin());
// cout << "? " << (*s[i].begin()) << ' ' << query(*s[i].begin()) << '\n';
int p1 = q[i].top();
cnt[i] -= 1;
q[i].pop();
int p2 = p1;
for(int j = 0; j < len; j++) p2 = r[p2];
int p0 = p1;
for(int j = 0; j < len and p0; j++) p0 = l[p0];
{
int k = r[p0], val = 0;
for(int _ = 0; _ + 1 < len and k <= n; _++){
val = val * 2 + str[k] - '0';
k = r[k];
}
for(int j = r[p0]; j != p2 and k <= n; j = r[j]){
val = val * 2 + str[k] - '0';
val &= mask;
if (val >= L and val <= R){
del[val].push(j);
cnt[val] -= 1;
}
k = r[k];
}
}
for(int j = p1; j != p2; j = r[j]){
modify(j, -1);
}
r[l[p1]] = p2;
l[p2] = l[p1];
{
int k = r[p0], val = 0;
for(int _ = 0; _ + 1 < len and k <= n; _++){
val = val * 2 + str[k] - '0';
k = r[k];
}
for(int j = r[p0]; j != p2 and k <= n; j = r[j]){
val = val * 2 + str[k] - '0';
val &= mask;
if (val >= L and val <= R){
q[val].push(j);
cnt[val] += 1;
}
k = r[k];
}
}
}
// for(int i = L; i <= R; i++) s[i].clear();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 69144kb
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: 0
Accepted
time: 185ms
memory: 158064kb
input:
1000000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1 1000000 -1 0 1 999998 -1 0 -1 0 -1 0 1 999995 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 1 999991 -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 999986 -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:
ok 1000000 lines
Test #3:
score: -100
Time Limit Exceeded
input:
1000000 1111111101011101110011011111111111111110110011110111011100111001011011011110101110111111111111111111111111011111101111110110111111111110111010111111100110011101101110011111111101111110111111111110111111111111011011110110111101101101110101100111111111001010111111111111010111011111111011110111...