QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#605909#8775. MountainCraftrikka_lyly#WA 4ms18716kbC++145.5kb2024-10-02 20:34:342024-10-02 20:34:35

Judging History

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

  • [2024-10-02 20:34:35]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:18716kb
  • [2024-10-02 20:34:34]
  • 提交

answer

//code_board
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double db;
typedef pair<int,int> pa;
typedef vector<int> vec;
typedef string str;

const int bias = 5;

int T = 1;




class SegmentTree {
private:
    struct Node {
        int left, right;
        int minValue, lazy;
        int minCount;
    };

    vector<Node> tree;

    int n;

    void build(int node, int start, int end) {
        tree[node].left = start;
        tree[node].right = end;
        tree[node].lazy = 0;
        tree[node].minValue = 0;
        tree[node].minCount = end - start + 1;

        if (start == end) {
            // 叶子节点
            tree[node].minValue = 0;
            tree[node].minCount = c[start + 1] - c[start];
            // cout << c[start] << " " << c[start + 1] << endl;
            // cout << "minValue: " << tree[node].minValue << " minCount: " << tree[node].minCount << " start: " << start << " end: " << end << endl;
        } else {
            int mid = (start + end) / 2;
            build(2 * node, start, mid);
            build(2 * node + 1, mid + 1, end);
            tree[node].minValue = min(tree[2 * node].minValue, tree[2 * node + 1].minValue);
            tree[node].minCount = (tree[2 * node].minValue == tree[node].minValue ? tree[2 * node].minCount : 0) +
                                  (tree[2 * node + 1].minValue == tree[node].minValue ? tree[2 * node + 1].minCount : 0);
        }
    }

    void propagate(int node) {
        if (tree[node].lazy != 0) {
            tree[node].minValue += tree[node].lazy;
            if (tree[node].left != tree[node].right) {
                tree[2 * node].lazy += tree[node].lazy;
                tree[2 * node + 1].lazy += tree[node].lazy;
            }
            tree[node].lazy = 0;
        }
    }

    void updateRange(int node, int start, int end, int l, int r, int val) {
        propagate(node);

        if (start > r || end < l) {
            return;
        }

        if (start >= l && end <= r) {
            tree[node].lazy += val;
            propagate(node);
            return;
        }

        int mid = (start + end) / 2;
        updateRange(2 * node, start, mid, l, r, val);
        updateRange(2 * node + 1, mid + 1, end, l, r, val);

        tree[node].minValue = min(tree[2 * node].minValue, tree[2 * node + 1].minValue);
        tree[node].minCount = (tree[2 * node].minValue == tree[node].minValue ? tree[2 * node].minCount : 0) +
                              (tree[2 * node + 1].minValue == tree[node].minValue ? tree[2 * node + 1].minCount : 0);
    }

    pair<int, int> queryRange(int node, int start, int end, int l, int r) {
        propagate(node);

        if (start > r || end < l) {
            return {INT_MAX, 0};
        }

        if (start >= l && end <= r) {
            return {tree[node].minValue, tree[node].minCount};
        }

        int mid = (start + end) / 2;
        auto leftQuery = queryRange(2 * node, start, mid, l, r);
        auto rightQuery = queryRange(2 * node + 1, mid + 1, end, l, r);

        if (leftQuery.first == rightQuery.first) {
            return {leftQuery.first, leftQuery.second + rightQuery.second};
        } else if (leftQuery.first < rightQuery.first) {
            return leftQuery;
        } else {
            return rightQuery;
        }
    }

public:
    vec c;
    SegmentTree(int size) { 
        n = size;
        tree.resize(4 * n);
    }
    
    void init(int size){
        n = size;
        build(1, 0, n - 1);
    }

    void updateRange(int l, int r, int val) {
        updateRange(1, 0, n - 1, l, r, val);
    }

    pair<int, int> queryRange(int l, int r) {
        return queryRange(1, 0, n - 1, l, r);
    }
}Tree(200005);

map<pa,int> mp;


void solve(){
    int n, p;
    cin >> n >> p;
    // Tree.init();
    vector<pa> query(n);
    
    for(int i = 0, a, b; i < n; i++){
        cin >> a >> b;
        int L = max(0, a - b);
        int R = min(p, a + b);
        query[i] = {L, R};
        Tree.c.push_back(L);
        Tree.c.push_back(R);
    }
    Tree.c.push_back(0);
    Tree.c.push_back(p);
    sort(Tree.c.begin(), Tree.c.end());
    Tree.c.erase(unique(Tree.c.begin(), Tree.c.end()), Tree.c.end());
    for(int i = 0; i < query.size(); i++){
        query[i].first = lower_bound(Tree.c.begin(), Tree.c.end(), query[i].first) - Tree.c.begin();
        query[i].second = lower_bound(Tree.c.begin(), Tree.c.end(), query[i].second) - Tree.c.begin();
        // cout << "query: " << query[i].first << " " << query[i].second << endl;
    }

    Tree.init(Tree.c.size() - 1);

    for(int i = 0; i < n; i++){
        if(mp[query[i]] == 0){
            mp[query[i]]++;
            Tree.updateRange(query[i].first, query[i].second - 1, 1);
        }else{
            mp[query[i]]--;
            Tree.updateRange(query[i].first, query[i].second - 1, -1);
        }
        // cout << query[i].first << " " << query[i].second << endl;
        auto ans = Tree.queryRange(0, Tree.c.size() - 2);
        // cout << "ans: " << ans.first << " " << ans.second << endl;
        ans.second = (ans.first == 0)? p - ans.second : p;
        cout << fixed << setprecision(10) << (db) ans.second * sqrt(2) << endl;
    }
}


int main(){

//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);    
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    // cin >> T;
    while(T--) solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 18716kb

input:

3 10
3 2
7 3
9 6

output:

5.6568542495
12.7279220614
12.7279220614

result:

ok 3 numbers

Test #2:

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

input:

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

output:

101.8233764909
120.2081528017
73.5391052434
0.0000000000
101.8233764909

result:

ok 5 numbers

Test #3:

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

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.3137084990
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.1421356237
12.7279220614
14.1421356237
14.1421356237
14.1421356237
0.0000000000
8.4852813742
12.7279220614
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.14213...

result:

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