QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#591421#8775. MountainCraftpikakaWA 0ms4060kbC++174.4kb2024-09-26 15:52:362024-09-26 15:52:56

Judging History

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

  • [2024-09-26 15:52:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4060kb
  • [2024-09-26 15:52:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

template<class Info, class Tag>
struct SegmentTree {
    int n;
    vector<Info> info;
    vector<Tag> tag;
    SegmentTree() : n(0) {}
    SegmentTree(int n_, Info v_ = Info()) {
        init(n_, v_);
    }
    template<class T>
    SegmentTree(vector<T> init_) {
        init(init_);
    }
    void init(int n_, Info v_ = Info()) {
        init(vector<Info>(n_, v_));
    }
    template<class T>
    void init(vector<T> init_) {
        n = init_.size();
        info.assign(4 << __lg(n), Info());
        tag.assign(4 << __lg(n), Tag());
        function<void(int, int, int)> build = [&](int p, int l, int r) {
            if (r - l == 1) {
                info[p] = init_[l];
                return;
            }
            int m = (l + r) / 2;
            build(2 * p, l, m);
            build(2 * p + 1, m, r);
            pull(p);
        };
        build(1, 0, n);
    }
    void pull(int p) {
        info[p] = info[2 * p] + info[2 * p + 1];
    }
    void apply(int p, const Tag &v) {
        info[p].apply(v);
        tag[p].apply(v);
    }
    void push(int p) {
        apply(2 * p, tag[p]);
        apply(2 * p + 1, tag[p]);
        tag[p] = Tag();
    }
    void modify(int p, int l, int r, int x, const Info &v) {
        if (r - l == 1) {
            info[p] = v;
            return;
        }
        int m = (l + r) / 2;
        push(p);
        if (x < m) {
            modify(2 * p, l, m, x, v);
        } else {
            modify(2 * p + 1, m, r, x, v);
        }
        pull(p);
    }
    void modify(int p, const Info &v) {
        modify(1, 0, n, p, v);
    }
    Info query(int p, int l, int r, int x, int y) {
        if (l >= y || r <= x) {
            return Info();
        }
        if (l >= x && r <= y) {
            return info[p];
        }
        int m = (l + r) / 2;
        push(p);
        return query(2 * p, l, m, x, y) + query(2 * p + 1, m, r, x, y);
    }
    Info query(int l, int r) {
        return query(1, 0, n, l, r);
    }
    void update(int p, int l, int r, int x, int y, const Tag &v) {
        if (l >= y || r <= x) {
            return;
        }
        if (l >= x && r <= y) {
            apply(p, v);
            return;
        }
        int m = (l + r) / 2;
        push(p);
        update(2 * p, l, m, x, y, v);
        update(2 * p + 1, m, r, x, y, v);
        pull(p);
    }
    void update(int l, int r, const Tag &v) {
        return update(1, 0, n, l, r, v);    
    }
};

struct Tag {
    int add = 0;
    void apply(Tag t) {
        add += t.add;
    }
};

struct Info {
    int mi = 0;
    int cnt = 0;
    void apply(Tag t) {
        mi += t.add;
    }
};

Info operator+(const Info &a, const Info &b) {
    if (a.mi < b.mi) {
        return a;
    } else if (a.mi > b.mi) {
        return b;
    } else {
        return {a.mi, a.cnt + b.cnt};
    }
}

using S = SegmentTree<Info, Tag>;


void solve() {
    int q, R;
    cin >> q >> R;
    vector<int> l(q), r(q);
    vector<int> a{0, R};
    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        l[i] = x - y;
        r[i] = x + y;
        l[i] = max(0, l[i]);
        r[i] = min(r[i], R);
        a.emplace_back(l[i]);
        a.emplace_back(r[i]);
    }
    sort(a.begin(), a.end());
    int m = unique(a.begin(), a.end()) - a.begin();
    a.resize(m);

    S t(m);
    set<pair<int, int>> st;
    for (int i = 1; i < m; i++) {
        t.modify(i - 1, {0, a[i] - a[i - 1]});
    }

    for (int i = 0; i < q; i++) {
        int x = (l[i] + r[i]) / 2;
        int y = (r[i] - l[i]) / 2;
        int cl = lower_bound(a.begin(), a.end(), l[i]) - a.begin();
        int cr = lower_bound(a.begin(), a.end(), r[i]) - a.begin();
        if (st.count({x, y})) {
            st.erase({x, y});
            t.update(cl, cr, {-1});
        } else {
            st.emplace(x, y);
            t.update(cl, cr, {1});
        }
        Info info = t.query(0, m);
        int res = R;
        // cerr << info.mi << " " << info.cnt << "\n";
        // cerr << a[cl] << " " << a[cr] << "\n";
        if (info.mi == 0) {
            res = R - info.cnt;
        }
        double t = sqrt(2);
        cout << fixed << setprecision(6) << res * t << "\n";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 4044kb

input:

3 10
3 2
7 3
9 6

output:

5.656854
12.727922
12.727922

result:

ok 3 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 3760kb

input:

5 100
31 41
59 26
31 41
59 26
31 41

output:

101.823376
120.208153
73.539105
0.000000
101.823376

result:

ok 5 numbers

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 4060kb

input:

100 10
6 4
2 3
7 6
5 5
3 6
7 5
5 8
10 4
9 8
0 9
9 10
9 3
2 3
10 10
8 4
10 9
0 1
1 7
0 2
3 4
10 3
3 10
7 4
7 5
1 4
0 7
1 9
5 6
8 8
7 4
8 1
3 9
2 1
5 5
2 1
10 9
8 4
0 9
10 7
4 1
9 10
8 6
5 4
1 4
0 9
9 3
4 8
5 10
7 2
8 10
7 10
3 4
2 2
8 5
0 9
5 3
1 4
6 4
0 3
8 1
1 6
3 8
8 4
6 5
10 2
2 2
8 4
6 1
2 4
6 4...

output:

11.313708
14.142136
14.142136
14.142136
14.142136
14.142136
14.142136
14.142136
14.142136
12.727922
14.142136
14.142136
14.142136
0.000000
8.485281
12.727922
14.142136
14.142136
14.142136
14.142136
14.142136
14.142136
14.142136
14.142136
14.142136
14.142136
14.142136
14.142136
14.142136
14.142136
14...

result:

wrong answer 10th numbers differ - expected: '14.1421356', found: '12.7279220', error = '0.1000000'