QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#289967 | #7862. Land Trade | ucup-team088# | TL | 2590ms | 12316kb | C++17 | 11.6kb | 2023-12-24 06:36:35 | 2023-12-24 06:36:35 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<chrono>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
//ll mod = 1;
constexpr ll mod = 998244353;
//constexpr ll mod = 1000000009;
const int mod17 = 1000000007;
const ll INF = (ll)mod17 * mod17;
typedef pair<int, int>P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
using ld = double;
typedef pair<ld, ld> LDP;
const ld eps = 1e-10;
const ld pi = acosl(-1.0);
template<typename T>
void chmin(T& a, T b) {
a = min(a, b);
}
template<typename T>
void chmax(T& a, T b) {
a = max(a, b);
}
template<typename T>
vector<T> vmerge(vector<T>& a, vector<T>& b) {
vector<T> res;
int ida = 0, idb = 0;
while (ida < a.size() || idb < b.size()) {
if (idb == b.size()) {
res.push_back(a[ida]); ida++;
}
else if (ida == a.size()) {
res.push_back(b[idb]); idb++;
}
else {
if (a[ida] < b[idb]) {
res.push_back(a[ida]); ida++;
}
else {
res.push_back(b[idb]); idb++;
}
}
}
return res;
}
template<typename T>
void cinarray(vector<T>& v) {
rep(i, v.size())cin >> v[i];
}
template<typename T>
void coutarray(vector<T>& v) {
rep(i, v.size()) {
if (i > 0)cout << " "; cout << v[i];
}
cout << "\n";
}
ll mod_pow(ll x, ll n, ll m = mod) {
if (n < 0) {
ll res = mod_pow(x, -n, m);
return mod_pow(res, m - 2, m);
}
if (abs(x) >= m)x %= m;
if (x < 0)x += m;
//if (x == 0)return 0;
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
//mod should be <2^31
struct modint {
int n;
modint() :n(0) { ; }
modint(ll m) {
if (m < 0 || mod <= m) {
m %= mod; if (m < 0)m += mod;
}
n = m;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
bool operator<(modint a, modint b) { return a.n < b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= (int)mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += (int)mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[a - b];
}
ll gcd(ll a, ll b) {
a = abs(a); b = abs(b);
if (a < b)swap(a, b);
while (b) {
ll r = a % b; a = b; b = r;
}
return a;
}
template<typename T>
void addv(vector<T>& v, int loc, T val) {
if (loc >= v.size())v.resize(loc + 1, 0);
v[loc] += val;
}
/*const int mn = 2000005;
bool isp[mn];
vector<int> ps;
void init() {
fill(isp + 2, isp + mn, true);
for (int i = 2; i < mn; i++) {
if (!isp[i])continue;
ps.push_back(i);
for (int j = 2 * i; j < mn; j += i) {
isp[j] = false;
}
}
}*/
//[,val)
template<typename T>
auto prev_itr(set<T>& st, T val) {
auto res = st.lower_bound(val);
if (res == st.begin())return st.end();
res--; return res;
}
//[val,)
template<typename T>
auto next_itr(set<T>& st, T val) {
auto res = st.lower_bound(val);
return res;
}
using mP = pair<modint, modint>;
mP operator+(mP a, mP b) {
return { a.first + b.first,a.second + b.second };
}
mP operator+=(mP& a, mP b) {
a = a + b; return a;
}
mP operator-(mP a, mP b) {
return { a.first - b.first,a.second - b.second };
}
mP operator-=(mP& a, mP b) {
a = a - b; return a;
}
LP operator+(LP a, LP b) {
return { a.first + b.first,a.second + b.second };
}
LP operator+=(LP& a, LP b) {
a = a + b; return a;
}
LP operator-(LP a, LP b) {
return { a.first - b.first,a.second - b.second };
}
LP operator-=(LP& a, LP b) {
a = a - b; return a;
}
mt19937 mt(time(0));
const string drul = "DRUL";
string senw = "SENW";
//DRUL,or SENW
//int dx[4] = { 1,0,-1,0 };
//int dy[4] = { 0,1,0,-1 };
//------------------------------------
typedef complex<ld> Point;
ld dot(Point a, Point b) { return real(conj(a) * b); }
ld cross(Point a, Point b) { return imag(conj(a) * b); }
namespace std {
bool operator<(const Point& lhs, const Point& rhs) {
return lhs.real() == rhs.real() ? lhs.imag() < rhs.imag() : lhs.real() < rhs.real();
}
}
struct Line {
Point a, b;
};
struct Circle {
Point p; ld r;
};
int ccw(Point a, Point b, Point c) {
b -= a; c -= a;
if (cross(b, c) > eps)return 1;//counter clockwise
if (cross(b, c) < -eps)return -1;//clock wise
if (dot(b, c) < 0)return 2;//c--a--b on line
if (norm(b) < norm(c))return -2;//a--b--c on line
return 0; //a--c--b on line
}
typedef vector<Point> polygon;
bool eq(ld a, ld b) {
return abs(a - b) < eps;
}
//2直線の交差判定
bool isis_ll(Line l, Line m) {
return !eq(cross(l.b - l.a, m.b - m.a), 0);
}
//直線と線分の交差判定
bool isis_ls(Line l, Line s) {
return (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps);
}
//点が直線上に存在するか
bool isis_lp(Line l, Point p) {
return (abs(cross(l.b - p, l.a - p)) < eps);
}
//点が線分上に存在するか
bool isis_sp(Line s, Point p) {
//誤差がisis_lpに比べて大きいので、できるだけisis_lpを使う
return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps);
}
//線分と線分の交差判定
//bool isis_ss(Line s, Line t) {
// return(cross(s.b - s.a, t.a - s.a)*cross(s.b - s.a, t.b - s.a) < -eps && cross(t.b - t.a, s.a - t.a)*cross(t.b - t.a, s.b - t.a) < -eps);
//}
//線分と線分の交差判定2
//本当にそれは線分ですか?(check {(0,0),(2,0)},{(1,0),(1,0)})
bool isis_ss(Line s, Line t) {
return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}
//点から直線への垂線の足
Point proj(Line l, Point p) {
ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
return l.a + t * (l.a - l.b);
}
//直線と直線の交点
//平行な2直線に対しては使うな!!!!
Point is_ll(Line s, Line t) {
Point sv = s.b - s.a; Point tv = t.b - t.a;
return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}
int getdec(string& s, int& i) {
int res = 0;
int coef = 1;
if (s[i] == '-') {
coef = -1; i++;
}
while ('0' <= s[i] && s[i] <= '9') {
res = 10 * res + (s[i] - '0');
i++;
}
res *= coef;
return res;
}
ld objx, objy;
bool expr(string& s, int& i);
bool subexpr(string& s, int& i);
bool expr(string& s, int& i) {
if (s[i] == '(') {
i++;
if (s[i] == '!') {
i++;
bool res = expr(s, i);
assert(s[i] == ')');
i++;
res = !res;
return res;
}
else {
bool res1 = expr(s, i);
char op = s[i];
i++;
bool res2 = expr(s, i);
assert(s[i] == ')');
i++;
bool res;
if (op == '&') {
res = res1 && res2;
}
else if (op == '|') {
res = res1 || res2;
}
else {
assert(op == '^');
res = res1 ^ res2;
}
return res;
}
}
else {
return subexpr(s, i);
}
}
bool subexpr(string& s, int& i) {
assert(s[i] == '[');
i++;
int a = getdec(s, i);
assert(s[i] == ',');
i++;
int b = getdec(s, i);
assert(s[i] == ',');
i++;
int c = getdec(s, i);
assert(s[i] == ']');
i++;
return a * objx + b * objy + c >= 0;
}
//-5 10 -10 5
//((!([1, 2, -3] & [10, 3, -2])) ^ ([-2, 3, 1] | [5, -2, 7]))
using ar = array<int, 3>;
void solve() {
int lx, ly, rx, ry; cin >> lx >> rx >> ly >> ry;
string s; cin >> s;
vector<Line> ls;
vector<ar> memls;
ls.push_back({ Point{(ld)lx,(ld)ly},Point{(ld)rx,(ld)ly} });
ls.push_back({ Point{(ld)lx,(ld)ry},Point{(ld)rx,(ld)ry} });
memls.push_back({ 0,1,-ly });
memls.push_back({ 0,1,-ry });
vector<ld> xs;
xs.push_back(lx);
xs.push_back(rx);
set<ld> zxs;
rep(i, s.size())if (s[i] == '[') {
i++;
int a = getdec(s, i);
i++;
int b = getdec(s, i);
i++;
int c = getdec(s, i);
//ax+by+c
if (b == 0) {
xs.push_back(-c / (ld)a);
zxs.insert(-c / (ld)a);
}
else {
Point pl = { 0,-c / (ld)b };
Point pr = { 1,(-a - c) / (ld)b };
ls.push_back({ pl,pr });
memls.push_back({ a,b,c });
}
}
rep(i, ls.size())Rep(j, i + 1, ls.size()) {
if (isis_ll(ls[i], ls[j])) {
Point p = is_ll(ls[i], ls[j]);
xs.push_back(real(p));
}
}
auto calc = [&](int id, ld x) {
ar a = memls[id];
ld res = (-a[0] * x - a[2]) / (ld)a[1];
return res;
};
sort(all(xs));
ld ans = 0;
map<P, int> mem;
rep(i, xs.size() - 1) {
if (zxs.count(xs[i]))mem.clear();
map<P, int> nmem;
if (xs[i + 1] - xs[i] < eps)continue;
if (lx <= xs[i] && xs[i + 1] <= rx) {
ld mx = (xs[i + 1] + xs[i]) / 2.0;
vector<pair<ld, int>> lines;
rep(j, memls.size()) {
ar a = memls[j];
ld cy = calc(j, mx);
if (ly - eps <= cy && cy <= ry + eps) {
lines.push_back({ cy,j });
}
}
sort(all(lines));
rep(j, lines.size() - 1) {
int idl = lines[j].second;
int idr = lines[j + 1].second;
//cout << i << " " << xs[i + 1] << " " << idl << " " << idr << "\n";
P pp = { idl,idr };
bool valid;
if (mem.find(pp) != mem.end()) {
/*ld my = 0;
my += calc(idr, mx);
my += calc(idl, mx);
my /= 2.0;
objx = mx, objy = my;
int z = 0;
bool b = expr(s, z);
assert(b == mem[pp]);*/
valid = mem[pp];
}
else {
ld my = 0;
my += calc(idr, mx);
my += calc(idl, mx);
my /= 2.0;
objx = mx, objy = my;
int z = 0;
valid = expr(s, z);
assert(z == s.size());
}
nmem[pp] = valid;
if (valid) {
ld lenl = 0, lenr = 0;
lenl += calc(idr, xs[i]);
lenl -= calc(idl, xs[i]);
lenr += calc(idr, xs[i + 1]);
lenr -= calc(idl, xs[i + 1]);
ld s = (lenr + lenl) * (xs[i + 1] - xs[i]) / 2.0;
ans += s;
}
}
}
swap(mem, nmem);
}
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
//init_f();
//init();
//while(true)
//expr();
//int t; cin >> t; rep(i, t)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 12164kb
input:
0 1 0 1 ([-1,1,0]^[-1,-1,1])
output:
0.5000000000
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 12212kb
input:
-5 10 -10 5 ((!([1,2,-3]&[10,3,-2]))^([-2,3,1]|[5,-2,7]))
output:
70.4516934046
result:
ok found '70.4516934', expected '70.4516934', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 12096kb
input:
0 1 -1 1 ([1,1,1]&[-1,-1,-1])
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 4ms
memory: 12076kb
input:
0 1000 0 1000 (([1,-1,0]&[-1000,999,999])&([1,0,-998]&[0,1,-998]))
output:
0.0005000000
result:
ok found '0.0005000', expected '0.0005000', error '0.0000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 12268kb
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.3348524412
result:
ok found '47063.3348524', expected '47063.3348524', error '0.0000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 12252kb
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.0586556632
result:
ok found '36999.0586557', expected '36999.0586557', error '0.0000000'
Test #7:
score: 0
Accepted
time: 2590ms
memory: 12268kb
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.6081035309
result:
ok found '295728.6081035', expected '295728.6081036', error '0.0000000'
Test #8:
score: 0
Accepted
time: 16ms
memory: 12316kb
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.6048796470
result:
ok found '107150.6048796', expected '107150.6048797', error '0.0000000'
Test #9:
score: 0
Accepted
time: 8ms
memory: 12048kb
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.3105175118
result:
ok found '335169.3105175', expected '335169.3105175', error '0.0000000'
Test #10:
score: 0
Accepted
time: 7ms
memory: 12168kb
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.3585049128
result:
ok found '411470.3585049', expected '411470.3585049', error '0.0000000'
Test #11:
score: 0
Accepted
time: 47ms
memory: 12108kb
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.0000000000
result:
ok found '2000000.0000000', expected '2000000.0000000', error '0.0000000'
Test #12:
score: 0
Accepted
time: 103ms
memory: 12268kb
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.9999984640
result:
ok found '539999.9999985', expected '540000.0000000', error '0.0000000'
Test #13:
score: 0
Accepted
time: 24ms
memory: 12252kb
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.8971529470
result:
ok found '1823923.8971529', expected '1823923.8971530', error '0.0000000'
Test #14:
score: 0
Accepted
time: 5ms
memory: 12108kb
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.7345409406
result:
ok found '420530.7345409', expected '420530.7345409', error '0.0000000'
Test #15:
score: 0
Accepted
time: 1302ms
memory: 12316kb
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.4407857689
result:
ok found '1479667.4407858', expected '1479667.4407860', error '0.0000000'
Test #16:
score: -100
Time Limit Exceeded
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.9574393309