QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#733274#8775. MountainCraft_DioWA 1ms4088kbC++172.7kb2024-11-10 18:03:182024-11-10 18:03:20

Judging History

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

  • [2024-11-10 18:03:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4088kb
  • [2024-11-10 18:03:18]
  • 提交

answer

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

struct node {
    int l, r, num, sum = 0;
    int ll, rr;
};

signed main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int,int> > a(n + 1);
    set<int> s;
    s.insert(0);
    s.insert(m);
    for (int i = 1; i <= n; i++) {
        cin >> a[i].first >> a[i].second;
        s.insert(max(a[i].first - a[i].second, 0ll));
        s.insert(min(a[i].first + a[i].second, m));
    }
    vector<int> b;
    b.push_back(-1);
    for (auto &i: s)
        b.push_back(i);
    int N = b.size() - 1;
    vector<node> c(4 * N + 1);
    function<void(int,int,int)> init = [&](int k,int l,int r)-> void {
        if (l == r) {
            c[k].l = c[k].r = b[l];
            return;
        }
        int mid = (l + r) >> 1;
        init(k << 1, l, mid);
        init(k << 1 | 1, mid + 1, r);
        c[k].l = c[k << 1].l;
        c[k].r = c[k << 1 | 1].r;
    };
    init(1, 1, N);

    function<void(int,int,int,int,int,int z)> add = [&](int k,int l,int r,int x,int y,int z)-> void {
        if (l == x && r == y) {
            c[k].num += z;
            if (c[k].num) {
                c[k].sum = c[k].r - c[k].l;
                c[k].ll = c[k].rr = 1;
                return;
            } else if(l==r){
                c[k].sum = 0;
                c[k].ll = c[k].rr = 0;
                return ;
            }

        }
        if(c[k].ll&&c[k].rr) {
            c[k<<1].num+=c[k].num;
            c[k<<1|1].num+=c[k].num;
            c[k<<1].ll=c[k<<1].rr=c[k<<1|1].ll=c[k<<1|1].rr=1;
        }
        int mid = (l + r) >> 1;
        if (y <= mid) {
            add(k << 1, l, mid, x, y, z);
        } else if (x > mid) {
            add(k << 1 | 1, mid + 1, r, x, y, z);
        } else {
            add(k << 1, l, mid, x, mid, z);
            add(k << 1 | 1, mid + 1, r, mid + 1, y, z);
        }
        c[k].sum = c[k << 1].sum + c[k << 1 | 1].sum;
        if (c[k << 1].rr && c[k << 1 | 1].ll) {
            c[k].sum += c[k << 1 | 1].l - c[k << 1].r;
        }
        c[k].ll = c[k << 1].ll;
        c[k].rr = c[k << 1 | 1].rr;
    };
    cout<<fixed<<setprecision(10);
    map<pair<int,int>,int> mp;
    for (int i = 1; i <= n; i++) {
        mp[a[i]]++;
        int ll = lower_bound(b.begin(), b.end(), max(a[i].first - a[i].second, 0ll)) - b.begin();
        int rr = lower_bound(b.begin(), b.end(), min(a[i].first + a[i].second, m)) - b.begin();
        // cout<<ll<<" "<<rr<<" "<<a[i].first<<" "<<a[i].second<<endl;
        if (mp[a[i]] & 1)
            add(1, 1, N, ll, rr, 1);
        else
            add(1, 1, N, ll, rr, -1);
        cout << c[1].sum * sqrt(2) << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3992kb

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: 0
Accepted
time: 0ms
memory: 3796kb

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
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.1421356237
14.142...

result:

ok 100 numbers

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 4088kb

input:

1000 100
95 8
54 8
64 96
47 34
77 47
99 91
45 70
8 6
64 84
48 42
53 14
73 66
38 27
6 52
19 75
33 39
6 24
37 80
27 45
96 48
55 95
67 1
23 78
40 4
76 7
77 22
4 47
41 31
60 54
96 37
79 52
63 40
7 92
17 7
74 12
93 16
87 5
67 43
60 29
71 58
52 41
53 84
38 2
46 87
13 54
54 14
16 93
57 7
91 98
31 23
70 3
9...

output:

18.3847763109
41.0121933088
141.4213562373
118.7939392393
120.2081528017
132.9360748631
141.4213562373
128.6934341760
141.4213562373
128.6934341760
117.3797256770
138.5929291126
121.6223663641
123.0365799265
134.3502884254
131.5218613007
131.5218613007
141.4213562373
131.5218613007
132.9360748631
14...

result:

wrong answer 4th numbers differ - expected: '141.4213562', found: '118.7939392', error = '0.1600000'