萌新 100pts 求助

P4097 【模板】李超线段树 / [HEOI2013] Segment

wangyibo201026 @ 2023-01-14 11:42:53

Subtask 0 的第 7 个点过不去,不知道是哪里 WA 了:

#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 2e5 + 5;
const double eps = 1e-9;

int n, cnt, lastans;

struct Line{
  double k, b;
  int st, ed;
}a[N];

double pf(int x, int id){
  return (a[id].st <= x && x <= a[id].ed ? a[id].k * x + a[id].b : -1145141919.00);
}

void add(int x0, int y0, int x1, int y1){
  ++cnt;
  if(x0 == x1){
    a[cnt].k = 0.00;
    a[cnt].b = max(y0, y1) * 1.00;
    a[cnt].st = a[cnt].ed = 0;
  }
  else{
    a[cnt].k = (double)(y1 - y0) / (double)(x1 - x0);
    a[cnt].b = y0 - a[cnt].k * x0;
    a[cnt].st = x0;
    a[cnt].ed = x1;
  }
}

int tree[N << 2];

pair<double, int> Max(pair<double, int> a, pair<double, int> b){
  return (a.first - b.first > eps ? a : (b.first - a.first > eps ? b : a.second < b.second ? a : b));
}

void update(int node, int lt, int rt, int x, int y, int k){
  if(x > rt || y < lt){
    return ;
  }
  if(x <= lt && rt <= y){
    if(!tree[node]){
      tree[node] = k;
      return ;
    }
    int mid = lt + rt >> 1;
    if(pf(mid, k) - pf(mid, tree[node]) > eps){
      swap(k, tree[node]);
    }
    if(pf(lt, k) - pf(lt, tree[node]) > eps || pf(lt, k) == pf(lt, tree[node]) && k < tree[node]){
      update(node << 1, lt, mid, x, y, k);
    }
    if(pf(rt, k) - pf(rt, tree[node]) > eps || pf(rt, k) == pf(rt, tree[node]) && k < tree[node]){
      update(node << 1 | 1, mid + 1, rt, x, y, k);
    }
    return ;
  }
  int mid = lt + rt >> 1;
  update(node << 1, lt, mid, x, y, k);
  update(node << 1 | 1, mid + 1, rt, x, y, k);
}

pair<double, int> query(int node, int lt, int rt, int x){
  if(rt < x || lt > x){
    return make_pair(0.00, 0);
  }
  double res = pf(x, tree[node]);
  if(lt == rt){
    return make_pair(res, tree[node]);
  }
  int mid = lt + rt >> 1;
  return Max(make_pair(res, tree[node]), Max(query(node << 1, lt, mid, x), query(node << 1 | 1, mid + 1, rt, x)));
}

void Solve(){
  cin >> n;
  for(int i = 1; i <= n; i++){
    int op;
    cin >> op;
    if(!op){
      int k;
      cin >> k;
      k = (k + lastans - 1 + 39989) % 39989 + 1;
      cout << (lastans = query(1, 1, 39989, k).second) << '\n';
    }
    else{
      int x0, y0, x1, y1;
      cin >> x0 >> y0 >> x1 >> y1;
      x0 = (x0 + lastans - 1 + 39989) % 39989 + 1, y0 = (y0 + lastans - 1 + 1000000000) % 1000000000 + 1;
      x1 = (x1 + lastans - 1 + 39989) % 39989 + 1, y1 = (y1 + lastans - 1 + 1000000000) % 1000000000 + 1;
      if(x0 > x1){
        swap(x0, x1);
        swap(y0, y1);
      }
      add(x0, y0, x1, y1);
      update(1, 1, 39989, x0, x1, cnt);
    }
  }
}

signed main(){
    Solve();
    return 0;
}

by wangyibo201026 @ 2023-01-14 11:45:05

7 个点的数据:

3
1 1 1 1 2
1 1 1 1 3
0 1

2

by niTMDsb @ 2023-01-14 11:45:31

《红名绿√》《萌新》


by wangyibo201026 @ 2023-01-14 11:46:17

这个数据点有点诡异


by wangyibo201026 @ 2023-01-14 11:50:33

已调出,死因:

a[cnt].st = a[cnt].ed = 0;

应改为:

a[cnt].st = a[cnt].ed = x0;

这里给所有写错的人一个警钟,此帖完结。


by 18974918693mzx @ 2023-01-14 11:51:10

@Alexande nb


|