QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#589735 | #8775. MountainCraft | microwave173 | WA | 6ms | 42668kb | C++20 | 4.4kb | 2024-09-25 19:56:26 | 2024-09-25 19:56:28 |
Judging History
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: 100
Accepted
time: 3ms
memory: 42668kb
input:
3 10 3 2 7 3 9 6
output:
5.6568542494923805819 12.727922061357856975 12.727922061357856975
result:
ok 3 numbers
Test #2:
score: 0
Accepted
time: 5ms
memory: 38956kb
input:
5 100 31 41 59 26 31 41 59 26 31 41
output:
101.8233764908628558 120.20815280171308359 73.539105243400953782 0 101.8233764908628558
result:
ok 5 numbers
Test #3:
score: -100
Wrong Answer
time: 6ms
memory: 42192kb
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.313708498984761164 14.142135623730951011 14.142135623730951011 14.142135623730951011 14.142135623730951011 14.142135623730951011 14.142135623730951011 14.142135623730951011 14.142135623730951011 12.727922061357856975 14.142135623730951011 14.142135623730951011 14.142135623730951011 0 8.4852813742...
result:
wrong answer 10th numbers differ - expected: '14.1421356', found: '12.7279221', error = '0.1000000'