QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#295287#7862. Land Tradehos_lyricAC ✓1329ms22416kbC++147.0kb2023-12-31 01:44:332023-12-31 01:44:33

Judging History

This is the latest submission verdict.

  • [2023-12-31 01:44:33]
  • Judged
  • Verdict: AC
  • Time: 1329ms
  • Memory: 22416kb
  • [2023-12-31 01:44:33]
  • Submitted

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


using Double = long double;
const Double EPS = 1e-10L;
const Double INF = 1e+10L;
const Double PI = acos(-1.0L);
inline int sig(Double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
inline Double sq(Double r) { return r * r; }

struct Pt {
  Double x, y;
  Pt() {}
  Pt(Double x_, Double y_) : x(x_), y(y_) {}
  Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
  Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
  Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); }
  Pt operator/(const Pt &a) const { const Double d2 = a.abs2(); return Pt((x * a.x + y * a.y) / d2, (y * a.x - x * a.y) / d2); }
  Pt operator+() const { return Pt(+x, +y); }
  Pt operator-() const { return Pt(-x, -y); }
  Pt operator*(const Double &k) const { return Pt(x * k, y * k); }
  Pt operator/(const Double &k) const { return Pt(x / k, y / k); }
  friend Pt operator*(const Double &k, const Pt &a) { return Pt(k * a.x, k * a.y); }
  Pt &operator+=(const Pt &a) { x += a.x; y += a.y; return *this; }
  Pt &operator-=(const Pt &a) { x -= a.x; y -= a.y; return *this; }
  Pt &operator*=(const Pt &a) { return *this = *this * a; }
  Pt &operator/=(const Pt &a) { return *this = *this / a; }
  Pt &operator*=(const Double &k) { x *= k; y *= k; return *this; }
  Pt &operator/=(const Double &k) { x /= k; y /= k; return *this; }
  Double abs() const { return sqrt(x * x + y * y); }
  Double abs2() const { return x * x + y * y; }
  Double arg() const { return atan2(y, x); }
  Double dot(const Pt &a) const { return x * a.x + y * a.y; }
  Double det(const Pt &a) const { return x * a.y - y * a.x; }
  friend ostream &operator<<(ostream &os, const Pt &a) { os << "(" << a.x << ", " << a.y << ")"; return os; }
};
inline Double tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); }

Pt pLL(const Pt &a, const Pt &b, const Pt &c, const Pt &d) {
  const Pt ab = b - a, cd = d - c;
  return a + ab * (c - a).det(cd) / ab.det(cd);
}

vector<Pt> convexCut(const vector<Pt> &ps, const Pt &a, const Pt &b) {
  const int n = ps.size();
  vector<Pt> ret;
  for (int i = 0; i < n; ++i) {
    if (sig(tri(a, b, ps[i])) >= 0) ret.push_back(ps[i]);
    if (sig(tri(a, b, ps[i])) * sig(tri(a, b, ps[(i + 1 == n) ? 0 : (i + 1)])) < 0) ret.push_back(pLL(a, b, ps[i], ps[(i + 1 == n) ? 0 : (i + 1)]));
  }
  if (ret.size() < 3) return {};
  return ret;
}


constexpr int LIM = 46'000;

