QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#589730#8775. MountainCraftmicrowave173WA 0ms42708kbC++204.4kb2024-09-25 19:55:262024-09-25 19:55:26

Judging History

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

  • [2024-09-25 19:55:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:42708kb
  • [2024-09-25 19:55:26]
  • 提交

answer

#include<iostream>
#include<set>
#include<utility>
#include<vector>
#include<map>
#include<math.h>
#include<iomanip>
using namespace std;
int q, w;
int x[200005];
int y[200005];
set<int> st1, st2;
map<int, int> x_2_id[2];
map<int, int> id_2_x[2];

struct Node{
    int l, r, sum, tag;
};

struct Tree{
    Node node[1200002];
    int flag = 0;

    void push_up(int p, int r){
        if(node[p].tag > 0){
            int id = p;
            // node[id].sum = node[id].r - node[id].l + 1;
            node[id].sum = id_2_x[flag][node[id].r + 1] - id_2_x[flag][node[id].l];
            if(node[id].r == r) node[id].sum -= (id_2_x[flag][node[id].r + 1] - id_2_x[flag][node[id].r] - 1);
            // cout << id_2_x[flag][node[id].l] << ',' << id_2_x[flag][node[id].r] << endl;
        }
        else if(node[p].l < node[p].r){
            node[p].sum = node[p * 2].sum + node[p * 2 + 1].sum;
        }
        else{
            node[p].sum = 0;
        }
        // if(node[p].tag <= 0) node[p].sum = 0;
        // cout << node[p].l << "," << node[p].r << ' ' << node[p].sum << endl;
    }

    void build(int id, int l, int r){
        node[id].l = l;
        node[id].r = r;
        // node[id].sum = (id_2_x[flag][r] - id_2_x[flag][l] + 1);
        node[id].sum = 0;
        node[id].tag = 0;
        if(l == r){
            return;
        }
        int mid = (l + r) / 2;
        build(id * 2, l, mid);
        build(id * 2 + 1, mid + 1, r);
    }

    void add(int id, int l, int r, int num){
        if(id == 1) cout << id_2_x[flag][l] << ',' << id_2_x[flag][r] << endl;
        if(node[id].r < l || node[id].l > r) return;
        if(node[id].l >= l && node[id].r <= r){
            node[id].tag += num;
            push_up(id, r);
            // cout << id << ' ' << ' ' << node[id].l << "," << node[id].r << ' ' << node[id].sum << ' ' << node[id].tag << endl;
            return;
        }
        add(id * 2, l, r, num);
        add(id * 2 + 1, l, r, num);
        push_up(id, r);
    }
};

Tree tree1, tree2;

void solve(){
    double sqrt2 = sqrt(2.0);
    set<pair<int, int> > st_p;
    for(int i = 0;i < q;i++){
        int x1[2] = {max(x[i] - y[i], 0), min(x[i] + y[i], w)};
        int x2[2] = {-1, -1};
        if(y[i] > w){
            x2[0] = max(x[i] - (y[i] - w), 0);
            x2[1] = min(x[i] + (y[i] - w), w);
        }
        st1.insert(x1[0]);
        st1.insert(x1[1]);
        st2.insert(x2[0]);
        st2.insert(x2[1]);
        st1.insert(x1[0] - 1);
        st1.insert(x1[1] - 1);
        st2.insert(x2[0] - 1);
        st2.insert(x2[1] - 1);
    }
    st1.insert(0);
    st1.insert(w);
    st1.insert(w - 1);
    st2.insert(0);
    st2.insert(w);
    st2.insert(w - 1);
    st1.insert(w + 1);
    st2.insert(w + 1);
    int id = 0;
    for(int x : st1){
        x_2_id[0][x] = id;
        id_2_x[0][id] = x;
        id++;
    }
    id = 0;
    for(int x : st2){
        x_2_id[1][x] = id;
        id_2_x[1][id] = x;
        id++;
    }
    // for(int i = 0;i < 20;i++) cout << i << ": " << id_2_x[0][i] << endl;
    tree1.flag = 0;
    tree2.flag = 1;
    tree1.build(1, 0, 400002);
    tree2.build(1, 0, 400002);
    for(int i = 0;i < q;i++){
        int x1[2] = {max(x[i] - y[i], 0), min(x[i] + y[i], w)};
        int x2[2] = {-1, -1};
        if(y[i] > w){
            x2[0] = max(x[i] - (y[i] - w), 0);
            x2[1] = min(x[i] + (y[i] - w), w);
        }
        int flag;
        if(st_p.count(pair<int, int>(x1[0], x1[1])) > 0){
            st_p.erase(pair<int, int>(x1[0], x1[1]));
            flag = -1;
        }
        else{
            st_p.insert(pair<int, int>(x1[0], x1[1]));
            flag = 1;
        }
        tree1.add(1, x_2_id[0][x1[0]], x_2_id[0][x1[1] - 1], flag);
        if(x2[0] >= 0) tree2.add(1, x_2_id[1][x2[0]], x_2_id[1][x2[1] - 1], flag);
        int temp = tree1.node[1].sum - tree2.node[1].sum;
        double ans = (double) temp * sqrt2;
        // cout << "#";
        cout << setprecision(20) << ans << '\n';
    }
}

void test(){
    Tree tree;
    tree.build(1, 0, 10);
    while(1){
        int l, r, flag;
        cin >> l >> r >> flag;
        tree.add(1, l, r, flag);
        cout << tree.node[1].sum << endl;
    }
}

int main(){
    // test();
    // return 0;
    cin >> q >> w;
    for(int i = 0;i < q;i++){
        cin >> x[i] >> y[i];
    }
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 42708kb

input:

3 10
3 2
7 3
9 6

output:

1,4
5.6568542494923805819
4,9
12.727922061357856975
3,9
12.727922061357856975

result:

wrong output format Expected double, but "1,4" found