QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#464775#7967. 二进制propane#ML 7ms53980kbC++202.7kb2024-07-06 14:48:372024-07-06 14:48:39

Judging History

你现在查看的是最新测评结果

  • [2024-07-06 14:48:39]
  • 评测
  • 测评结果:ML
  • 用时:7ms
  • 内存:53980kb
  • [2024-07-06 14:48:37]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<set>
using namespace std;
using LL = long long;
set<int> s[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++){
        int val = 0;
        if (str[i] == '1'){
            for(int j = 1; i + j - 1 <= n; j++){
                val = val * 2 + str[i + j - 1] - '0';
                if (val > n) break;
                s[val].insert(i);
            }
        }
        l[i] = i - 1;
        r[i] = i + 1;
    }
    r[0] = 1;
    l[n + 1] = n;

    auto inter = [&](int l1, int r1, int l2, int r2){
        return max(l1, l2) <= min(r1, r2);
    };

    for(int i = 1; i <= n; i++){
        modify(i, 1);
    }

    for(int i = 1; i <= n; i++){
        if (s[i].empty()){
            cout << -1 << ' ' << 0 << '\n';
            continue;
        }
        cout << query(*s[i].begin()) << ' ' << s[i].size() << '\n';
        int len = __lg(i) + 1;
        int p1 = *s[i].begin();
        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];
        for(int j = r[p0]; j != p2; j = r[j]){
            if (str[j] == '1'){
                int pt = j, val = 0;
                while(pt <= n){
                    val = val * 2 + str[pt] - '0';
                    if (val > n) break;
                    if (val > i and inter(j, pt, p1, l[p2])){
                        s[val].erase(j);
                    }
                    pt = r[pt];
                }
            }
        }
        for(int j = p1; j != p2; j = r[j]){
            modify(j, -1);
        }
        r[l[p1]] = p2;
        l[p2] = l[p1];
        for(int j = r[p0]; j != p2; j = r[j]){
            if (str[j] == '1'){
                int pt = j, val = 0;
                while(pt <= n){
                    val = val * 2 + str[pt] - '0';
                    if (val > n) break;
                    if (val > i and inter(j, pt, p2, n)){
                        s[val].insert(j);
                    }
                    pt = r[pt];
                }
            }
        }
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 53980kb

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
Memory Limit Exceeded

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: