QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212380#6733. Moniphant SleepExplodingKonjacTL 6ms50712kbC++207.1kb2023-10-13 15:26:082023-10-13 15:26:08

Judging History

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

  • [2023-10-13 15:26:08]
  • 评测
  • 测评结果:TL
  • 用时:6ms
  • 内存:50712kb
  • [2023-10-13 15:26:08]
  • 提交

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[numeric_limits<T>::digits10+1],*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[--buf_p]=c;
#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;
constexpr int INF=1e9;

#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

struct Line
{
	int k,b;
	Line(): k{},b{} {}
	Line(int _b): k(0),b(_b) {}
	Line(int _k,int _b): k(_k),b(_b) {}
#define DEF_OP(op) \
	Line &operator op##=(const Line &rhs) \
	{ return k op##=rhs.k,b op##=rhs.b,*this; } \
	Line operator op(const Line &rhs)const \
	{ return Line(*this)op##=rhs; }
	DEF_OP(+) DEF_OP(-)
#undef DEF_OP
	Line operator -()const
	{ return Line(-k,-b); }
	int operator ()(int x)const
	{ return k*x+b; }
	Line operator ()(const Line &rhs)const
	{ return Line(k*rhs.k,k*rhs.b+b); }
	bool operator ==(const Line &rhs)const
	{ return k==rhs.k && b==rhs.b; }
};
struct Node
{
	Line A,B;
	Node(): A(1,0),B(0,0) {}
	Node(const Line &_A,const Line &_B): A(_A),B(_B) {}
	Node operator ()(const Node &rhs)const
	{ return Node(A(rhs.A),B(rhs.A)+rhs.B); }
	bool operator <(auto)const
	{ return false; }
	bool operator ==(const Node &rhs)const
	{ return A==rhs.A && B==rhs.B; }
};
class Func final: private vector<pair<int,Node>>
{
 private:
	using BaseT=vector<pair<int,Node>>;
 public:
	Func(): BaseT{} {}
	Func(const BaseT &vec): BaseT(vec) {}
	Func operator ()(const Func &rhs)const
	{
		Func res;
		auto add=[&](int k,auto &&x)
		{
			if(res.empty() || x!=res.back().second)
				res.emplace_back(k,x);
			else res.back().first=k;
		};
		int l=-INF,r;
		for(auto i=rhs.begin(),j=begin();i!=rhs.end();i++)
		{
			auto &f=i->second.A;
			r=i->first;
			int fl=f(l),fr=min(INF,f(r));
			while(j->first<fl) j++;
			do
			{
				int rr=i->first;
				if(f.k) rr=min(rr,j->first-f.b);
				add(rr,j->second(i->second));
			} while((j++)->first<fr);
			j--,l=r+1;
		}
		res.back().first=INF;
		return res;
	}
	Node operator ()(int x)const
	{
		auto it=lower_bound(begin(),end(),pair(x,Node{}));
		return it->second;
	}
	bool operator ==(const Func &rhs)const
	{ return static_cast<const BaseT&>(*this)==static_cast<const BaseT&>(rhs); }
};

const Line _X(1,0);
const Func E({{INF,Node(_X,0)}}),
		   F1({{INF,Node(_X+1,1)}}),
		   F2({{0,Node(-INF,-1)},{INF,Node(_X-1,-1)}}),
		   F3({{-1,Node(0,0)},{INF,Node(_X,0)}}),
		   F4({{-1,Node(-INF,0)},{INF,Node(-INF,-_X)}});

int n,q;
Func t[2000005];
#define LC (i<<1)
#define RC (i<<1|1)
void build(int l,int r,int i=1)
{
	t[i]=E;
	if(l==r) return;
	int mid=(l+r)>>1;
	build(l,mid,LC),build(mid+1,r,RC);
}
inline void pushdown(int i)
{
	if(t[i]==E) return;
	t[LC]=t[i](t[LC]);
	t[RC]=t[i](t[RC]);
	t[i]=E;
}
void modify(int lq,int rq,const Func &f,int i=1,int l=1,int r=n)
{
	if(l>=lq && r<=rq) return t[i]=f(t[i]),void();
	int mid=(l+r)>>1;
	pushdown(i);
	if(mid>=lq) modify(lq,rq,f,LC,l,mid);
	if(mid<rq) modify(lq,rq,f,RC,mid+1,r);
}
Func query(int p,int i=1,int l=1,int r=n)
{
	if(l==r) return t[i];
	int mid=(l+r)>>1;
	Func res=(mid>=p?query(p,LC,l,mid):query(p,RC,mid+1,r));
	if(t[i]==E) return res;
	else return t[i](res);
}

int main()
{
	qin>>n>>q;
	build(1,n);
	while(q--)
	{
		int opt,l,r;
		qin>>opt>>l>>r;
		if(opt==1) modify(l,r,F1);
		else if(opt==2) modify(l,r,F2);
		else if(opt==3) modify(l,r,F3);
		else if(opt==4) modify(l,r,F4);
		else qout<<(500000+query(l)(-INF).B(0))<<'\n';
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 6ms
memory: 50392kb

input:

1 9
1 1 1
1 1 1
1 1 1
3 1 1
2 1 1
1 1 1
1 1 1
4 1 1
5 1 1

output:

500004

result:

ok 1 number(s): "500004"

Test #2:

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

input:

3 7
2 1 3
3 1 3
1 1 3
1 1 3
5 1 1
4 1 3
5 1 1

output:

500001
499999

result:

ok 2 number(s): "500001 499999"

Test #3:

score: -100
Time Limit Exceeded

input:

500000 500000
2 132991 371170
5 15281 15281
1 278642 397098
2 152103 176573
2 13797 47775
3 139320 370045
3 79054 432340
3 82556 212775
4 270171 469418
5 148000 148000
3 371255 401414
5 71051 71051
2 358945 473071
2 231663 265401
2 20243 58131
1 247710 313373
5 154549 154549
1 17317 233265
5 37602 3...

output:

500000
499999
500000
499998
499999
500000
500000
499997
500000
499997
499997
499999
499998
500000
499997
500000
499999
500001
499999
499999
499997
499997
499996
499998
500000
500001
500001
499996
499998
499999
499996
499999
500001
500000
500000
500002
500002
499997
500001
499997
499995
499999
500004...

result: