QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#289951 | #7862. Land Trade | ucup-team088# | TL | 11ms | 12260kb | C++17 | 10.9kb | 2023-12-24 06:03:05 | 2023-12-24 06:03:06 |
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;
}
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);
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);
}
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;
rep(i, xs.size() - 1) {
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;
ld my = 0;
my += calc(idr, mx);
my += calc(idl, mx);
my /= 2.0;
objx = mx, objy = my;
int z = 0;
if (expr(s, z)) {
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;
}
assert(z == s.size());
}
}
}
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: 12140kb
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: 12036kb
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: 4ms
memory: 12092kb
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: 0ms
memory: 12100kb
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: 11ms
memory: 12260kb
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: 4ms
memory: 12180kb
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: -100
Time Limit Exceeded
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...