Int X0, X1, Y0, Y1;
char S[10'010];

struct F {
  char op;
  int l, r;
  Int a, b, c;
  void print() {
    cerr << op << " " << l << " " << r << " " << a << " " << b << " " << c << endl;
  }
};
int N;
F fs[10010];

int cur;
void eat(char c) {
  assert(S[cur] == c);
  ++cur;
}
int formula();
int atomic();
int formula() {
  int ret;
  if (S[cur] == '(') {
    eat('(');
    if (S[cur] == '!') {
      eat('!');
      const int r = formula();
      eat(')');
      const int u = N++;
      fs[u] = F{'!', -1, r, 0, 0, 0};
      ret = u;
    } else {
      const int l = formula();
      const char op = S[cur++];
      const int r = formula();
      eat(')');
      const int u = N++;
      fs[u] = F{op, l, r, 0, 0, 0};
      ret = u;
    }
  } else {
    ret = atomic();
  }
  return ret;
}
int atomic() {
  int ret;
  eat('[');
  const int u = N++;
  fs[u] = F{'a', -1, -1, 0, 0, 0};
  sscanf(S + cur, "%lld,%lld,%lld", &fs[u].a, &fs[u].b, &fs[u].c);
  ret = u;
  for (; S[cur] != ']'; ++cur) {}
  eat(']');
  return ret;
}


vector<int> atoms;
int regsLen;
vector<pair<Pt, Double>> regs;
void dfs(int pos, const vector<Pt> &ps) {
  if (pos == (int)atoms.size()) {
    const int psLen = ps.size();
    Pt g(0.0L, 0.0L);
    Double area = 0.0L;
    for (int i = 0; i < psLen; ++i) {
      g += ps[i];
      area += ps[i].det(ps[(i + 1) % psLen]);
    }
    g /= psLen;
    area /= 2.0;
    regs.emplace_back(g, area);
  } else {
    const int u = atoms[pos];
    Pt s = fs[u].a ? Pt(-fs[u].c / (Double)fs[u].a, 0.0L) : Pt(0.0L, -fs[u].c / (Double)fs[u].b);
    Pt t = s + Pt(-fs[u].b, fs[u].a);
    for (int dir = 0; dir < 2; ++dir) {
      const auto qs = convexCut(ps, s, t);
      if (qs.size() >= 3) {
        dfs(pos + 1, qs);
      }
      swap(s, t);
    }
  }
}

int main() {
  for (; ~scanf("%lld%lld%lld%lld", &X0, &X1, &Y0, &Y1); ) {
    scanf("%s", S);
    
    cur = 0;
    N = 0;
    const int rt = formula();
// for(int u=0;u<N;++u)fs[u].print();
    
    atoms.clear();
    for (int u = 0; u < N; ++u) if (fs[u].op == 'a') {
      atoms.push_back(u);
    }
    regs.clear();
    vector<Pt> ini;
    ini.emplace_back(X0, Y0);
    ini.emplace_back(X1, Y0);
    ini.emplace_back(X1, Y1);
    ini.emplace_back(X0, Y1);
    dfs(0, ini);
    regsLen = regs.size();
// cerr<<"regs = "<<regs<<endl;
    
    assert(regsLen < LIM);
    bitset<LIM> all;
    for (int j = 0; j < regsLen; ++j) all.set(j);
    vector<bitset<LIM>> dp(N);
    for (int u = 0; u < N; ++u) {
      switch (fs[u].op) {
        case '&': {
          dp[u] = dp[fs[u].l] & dp[fs[u].r];
        } break;
        case '|': {
          dp[u] = dp[fs[u].l] | dp[fs[u].r];
        } break;
        case '^': {
          dp[u] = dp[fs[u].l] ^ dp[fs[u].r];
        } break;
        case '!': {
          dp[u] = all ^ dp[fs[u].r];
        } break;
        case 'a': {
          for (int j = 0; j < regsLen; ++j) {
            const Pt p = regs[j].first;
            if (fs[u].a * p.x + fs[u].b * p.y + fs[u].c >= 0) {
              dp[u].set(j);
            }
          }
        } break;
        default: assert(false);
      }
    }
    
    Double ans = 0.0;
    for (int j = 0; j < regsLen; ++j) if (dp[rt][j]) {
      ans += regs[j].second;
    }
    printf("%.12Lf\n", ans);
  }
  return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

0.500000000000

result:

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

Test #2:

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

input:

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

output:

70.451693404635

result:

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

Test #3:

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

input:

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

output:

0.000000000000

result:

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

Test #4:

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

input:

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

output:

0.000500000000

result:

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

Test #5:

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

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.334852441477

result:

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

Test #6:

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

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.058655663222

result:

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

Test #7:

score: 0
Accepted
time: 1236ms
memory: 9576kb

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.608103610678

result:

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

Test #8:

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

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.604879697176

result:

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

Test #9:

score: 0
Accepted
time: 7ms
memory: 4324kb

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.310517515866

result:

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

Test #10:

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

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.358504943457

result:

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

Test #11:

score: 0
Accepted
time: 194ms
memory: 6156kb

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.000000000000

result:

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

Test #12:

score: 0
Accepted
time: 195ms
memory: 5992kb

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:

540000.000000000001

result:

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

Test #13:

score: 0
Accepted
time: 18ms
memory: 6772kb

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.897152950196

result:

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

Test #14:

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

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.734540940510

result:

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

Test #15:

score: 0
Accepted
time: 601ms
memory: 7956kb

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.440785966164

result:

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

Test #16:

score: 0
Accepted
time: 1329ms
memory: 9256kb

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.957439870418

result:

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

Test #17:

score: 0
Accepted
time: 3ms
memory: 5564kb

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.000000000000

result:

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

Test #18:

score: 0
Accepted
time: 196ms
memory: 6152kb

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.314854974314

result:

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

Test #19:

score: 0
Accepted
time: 746ms
memory: 8048kb

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:

145000.000000000000

result:

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

Test #20:

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

input:

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

output:

623640.000000000000

result:

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

Test #21:

score: 0
Accepted
time: 207ms
memory: 6516kb

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.000001388917

result:

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

Test #22:

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

input:

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

output:

0.000001127254

result:

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

Extra Test:

score: 0
Extra Test Passed