QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#188888#5310. PaintingExplodingKonjacWA 135ms6924kbC++147.2kb2023-09-26 16:09:332023-09-26 16:09:34

Judging History

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

  • [2023-09-26 16:09:34]
  • 评测
  • 测评结果:WA
  • 用时:135ms
  • 内存:6924kb
  • [2023-09-26 16:09:33]
  • 提交

answer

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

namespace FastIO
{

class FastIOBase
{
 protected:
#ifdef OPENIOBUF
	static const int BUFSIZE=1<<16;
	char buf[BUFSIZE+1];
	int buf_p=0;
#endif
	FILE *target;
	FastIOBase(FILE *f): target(f){}
	~FastIOBase()=default;
 public:
#ifdef OPENIOBUF
	virtual void flush()=0;
#endif
};

class FastOutput final: public FastIOBase
{
 private:
	void __putc(char x)
	{
#ifdef OPENIOBUF
		if(buf[buf_p++]=x,buf_p==BUFSIZE) flush();
#else
		putc(x,target);
#endif
	}
	template<typename T>
	void __write(T x)
	{
		char stk[64],*top=stk;
		if(x<0) return __putc('-'),__write(-x);
		do *(top++)=x%10,x/=10; while(x);
		for(;top!=stk;__putc(*(--top)+'0'));
	}
 public:
	FastOutput(FILE *f=stdout): FastIOBase(f) {}
#ifdef OPENIOBUF
	~FastOutput() { flush(); }
	void flush() { fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
	FastOutput &operator <<(char x)
	{ return __putc(x),*this; }
	FastOutput &operator <<(const char *s)
	{ for(;*s;__putc(*(s++)));return *this; }
	FastOutput &operator <<(const std::string &s)
	{ return (*this)<<s.c_str(); }
	template<typename T>
	std::enable_if_t<std::is_integral<T>::value,FastOutput&> operator <<(const T &x)
	{ return __write(x),*this; }
	template<typename ...T>
	void writesp(const T &...x)
	{ std::initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
	template<typename ...T>
	void writeln(const T &...x)
	{ std::initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
	template<typename Iter>
	void writesp(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<' '; }
	template<typename Iter>
	void writeln(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<'\n'; }
}qout;

class FastInput final: public FastIOBase
{
 private:
	bool __eof;
 public:
	FastInput(FILE *f=stdin): FastIOBase(f),__eof(false)
#ifdef OPENIOBUF
	{ buf_p=BUFSIZE; }
	void flush() { buf[fread(buf,1,BUFSIZE,target)]=EOF,buf_p=0; }
	bool eof()const { return buf[buf_p]==EOF; }
#else
	{}
	bool eof()const { return feof(target); }
#endif
	char get()
	{
		if(__eof) return EOF;
#ifdef OPENIOBUF
		if(buf_p==BUFSIZE) flush();
		char ch=buf[buf_p++];
#else
		char ch=getc(target);
#endif
		return ~ch?ch:(__eof=true,EOF);
	}
	void unget(char c)
	{
		__eof=false;
#ifdef OPENIOBUF
		buf_p--;
#else
		ungetc(c,target);
#endif
	}
	explicit operator bool()const { return !__eof; }
	FastInput &operator >>(char &x)
	{ while(isspace(x=get()));return *this; }
	template<typename T>
	std::enable_if_t<std::is_integral<T>::value,FastInput&> operator >>(T &x)
	{
		char ch,sym=0;x=0;
		while(isspace(ch=get()));
		if(__eof) return *this;
		if(ch=='-') sym=1,ch=get();
		for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=get());
		return unget(ch),sym?x=-x:x,*this;
	}
	FastInput &operator >>(char *s)
	{
		while(isspace(*s=get()));
		if(__eof) return *this;
		for(;!isspace(*s) && !__eof;*(++s)=get());
		return unget(*s),*s='\0',*this;
	}
	FastInput &operator >>(std::string &s)
	{
		char str_buf[(1<<8)+1]={0},*p=str_buf;
		char *const buf_end=str_buf+(1<<8);
		while(isspace(*p=get()));
		if(__eof) return *this;
		for(s.clear(),p++;;p=str_buf)
		{
			for(;p!=buf_end && !isspace(*p=get()) && !__eof;p++);
			if(p!=buf_end) break;
			s.append(str_buf);
		}
		unget(*p),*p='\0',s.append(str_buf);
		return *this;
	}
	template<typename ...T>
	void read(T &...x)
	{ std::initializer_list<int>{(this->operator>>(x),0)...}; }
	template<typename Iter>
	void read(Iter begin,Iter end)
	{ while(begin!=end) (*this)>>*(begin++); }
}qin;

} // namespace FastIO
using FastIO::qin,FastIO::qout;

using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;

#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#define LOG(...) void()
#else
#define FILEIO(file)
#define LOG(...) fprintf(stderr,__VA_ARGS__)
#endif

namespace Math
{

// A class for 2D vectors.
template<typename T>
struct Vector2d
{
#define DEF_OP1(op) \
	Vector2d &operator op##=(const Vector2d &rhs) \
	{ return x op##= rhs.x,y op##= rhs.y,*this; } \
	Vector2d operator op(const Vector2d &rhs)const \
	{ return Vector2d(*this)op##=rhs; }
	T x,y;
	Vector2d(): x(0),y(0){}
	Vector2d(T _x,T _y): x(_x),y(_y){}
	DEF_OP1(+) DEF_OP1(-) DEF_OP1(*) DEF_OP1(/)
	Vector2d &operator *=(T scale)
	{ return x*=scale,y*=scale,*this; }
	friend Vector2d operator *(T scale,const Vector2d &u)
	{ return Vector2d(u)*=scale; }
	friend Vector2d operator *(const Vector2d &u,T scale)
	{ return Vector2d(u)*=scale; }
	friend auto cross(const Vector2d &u,const Vector2d &v)
	{ return u.x*v.y-u.y*v.x; }
	friend auto dot(const Vector2d &u,const Vector2d &v)
	{ return u.x*v.x+u.y*v.y; }
	friend auto abs(const Vector2d &u)
	{ return hypot(u.x,u.y); }
	friend auto abs2(const Vector2d &u)
	{ return u.x*u.x+u.y*u.y; }
	friend auto arg(const Vector2d &u)
	{ return atan2(u.y,u.x); }
	auto proj(const Vector2d &u)const
	{ return (*this)*(dot(u,*this)/abs2(*this)); }
	auto trunc(T r=1)const
	{ T l=abs(*this);return sgn(l)?(*this)*(r/l):*this; }
	auto rotate(T t)const
	{ return Vector2d(x*cos(t)-y*sin(t),x*sin(t)+y*cos(t)); }
	bool operator <(const Vector2d &rhs)const
	{ return x!=rhs.x?x<rhs.x:y<rhs.y; }
	bool operator ==(const Vector2d &rhs)const
	{ return FEQ(x,rhs.x) && FEQ(y,rhs.y); }
	bool operator !=(const Vector2d &rhs)const
	{ return FNE(x,rhs.x) || FNE(y,rhs.y); }
#undef DEF_OP1
};

} // namespace Math
using RVec=Math::Vector2d<LD>;

constexpr int V=1e6;
int n,W,m,a[100005],b[100005];

map<int,int> mp;
int f[100005][20],dep[100005];
RVec p[100005];
RVec intersect(int x,int y)
{
	if(x==1) return RVec(W,b[y]);
	if(y==1) return RVec(W,b[x]);
	return RVec(LD(a[x]-a[y])*W/(a[x]-a[y]-b[x]+b[y]),
				-LD(a[y]*b[x]-a[x]*b[y])/(a[x]-a[y]-b[x]+b[y]));
}
void norm(int &num,int &den)
{
	int g=__gcd(num,den);
	num/=g,den/=g;
}
void add(int u,int fa)
{
	f[u][0]=fa,dep[u]=dep[fa]+1;
	for(int i=1;(1<<i)<=dep[u];i++)
		f[u][i]=f[f[u][i-1]][i-1];
	mp[a[u]]=u;
	p[u]=intersect(u,fa);
}
int lca(int u,int v)
{
	if(dep[u]<dep[v]) swap(u,v);
	for(int i=18;i>=0;i--)
		if(dep[f[u][i]]>=dep[v])
			u=f[u][i];
	if(u==v) return u;
	for(int i=18;i>=0;i--)
		if(f[u][i]!=f[v][i])
			u=f[u][i],v=f[v][i];
	return f[u][0];
}

int main()
{
	qin>>n>>W;
	m=3;
	a[2]=b[2]=0,add(2,1);
	a[3]=b[3]=V+1,add(3,1);
	for(int o=1;o<=n;o++)
	{
		int opt,s,t;
		qin>>s>>t>>opt;
		auto it=mp.lower_bound(s);
		RVec vs(0,s),vt(W,t);
		int u=prev(it)->second,v=it->second,w=lca(u,v);
		for(int i=__lg(dep[u]-dep[w]);i>=0;i--)
			if(dep[f[u][i]]>dep[w] && cross(vt-vs,p[f[u][i]]-vs)<=0)
				u=f[u][i];
		for(int i=__lg(dep[v]-dep[w]);i>=0;i--)
			if(dep[f[v][i]]>dep[w] && cross(vt-vs,p[f[v][i]]-vs)>=0)
				v=f[v][i];
		if(cross(vt-vs,p[u]-vs)<=0)
			u=f[u][0];
		if(cross(vt-vs,p[v]-vs)>=0)
			v=f[v][0];
		w=(u==w?v:v==w?u:0);
		assert(w);
		int xnum=(w==1?W:(s-a[w])*W),xden=(w==1?1:(s-a[w]-t+b[w])),
			ynum=(w==1?t:-(a[w]*t-s*b[w])),yden=(w==1?1:(s-a[w]-t+b[w]));
		norm(xnum,xden);
		norm(ynum,yden);
		qout<<'('<<xnum<<'/'<<xden<<','
				 <<ynum<<'/'<<yden<<")\n";
		if(opt) m++,a[m]=s,b[m]=t,add(m,w);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 6580kb

input:

4 3
1 2 1
2 1 1
3 1 0
3 2 1

output:

(3/1,2/1)
(3/2,3/2)
(2/1,5/3)
(3/1,2/1)

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 135ms
memory: 6924kb

input:

300000 894665
1 1000000 1
2 999999 1
3 999997 1
4 999994 1
5 999990 1
6 999985 1
7 999979 1
8 999972 1
9 999964 1
10 999955 1
11 999945 1
12 999934 1
13 999922 1
14 999909 1
15 999895 1
16 999880 1
17 999864 1
18 999847 1
19 999829 1
20 999810 1
21 999790 1
22 999769 1
23 999747 1
24 999724 1
25 999...

output:

(894665/1,1000000/1)
(894665/2,1000001/2)
(894665/3,1000003/3)
(894665/4,500003/2)
(178933/1,200002/1)
(894665/6,1000015/6)
(894665/7,1000021/7)
(894665/8,250007/2)
(894665/9,1000036/9)
(178933/2,200009/2)
(894665/11,1000055/11)
(894665/12,500033/6)
(894665/13,1000078/13)
(894665/14,1000091/14)
(178...

result:

wrong answer 1401st lines differ - expected: '(147564792569/342960,824693955521/1714800)', found: '(-303470689/571600,60234689/1714800)'