QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#289373#7862. Land Tradeucup-team266#WA 2ms11436kbC++205.4kb2023-12-23 17:20:402023-12-23 17:20:40

Judging History

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

  • [2023-12-23 17:20:40]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11436kb
  • [2023-12-23 17:20:40]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
#define x first
#define y second
#define x1 x114514
#define x2 x1919810
#define y1 y114514
#define y2 y1919810
#define index _index
void die(string S){puts(S.c_str());exit(0);}
const double eps=1e-8;
struct line
{
	double A,B,C;
	line(double _A,double _B,double _C):A(_A),B(_B),C(_C){}
	line(){}
}L[1010];
int x1,x2,y1,y2;
string s;
struct formula
{
	formula *a,*b;
	int op;
};
const pair<double,double> error=mp(20210109,20210448);
pair<double,double> its(line a,line b)
{
	double B=a.B*b.A-b.B*a.A,C=a.C*b.A-b.C*a.A;
	double y=-C/B;
	double x=(-a.C-a.B*y)/a.A;
	if(isnan(y)||y<-1e9||y>1e9) return error;
	if(isnan(x)) x=(-b.C-b.B*y)/b.A;
	return mp(x,y);
}
int tot;
formula *get(int l,int r)
{
//	cerr<<l<<" "<<r<<endl;
	int c=0,p=-1;
	for(int i=l;i<=r;i++)
	{
		if(s[i]=='(')
			c++;
		if(s[i]==')')
			c--;
		if(s[i]=='!'||s[i]=='&'||s[i]=='|'||s[i]=='^') if(!c)
			p=i;
	}
	if(p==-1)
	{
		if(s[l]=='(')
			return get(l+1,r);
		formula *ret=new formula;
		ret->op=++tot;
		vector<int> vec;
		int x=0,f=0;
		for(int i=l;i<=r;i++)
		{
			if(isdigit(s[i]))
			{
				x=x*10+(s[i]^48);
				if(!f) f=1;
			}
			else if(s[i]=='-')
				f=-1;
			else if(f)
			{
				vec.pb(x*f);
				x=0;
				f=0;
			}
		}
		L[tot]=line(vec[0],vec[1],vec[2]);
		return ret;
	}
	else
	{
		if(s[p]=='!')
		{
			formula *ret=new formula;
			ret->op=-4;
			ret->a=get(l+1,r);
			return ret;
		}
		formula *ret=new formula;
		ret->op=(s[p]=='&'?-1:(s[p]=='|'?-2:-3));
		ret->a=get(l,p-1);
		ret->b=get(p+1,r);
		return ret;
	}
}
vector<pair<pair<double,double>,pii>> vec;
int lst[1010];
vector<pair<double,int>> G[100100];
double calc(int a,int b)
{
	return atan2(vec[b].x.y-vec[a].x.y,vec[b].x.x-vec[a].x.x);
}
map<int,int> index[100100];
map<pii,bool> vis;
bool status[100100];
pair<double,double> ctr(pair<double,double> a,pair<double,double> b,pair<double,double> c)
{
	return mp((a.x+b.x+c.x)/3,(a.y+b.y+c.y)/3);
}
bool calc(formula *F)
{
	if(F->op>0) return status[F->op];
	if(F->op==-4) return !calc(F->a);
	bool a=calc(F->a),b=calc(F->b);
	if(F->op==-1) return a&b;
	if(F->op==-2) return a|b;
	return a^b;
}
map<pair<double,double>,vector<int>> belong;
const bool operator ==(const pair<double,double> &a,const pair<double,double> &b)
{
	return fabs(a.x-b.x)<eps&&fabs(a.y-b.y)<eps;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>x1>>x2>>y1>>y2;
	cin>>s;
	formula *F=get(0,sz(s)-1);
	L[tot+1]=line(1,0,-x1);
	L[tot+2]=line(0,-1,y2);
	L[tot+3]=line(-1,0,x2);
	L[tot+4]=line(0,1,-y1);
	int cnt=0;
	for(int i=1;i<=tot+4;i++)
		for(int j=i+1;j<=tot+4;j++)
		{
			pair<double,double> p=its(L[i],L[j]);
			if(p==error) continue;
//			cerr<<i<<" "<<j<<" "<<p.x<<" "<<p.y<<endl;
			if(p.x<x1-eps||p.x>x2+eps||p.y<y1-eps||p.y>y2+eps)
				continue;
			belong[p].pb(i);
			belong[p].pb(j);
			vec.pb(p,mp(0,0));
		}
	srt(vec);
	uni(vec);
	int n=sz(vec);
	memset(lst,-1,sizeof(lst));
	for(int i=0;i<n;i++)
	{
		auto pr=vec[i];
		bool flag=0;
		srt(belong[pr.first]);
		uni(belong[pr.first]);
		for(auto a:belong[pr.first])
		{
			if(a>tot) flag=1;
			if(lst[a]!=-1)
			{
				G[lst[a]].pb(calc(lst[a],i),i);
				G[i].pb(calc(i,lst[a]),lst[a]);
			}
			lst[a]=i;
		}
		cnt+=flag;
	}
//	cerr<<cnt<<endl;
	for(int i=0;i<n;i++)
	{
		srt(G[i]);
		for(int j=0;j<sz(G[i]);j++)
			index[i][G[i][j].second]=j;
	}
	vector<array<int,3>> pool;
	for(int i=0;i<n;i++)
		for(auto pr:G[i])
			if(!vis[mp(i,pr.second)])
			{
				vector<int> cvh;
				int cura=i,curb=pr.second;
				while(!vis[mp(cura,curb)])
				{
					vis[mp(cura,curb)]=1;
					cvh.pb(curb);
					int p=index[curb][cura];
					p=(p+1)%sz(G[curb]);
					cura=curb;
					curb=G[cura][p].second;
				}
				if(sz(cvh)<3) continue;
				if(sz(cvh)==cnt) continue;
//				for(auto a:cvh)
//					cerr<<a<<" ";
//				cerr<<endl;
//				for(auto a:cvh)
//					cerr<<"("<<vec[a].x.x<<","<<vec[a].x.y<<") ";
//				cerr<<endl;
				for(int i=2;i<sz(cvh);i++)
					pool.push_back({cvh[0],cvh[i-1],cvh[i]});
			}
//	cerr<<F->op<<endl;
	double ans=0;
	for(auto arr:pool)
	{
		int a=arr[0],b=arr[1],c=arr[2];
		pair<double,double> center=ctr(vec[a].first,vec[b].first,vec[c].first);
		memset(status,0,sizeof(status));
		for(int i=1;i<=tot;i++)
			if(L[i].A*center.x+L[i].B*center.y+L[i].C>-eps)
				status[i]=1;
		if(calc(F))
		{
			double S=0;
			double ax=vec[a].x.x-vec[c].x.x,ay=vec[a].x.y-vec[c].x.y,bx=vec[b].x.x-vec[c].x.x,by=vec[b].x.y-vec[c].x.y;
			S=fabs(ax*by-ay*bx)/2;
//			cerr<<vec[a].x.x<<" "<<vec[a].x.y<<" "<<vec[b].x.x<<" "<<vec[b].x.y<<" "<<vec[c].x.x<<" "<<vec[c].x.y<<endl;
//			cerr<<status[1]<<" "<<status[2]<<" "<<status[3]<<" "<<status[4]<<" "<<calc(F)<<endl;
//			cerr<<S<<endl;
			ans+=S;
		}
	}
	printf("%.20lf\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 2ms
memory: 11436kb

input:

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

output:

nan

result:

wrong output format Expected double, but "nan" found