QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#303818#7862. Land TradeckisekiAC ✓145ms14532kbC++207.8kb2024-01-13 00:38:032024-01-13 00:38:05

Judging History

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

  • [2024-01-13 00:38:05]
  • 评测
  • 测评结果:AC
  • 用时:145ms
  • 内存:14532kb
  • [2024-01-13 00:38:03]
  • 提交

answer

#pragma GCC optimize("Ofast")
// #pragma GCC target("arch=skylake")

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

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
#include <experimental/iterator>
void debug_(auto s, auto ...a) {
  cerr << "\e[1;32m(" << s << ") = (";
  int f = 0;
  (..., (cerr<< (f++ ? ", " : "") << a));
  cerr << ")\e[0m\n";
}
void orange_(auto s, auto L, auto R) {
  cerr << "\e[1;33m[ " << s << " ] = [ ";
  using namespace experimental;
  copy(L, R, make_ostream_joiner(cerr, ", "));
  cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

namespace {

#define IM imag
#define RE real

using lld = int64_t;
using llf = double;
using PF = complex<llf>;
using P = PF;

const llf eps = 1e-9;
int sgn(lld x) { return (x > 0) - (x < 0); }
int sgn(int x) { return (x > 0) - (x < 0); }
int sgn(llf x) { return (x > eps) - (x < -eps); }

llf cross(P a, P b) { return IM(conj(a) * b); }
int ori(P a, P b, P c) {
  return sgn(cross(b - a, c - a));
}

int quad(P p) {
  return (sgn(IM(p)) == 0)
    ? (sgn(RE(p)) < 0 ? 3 : 1) : (sgn(IM(p)) < 0 ? 0 : 2);
}
int argCmp(P a, P b) {
  int qa = quad(a), qb = quad(b);
  if (qa != qb) return sgn(qa - qb);
  return sgn(cross(b, a));
}

template <typename V> llf area(const V &pt) {
  llf ret = 0;
  for (int i = 1; i + 1 < (int)pt.size(); i++)
    ret += cross(pt[i] - pt[0], pt[i + 1] - pt[0]);
  return ret / 2.0;
}

struct Line {
  P st, ed, dir;
  Line (P s, P e) : st(s), ed(e), dir(e - s) {}
  Line rev() const {
    return Line(ed, st);
  }
};
using LN = const Line &;

PF intersect(LN A, LN B) {
  llf t = cross(B.st - A.st, B.dir) / llf(cross(A.dir, B.dir));
  return A.st + A.dir * t;
}

bool cov(LN l, LN A, LN B) {
  llf u = cross(B.st - A.st, B.dir);
  llf v = cross(A.dir, B.dir);

  llf x = RE(A.dir) * u + RE(A.st - l.st) * v;
  llf y = IM(A.dir) * u + IM(A.st - l.st) * v;
  return sgn(x * IM(l.dir) - y * RE(l.dir)) * sgn(v) >= 0;
}
bool operator<(LN a, LN b) {
  if (int c = argCmp(a.dir, b.dir)) return c == -1;
  return ori(a.st, a.ed, b.st) < 0;
}

bool HPI(vector<Line> &q, bool flag) {
  if (!flag) {
    sort(q.begin(), q.end());
  } else {
    auto l = q.back(); q.pop_back();
    auto it = lower_bound(q.begin(), q.end(), l);
    q.insert(it, l);
  }

  int n = (int)q.size(), l = 0, r = -1;
  for (int i = 0; i < n; i++) {
    if (i && !argCmp(q[i].dir, q[i-1].dir)) continue;
    while (l < r && cov(q[i], q[r-1], q[r])) --r;
    while (l < r && cov(q[i], q[l], q[l+1])) ++l;
    q[++r] = q[i];
  }
  while (l < r && cov(q[l], q[r-1], q[r])) --r;
  while (l < r && cov(q[r], q[l], q[l+1])) ++l;
  n = r - l + 1;
  if (n <= 1 || !argCmp(q[l].dir, q[r].dir)) {
    return false;
  }
  vector<PF> pt(n);
  for (int i = 0; i < n; i++)
    pt[i] = intersect(q[i + l], q[(i + 1) % n + l]);
  if (area(pt) < eps)
    return false;
  q = vector(q.begin() + l, q.begin() + r + 1);

  return true;
}

const int maxn = 50025;

struct node {
  node *lc, *rc;
  char op;
  int atomic_id;
  //~node() {
  //  delete lc;
  //  delete rc;
  //  lc = rc = 0;
  //}

  bitset<maxn> evaluate(const vector<bitset<maxn>> &s) {
    switch (op) {
      case '\0':
        return s[atomic_id];
      case '&':
        return lc->evaluate(s) & rc->evaluate(s);
      case '|':
        return lc->evaluate(s) | rc->evaluate(s);
      case '^':
        return lc->evaluate(s) ^ rc->evaluate(s);
      case '!':
        return ~lc->evaluate(s);
      default:
        __builtin_unreachable();
    }
  }
};

int atomid;
vector<Line> all_lines;

Line make_line(array<int, 3> v) {
  auto [a, b, c] = v;
  P dir(b, -a);
  P st(-c * a / llf(a * a + b * b), -c * b / llf(a * a + b * b));
  return Line(st, st + dir);
}

node *parse(const string &s, int &ptr) {
  array<int, 3> v;
  switch (s[ptr++]) {
    case '(':
    if (s[ptr] == '!') {
      ++ptr;
      node *lc = parse(s, ptr);
      assert(s[ptr++] == ')');
      if (lc->op == '!')
        return lc->lc;
      return new node(lc, nullptr, '!', -1);
    } else {
      node *lc = parse(s, ptr);
      char op = s[ptr++];
      node *rc = parse(s, ptr);
      assert(s[ptr++] == ')');
      return new node(lc, rc, op, -1);
    }

    case '[':
      for (int j = 0; j < 3; j++) {
        string decimal;
        while (s[ptr] != ',' && s[ptr] != ']') {
          decimal += s[ptr++];
        }
        v[j] = stoi(decimal);
        debug(v[j]);

        if (j < 2)
          assert(s[ptr++] == ',');
        else
          assert(s[ptr++] == ']');
      }
      all_lines.emplace_back(make_line(v));

      return new node(nullptr, nullptr, '\0', atomid++);

    default:
      __builtin_unreachable();
  };
  __builtin_unreachable();
}


struct Region {
  vector<P> p;
  bitset<500> value;
  // vector<int> value;
};

using P = PF;
vector<P> cut(const vector<P> &poly, P s, P e) {
  vector<P> res;
  for (size_t i = 0; i < poly.size(); i++) {
    P cur = poly[i], prv = i ? poly[i - 1] : poly.back();
    bool side = ori(s, e, cur) < 0;
    if (side != (ori(s, e, prv) < 0))
      res.push_back(intersect({s, e}, {cur, prv}));
    if (side)
      res.push_back(cur);
  }
  return res;
}

}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);

  int xmin, xmax, ymin, ymax;
  cin >> xmin >> xmax >> ymin >> ymax;

  string s;
  cin >> s;
  int ptr = 0;
  node *root = parse(s, ptr);


  vector<Region> regions;
  {
    // vector<Line> frame;
    bitset<500> v;
    const vector<P> p = {
      P(xmin, ymin), P(xmax, ymin), P(xmax, ymax), P(xmin, ymax)
    };
    // frame.emplace_back(P(xmin, 0), P(xmin, 0) + P(0, -1));
    // frame.emplace_back(P(0, ymin), P(0, ymin) + P(1, 0));
    // frame.emplace_back(P(xmax, 0), P(xmax, 0) + P(0, 1));
    // frame.emplace_back(P(0, ymax), P(0, ymax) + P(-1, 0));
    // assert(HPI(frame, false));
    // assert(frame.size() == 4);
    // regions.emplace_back(frame, v);
    regions.emplace_back(p, v);
  }

  for (int i = 0; i < atomid; i++) {
    auto ln = all_lines[i];
  // for (Line ln : all_lines) {

    P s = ln.st;
    P e = ln.ed;
    vector<Region> new_region;

    const auto old_size = regions.size();
    for (size_t x = 0; x < old_size; x++) {
      auto &r = regions[x];
      if (area(r.p) < eps) continue;
      bool pos = false, neg = false;
      orange(all(r.p));
      for (size_t j = 0; j < r.p.size(); j++) {
        int o = sgn( cross(r.p[j] - s, e - s) );
        // int o = ori(s, r.p[j], e);
        if (o > 0) pos = true;
        if (o < 0) neg = true;
        debug(o);
      }

      debug(pos, neg);
      if (pos && neg) {
        auto new_p = cut(r.p, e, s);
        orange(all(new_p));
        r.p = cut(r.p, s, e);
        auto new_val = r.value;
        new_val[i] = true;
        regions.emplace_back(new_p, new_val);
      } else {
        // assert(pos || neg);
        if (neg)
          r.value[i] = true;
      }
    }
    debug(regions.size());
  }


  /*
  debug(regions.size());
  for (const Region &r : regions) {
    orange(all(r.p));
    debug(r.value);
  }
  */

  vector<bitset<maxn>> mask(atomid);
  for (size_t i = 0; i < regions.size(); i++) {
    for (int j = 0; j < atomid; j++) {
      if (regions[i].value[j]) {
        mask[j][i] = true;
      }
    }
  }

  llf ans = 0;
  auto M = root->evaluate(mask);
  for (size_t i = 0; i < regions.size(); i++) {
    if (M[i]) {
      ans += area(regions[i].p);
    }
  }
  

  cout << fixed << setprecision(20);
  cout << ans << '\n';

  //delete root;

  return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

0 1 0 1
([-1,1,0]^[-1,-1,1])

output:

0.50000000000000000000

result:

ok found '0.5000000', expected '0.5000000', error '0.0000000'

Test #2:

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

input:

-5 10 -10 5
((!([1,2,-3]&[10,3,-2]))^([-2,3,1]|[5,-2,7]))

output:

70.45169340463458240720

result:

ok found '70.4516934', expected '70.4516934', error '0.0000000'

Test #3:

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

input:

0 1 -1 1
([1,1,1]&[-1,-1,-1])

output:

0.00000000000000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #4:

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

input:

0 1000 0 1000
(([1,-1,0]&[-1000,999,999])&([1,0,-998]&[0,1,-998]))

output:

0.00050000000009032424

result:

ok found '0.0005000', expected '0.0005000', error '0.0000000'

Test #5:

score: 0
Accepted
time: 1ms
memory: 4288kb

input:

-725 165 643 735
((((!(([22,15,137]|(!([23,-5,-41]^(!([2,25,-515]&[-37,10,487])))))&(!(([25,24,47]^([-24,21,-114]^[19,-7,79]))^[4,20,241]))))^(!((!((!(([30,-1,474]^([14,17,155]^[-31,-6,-153]))|[-15,-15,108]))|(([-26,-11,421]&[-15,-3,-224])&[14,-3,458])))^[9,20,-404])))^(!((!((!(([14,-6,-464]^[-11,8,...

output:

47063.33485244149051140994

result:

ok found '47063.3348524', expected '47063.3348524', error '0.0000000'

Test #6:

score: 0
Accepted
time: 1ms
memory: 4140kb

input:

767 957 738 941
((!(((!([3,-3,507]^[-30,-10,425]))^[-6,7,643])^((!((!([-11,0,450]^[21,17,-65]))&(!([17,0,64]^[-11,0,804]))))|[-31,10,-687])))&((!(([-34,12,-527]^(!([17,-14,-219]^(!([13,-27,-105]^(!([18,-47,-110]&(!([-9,-20,-455]^[-18,26,-228])))))))))^([-4,0,144]^[10,1,396])))^((!((!([35,0,-221]&[-5...

output:

36999.05865566320426296443

result:

ok found '36999.0586557', expected '36999.0586557', error '0.0000000'

Test #7:

score: 0
Accepted
time: 127ms
memory: 13140kb

input:

-513 213 -733 114
(!((!((!((((!([2,16,-57]|[15,40,-272]))^((!(([0,26,315]|[5,-4,-336])^(!([-12,2,218]&([17,-16,-730]&[-7,3,-263])))))^[18,-7,29]))^[5,30,-126])^((!(((!((([8,9,406]^(!([-26,6,63]^[-38,-25,108])))^(([-9,20,220]^(!([-2,-27,213]^[29,16,-269])))|[-12,-4,-586]))^([30,0,-443]|(!((!([-17,0,3...

output:

295728.60810361010953783989

result:

ok found '295728.6081036', expected '295728.6081036', error '0.0000000'

Test #8:

score: 0
Accepted
time: 2ms
memory: 5592kb

input:

-517 -379 -789 477
(((!((!(([1,-12,191]^(!(((!([32,0,89]^[-35,6,33]))^[-3,6,-293])^[20,-39,77])))^(([16,15,-285]^[15,-7,430])^([20,3,-95]|(!((!(([-15,-27,339]^[-11,-13,221])^[33,28,596]))|([-17,21,402]^[22,16,90])))))))&(!((!((!([12,-1,-279]^[-30,-13,224]))^[-29,24,-33]))^([31,-19,288]^(!((!([-1,26,...

output:

107150.60487969710084144026

result:

ok found '107150.6048797', expected '107150.6048797', error '0.0000000'

Test #9:

score: 0
Accepted
time: 2ms
memory: 4356kb

input:

-477 275 -266 519
(!((!((!((!([-1,3,162]|[-32,16,269]))&(!(((((([-31,7,114]^([-12,7,-163]^[23,-10,159]))|(!(([0,-16,114]^[-33,15,-190])|(!([1,-22,308]^[-31,13,316])))))^((!([-12,29,-22]^(([23,15,-8]^[0,15,46])^[6,15,356])))^[22,13,-163]))^([18,17,487]^[28,23,143]))|(!(((!((!(([7,-45,-583]&([31,2,-22...

output:

335169.31051751569611951709

result:

ok found '335169.3105175', expected '335169.3105175', error '0.0000000'

Test #10:

score: 0
Accepted
time: 1ms
memory: 4152kb

input:

175 624 -835 683
(!(((!(([-32,30,-478]^[23,4,-120])^[28,33,413]))|(!((!((!((!([-15,-5,0]^(!((!(((!([0,-32,90]^[-9,-22,-7]))^[-10,-35,344])|(!([1,11,-235]|[-31,-6,-344]))))^(!((!([-15,0,-90]|[-17,-10,-153]))^[-1,6,-8]))))))^(!([8,-6,302]^[-2,4,91]))))|([13,28,-70]^[16,-11,-74])))^(((((!((!((([-5,8,45...

output:

411470.35850494320038706064

result:

ok found '411470.3585049', expected '411470.3585049', error '0.0000000'

Test #11:

score: 0
Accepted
time: 14ms
memory: 9712kb

input:

-1000 1000 -1000 1000
([1,0,-1000]^([0,1,-1000]^([1,0,-980]^([0,1,-980]^([1,0,-960]^([0,1,-960]^([1,0,-940]^([0,1,-940]^([1,0,-920]^([0,1,-920]^([1,0,-900]^([0,1,-900]^([1,0,-880]^([0,1,-880]^([1,0,-860]^([0,1,-860]^([1,0,-840]^([0,1,-840]^([1,0,-820]^([0,1,-820]^([1,0,-800]^([0,1,-800]^([1,0,-780]^...

output:

2000000.00000000000000000000

result:

ok found '2000000.0000000', expected '2000000.0000000', error '0.0000000'

Test #12:

score: 0
Accepted
time: 15ms
memory: 9908kb

input:

-500 500 -500 500
([2,-3,-1000]^([2,3,-1000]^([2,-3,-980]^([2,3,-980]^([2,-3,-960]^([2,3,-960]^([2,-3,-940]^([2,3,-940]^([2,-3,-920]^([2,3,-920]^([2,-3,-900]^([2,3,-900]^([2,-3,-880]^([2,3,-880]^([2,-3,-860]^([2,3,-860]^([2,-3,-840]^([2,3,-840]^([2,-3,-820]^([2,3,-820]^([2,-3,-800]^([2,3,-800]^([2,-...

output:

539999.99999995506368577480

result:

ok found '540000.0000000', expected '540000.0000000', error '0.0000000'

Test #13:

score: 0
Accepted
time: 4ms
memory: 10760kb

input:

-1000 1000 -1000 1000
([-57,281,0]^([478,81,0]^([-362,995,0]^([-339,614,0]^([491,769,0]^([673,486,0]^([-637,374,0]^([-204,383,0]^([-509,859,0]^([-973,757,0]^([-707,648,0]^([-792,409,0]^([-944,621,0]^([446,21,0]^([-553,473,0]^([795,704,0]^([-821,992,0]^([89,47,0]^([771,332,0]^([-845,259,0]^([271,867,...

output:

1823923.89715294842608273029

result:

ok found '1823923.8971529', expected '1823923.8971530', error '0.0000000'

Test #14:

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

input:

-1000 1000 -1000 1000
(([-27,-20,-237]^((([31,17,247]^[-4,-23,-917])^(![8,21,-342]))^((([-17,2,-281]&[-26,-31,186])|[31,-21,-697])|[-18,8,-512])))&[-5,19,-104])

output:

420530.73454094049520790577

result:

ok found '420530.7345409', expected '420530.7345409', error '0.0000000'

Test #15:

score: 0
Accepted
time: 67ms
memory: 9640kb

input:

-1000 1000 -1000 1000
((((!(((([31,17,247]^[-4,-23,-917])^(![8,21,-342]))^((([-17,2,-281]&[-26,-31,186])|[31,-21,-697])|[-18,8,-512]))^((!((!(!((([12,23,237]|[913,22,925])^[-14,11,-956])^[-9,-10,818])))|((([3,1,-213]^[-296,-13,171])&(!(!((!((!([-10,6,636]^[17,19,-546]))^([28,28,-698]|[-14,-4,-295]))...

output:

1479667.44078596285544335842

result:

ok found '1479667.4407860', expected '1479667.4407860', error '0.0000000'

Test #16:

score: 0
Accepted
time: 145ms
memory: 14532kb

input:

-1000 1000 -1000 1000
(((((((((((([-15,-2,9]^[-168,-28,507])^[-31,-23,293])^[23,-1,-290])^(([26,-4,869]^(([24,2,522]^[-10,5,-918])^[-22,5,50]))^[16,-827,-276]))^(([-1,-24,-651]^([16,15,-332]^[-722,29,-330]))^([-19,-23,14]^[12,-18,289])))^(((([6,-29,803]^[8,-8,50])^((([9,-7,-112]^([23,-29,-827]^[-12,...

output:

1945479.95743986987508833408

result:

ok found '1945479.9574399', expected '1945479.9574399', error '0.0000000'

Test #17:

score: 0
Accepted
time: 1ms
memory: 4704kb

input:

0 1000 0 1000
(((((((([85,-100,0]^[21,-100,0])^[55,-100,0])^([29,-100,0]^([47,-100,0]^([78,-100,0]^([13,-100,0]^([100,-11,0]^[86,-100,0]))))))^(([48,-100,0]^[35,-100,0])^((([39,-100,0]^[98,-100,0])^([9,-100,0]^[100,-14,0]))^[100,-79,0])))^([12,-100,0]^[100,-100,0]))^((([20,-100,0]^([100,-64,0]^([100...

output:

500000.00000000000000000000

result:

ok found '500000.0000000', expected '500000.0000000', error '0.0000000'

Test #18:

score: 0
Accepted
time: 9ms
memory: 6216kb

input:

0 100 0 100
(((([-85,1,0]^((([-21,1,0]^([-55,1,0]^(([-29,1,0]^[-47,1,0])^([-78,1,0]^[-13,1,0]))))^(([11,1,-100]^[-86,1,0])^[-48,1,0]))^([-35,1,0]^((((([-39,1,0]^([-98,1,0]^[-9,1,0]))^((([14,1,-100]^[79,1,-100])^[-12,1,0])^[100,1,-100]))^((([-20,1,0]^[64,1,-100])^(([60,1,-100]^([-1,1,0]^[41,1,-100]))...

output:

4987.31485497433914133580

result:

ok found '4987.3148550', expected '4987.3148550', error '0.0000000'

Test #19:

score: 0
Accepted
time: 62ms
memory: 9672kb

input:

-500 1000 -500 1000
((((((([2,-1,37]^[2,-1,1])^(([2,1,-55]^(([2,1,-29]^[2,1,-47])^[2,1,-78]))^([2,1,-13]^[0,1,-11])))^(((([2,1,-86]^([2,1,-48]^[2,-1,100]))^[2,-1,95])^[2,1,-98])^([2,1,-9]^([0,1,-14]^[0,1,-79]))))^([2,-1,88]^[0,1,-100]))^(([2,1,-20]^(([0,1,-64]^([2,-1,85]^[2,1,-1]))^(([2,-1,65]^([0,1...

output:

144999.99999999962165020406

result:

ok found '145000.0000000', expected '145000.0000000', error '0.0000000'

Test #20:

score: 0
Accepted
time: 1ms
memory: 4544kb

input:

0 1000 0 1000
(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!...

output:

623640.00000000023283064365

result:

ok found '623640.0000000', expected '623640.0000000', error '0.0000000'

Test #21:

score: 0
Accepted
time: 8ms
memory: 5668kb

input:

-300 300 -300 300
((([-199,200,0]&[299,-300,0])&([-1,-300,300]&[1,200,-200]))&([-1,-215,215]^((((([-1,-279,279]^[-1,-245,245])^(((((([-1,-271,271]^[-1,-253,253])^([-1,-222,222]^([-1,-287,287]^[289,-290,0])))^([-1,-214,214]^[-1,-252,252]))^(([-1,-265,265]^[-1,-261,261])^([-1,-202,202]^((([-1,-291,291...

output:

0.00000139525338831604

result:

ok found '0.0000014', expected '0.0000014', error '0.0000000'

Test #22:

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

input:

0 1000 0 1000
(([-998,999,0]&[999,-1000,0])&[-1,-1,3])

output:

0.00000112725348013470

result:

ok found '0.0000011', expected '0.0000011', error '0.0000000'

Extra Test:

score: 0
Extra Test Passed