QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212439#6733. Moniphant SleepExplodingKonjacAC ✓915ms160124kbC++208.5kb2023-10-13 15:54:362023-10-13 15:54:36

Judging History

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

  • [2023-10-13 15:54:36]
  • 评测
  • 测评结果:AC
  • 用时:915ms
  • 内存:160124kb
  • [2023-10-13 15:54:36]
  • 提交

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

template<typename T,size_t MAXN>
class SmallVector
{
 private:
	char mem[MAXN*sizeof(T)];
	size_t n;
 public:
	using pointer=T*;
	using const_pointer=const T*;
	using reference=T&;
	using const_reference=const T&;
	using iterator=T*;
	using const_iterator=const T*;
	SmallVector(): mem{},n{} {}
	~SmallVector() { while(n) pop_back(); }
	SmallVector(const initializer_list<T> &ils): mem{},n{}
	{ for(auto &i: ils) push_back(i); }
	size_t size()const
	{ return n; }
	bool empty()const
	{ return !n; }
	reference back()
	{ return *(end()-1); }
	const_reference back()const
	{ return *(end()-1); }
	reference operator [](size_t i)
	{ return *static_cast<T*>(mem+i*sizeof(T)); }
	const_reference operator[](size_t i)const
	{ return *static_cast<const T*>(mem+i*sizeof(T)); }
	void push_back(const T &x)
	{ new(end()) T(x),n++; }
	template<typename ...Args>
	void emplace_back(Args &&...x)
	{ new(end()) T(forward<Args&&>(x)...),n++; }
	void pop_back()
	{ back().~T(),n--; }
	iterator begin()
	{ return static_cast<iterator>(static_cast<void*>(mem)); }
	iterator end()
	{ return static_cast<iterator>(static_cast<void*>(mem+n*sizeof(T))); }
	const_iterator begin()const
	{ return static_cast<const_iterator>(static_cast<const void*>(mem)); }
	const_iterator end()const
	{ return static_cast<const_iterator>(static_cast<const void*>(mem+n*sizeof(T))); }
};

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 SmallVector<pair<int,Node>,3>
{
 private:
	using BaseT=SmallVector<pair<int,Node>,3>;
 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;
	}
};

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;
struct TreeNode{ bool ise;Func f;}t[2000005];
#define LC (i<<1)
#define RC (i<<1|1)
void build(int l,int r,int i=1)
{
	t[i]=TreeNode{true,E};
	if(l==r) return;
	int mid=(l+r)>>1;
	build(l,mid,LC),build(mid+1,r,RC);
}
inline void pushTag(int i,const Func &f)
{
	t[i].ise=false;
	t[i].f=f(t[i].f);
}
inline void pushdown(int i)
{
	if(t[i].ise) return;
	pushTag(LC,t[i].f),pushTag(RC,t[i].f);
	t[i].f=E,t[i].ise=true;
}
void modify(int lq,int rq,const Func &f,int i=1,int l=1,int r=n)
{
	if(l>=lq && r<=rq) return pushTag(i,f);
	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].f;
	int mid=(l+r)>>1;
	Func res=(mid>=p?query(p,LC,l,mid):query(p,RC,mid+1,r));
	return t[i].ise?res:t[i].f(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: 23ms
memory: 159800kb

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: 19ms
memory: 159920kb

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: 0
Accepted
time: 915ms
memory: 159988kb

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:

ok 99850 numbers

Test #4:

score: 0
Accepted
time: 893ms
memory: 160100kb

input:

500000 500000
1 82261 414004
4 128531 435780
1 182288 357334
1 384377 425512
5 400207 400207
5 12158 12158
4 287819 439382
4 273623 387675
4 141825 285941
3 69773 134995
4 29380 264126
1 294648 422834
5 39538 39538
3 142540 417717
5 234932 234932
3 203802 448531
4 70427 154922
5 350852 350852
1 1512...

output:

500002
500000
500000
500002
500003
500000
499998
499999
500000
500001
499998
499996
500001
499997
499995
499998
499995
499996
499994
499998
499999
500000
499996
499988
499995
499999
499992
500001
499995
499991
499991
499995
500002
499987
499992
500000
500001
499988
499987
499989
499989
499992
500001...

result:

ok 99856 numbers

Test #5:

score: 0
Accepted
time: 885ms
memory: 160044kb

input:

500000 500000
5 72042 72042
3 413594 434238
2 361496 397187
1 269630 487427
3 242649 269514
1 54440 379912
4 186602 218641
3 276439 423353
3 135538 386886
1 18494 105835
2 280844 281961
4 295419 431095
2 371614 462384
3 287902 310870
4 16615 433795
4 190316 318613
3 212017 398069
5 9605 9605
4 91266...

output:

500000
500000
500002
500002
500000
500003
500002
500000
500000
500001
500002
500000
500002
500004
499997
500001
500003
500002
500000
500001
500001
500004
500000
500002
500001
500001
499999
500004
500001
500001
500001
500006
499998
499997
500006
500005
500005
500001
499995
499999
500006
500000
500001...

result:

ok 100105 numbers

Test #6:

score: 0
Accepted
time: 904ms
memory: 160044kb

input:

500000 500000
2 5190 91049
4 128857 445467
3 223530 277888
2 40982 105310
1 407309 471677
2 28575 133349
1 32121 490377
5 253892 253892
3 302998 419525
2 113017 482504
1 69934 143033
4 48272 361234
5 2861 2861
1 73851 222387
4 353590 463398
5 246538 246538
4 172175 241916
3 123903 463282
5 265403 26...

output:

500001
500000
500000
500000
500000
499999
499999
500000
500000
499996
499996
499999
499998
500000
499998
499999
500000
499998
499999
500002
499999
499999
500001
499999
500002
500000
499997
499994
500000
499994
499993
500002
499992
499988
499988
500001
499996
500002
500002
499995
499990
499992
500002...

result:

ok 100018 numbers

Test #7:

score: 0
Accepted
time: 912ms
memory: 160044kb

input:

500000 500000
1 92884 302553
3 55209 426930
4 274477 421174
1 116041 243779
2 184334 487953
3 377378 416732
2 78059 458714
1 117519 134853
5 30966 30966
4 6896 243400
4 133516 387611
5 274315 274315
4 1255 321875
1 223029 472140
1 134662 463400
1 271092 375546
4 154845 453545
2 283001 468220
3 20643...

output:

500000
499999
500000
500000
500002
500003
500000
500003
500000
500000
499996
500001
499994
499999
499996
499994
499995
499995
499999
499998
500001
499992
499990
499990
499990
499990
499998
499997
499996
499991
499991
499994
499998
499997
499990
499990
499997
499996
499990
499995
499991
499991
499993...

result:

ok 100214 numbers

Test #8:

score: 0
Accepted
time: 894ms
memory: 160048kb

input:

500000 500000
5 417190 417190
5 343155 343155
3 238196 397249
2 190674 437636
3 292166 453486
3 33110 230933
1 203367 265293
5 224931 224931
4 147852 361144
5 267505 267505
3 135127 384589
3 223472 441256
1 149972 160456
1 207060 334058
1 461029 486155
1 180058 382221
3 122724 138722
2 438731 448303...

output:

500000
500000
500000
499999
499999
500000
499999
499999
500000
499997
499997
499998
499996
499998
499997
500000
500000
500000
500000
499999
500003
500001
500000
500000
499998
499998
499998
499996
499998
499995
500003
499998
499999
500005
499998
500001
499997
500000
500000
500006
500000
500003
500004...

result:

ok 99758 numbers

Test #9:

score: 0
Accepted
time: 886ms
memory: 160124kb

input:

500000 500000
5 463523 463523
5 113643 113643
2 381674 410504
1 22966 114703
5 16811 16811
5 273752 273752
2 272169 420247
2 71593 112069
4 171364 379367
3 56291 187294
1 151339 169092
1 191063 393959
4 96567 345115
5 47859 47859
2 447869 485334
1 148875 281623
3 57575 88435
3 7881 207243
5 84967 84...

output:

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

result:

ok 99487 numbers

Test #10:

score: 0
Accepted
time: 887ms
memory: 159980kb

input:

500000 500000
4 315829 368195
3 414015 486000
2 148601 309648
3 323477 435058
2 7730 312072
1 91960 499853
5 243073 243073
4 308460 375604
1 40395 150056
5 116054 116054
3 142106 406335
3 166868 380856
4 101797 181638
1 31743 237233
4 190434 259395
1 91100 332530
3 156661 282976
5 98708 98708
1 1997...

output:

499999
500001
500003
499999
500003
500001
500001
500001
499999
500001
499999
500002
499999
500007
500002
500004
499998
499999
500006
499999
499999
499997
499997
500001
499997
499994
500002
499997
499998
500002
499996
499999
499998
500000
500001
500002
499997
500000
500003
500005
500003
500002
500003...

result:

ok 99671 numbers

Test #11:

score: 0
Accepted
time: 907ms
memory: 160104kb

input:

500000 500000
2 338729 402306
2 260139 296789
2 348628 378006
4 151959 263061
3 274633 499362
3 132916 136988
3 19132 495822
3 47431 471607
2 144550 199941
3 52929 115332
1 17302 132635
2 195980 480390
3 173564 289435
1 219579 286571
2 319857 387911
1 444872 466260
3 117298 214290
2 245260 322033
1 ...

output:

500003
500000
499999
500001
500003
499999
500005
500000
499999
499999
500005
500000
499996
500001
500001
499998
499999
499996
499998
499998
499993
500002
499993
499997
499998
499998
499998
499992
499993
499997
499997
499993
499994
499995
499988
499996
499989
499992
499994
499997
500001
499999
500000...

result:

ok 99951 numbers

Test #12:

score: 0
Accepted
time: 907ms
memory: 160044kb

input:

500000 500000
4 43080 426035
2 446418 498842
2 261117 446761
3 174657 283077
3 475449 484835
5 346061 346061
2 312006 425604
4 154903 350468
1 53920 374405
2 289214 481287
5 181600 181600
3 72854 222601
5 289827 289827
5 18524 18524
4 304780 417551
1 307684 430391
2 238310 271890
1 196257 364172
5 4...

output:

499999
500001
499999
500000
500000
500002
500003
500001
500003
500003
500005
500005
500002
500006
500004
500003
500000
500004
500002
500007
500000
499999
500000
500002
500001
499998
499998
499998
499999
500001
500002
500000
500000
500003
499998
499999
500003
500001
500001
499999
499997
499999
500000...

result:

ok 100352 numbers