QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#647662#4253. RobotCap1taL10 305ms113716kbC++148.7kb2024-10-17 15:08:012024-10-17 15:08:07

Judging History

This is the latest submission verdict.

  • [2024-10-17 15:08:07]
  • Judged
  • Verdict: 10
  • Time: 305ms
  • Memory: 113716kb
  • [2024-10-17 15:08:01]
  • Submitted

answer

// Problem: B - 李超线段树
// Contest: Virtual Judge - 炼石计划第六周综合题单
// URL: https://vjudge.net/contest/663209#problem/B
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// Genshin Impact launch
// ZYB TXDY
// 
// Powered by CP Editor (https://cpeditor.org)

//%^~
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
// #include <bits/extc++.h>
#define MAXN 500005
#define eps 1e-10
#define foru(a, b, c) for (int a = (b); (a) <= (c); (a)++)
#define ford(a, b, c) for (int a = (b); (a) >= (c); (a)++)
#define uLL unsigned long long
#define LL long long
#define LXF int
#define RIN rin()
#define HH printf("\n")
#define All(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
inline LXF rin(){
	LXF x=0,w=1;char ch=0;
	while(ch<'0'||ch>'9'){
	if(ch=='-')	w=-1;
	ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
	x=x*10+(ch-'0');
	ch=getchar();
	}
	return x*w;
}
int ID;
#define ceinl(x) cein<<(x)<<endl;
#define ceink(x) cein<<(x)<<' ';
#define ceinp(x,y) cein<<(y)<<(x);
#define ceinpk(x,y) cein<<(y)<<(x)<<' ';
#define ceinpl(x,y) cein<<(y)<<(x)<<endl;
class Cap1taLDebug{
	#define DEBUGING
	ostream& buf;
public:
	Cap1taLDebug(ostream& out=cout):buf(out){}
	~Cap1taLDebug(){
		#ifdef DEBUGING
		buf.flush();
		#endif
	}
	static string int128ToString(__int128 x){
		if(x==0)	return "0";
		string s="",w="";
		if(x<0)	w="-",x*=-1;
		while(x%10) s+=(char)('0'+(int)(x%10)),x/=10;
		reverse(All(s));
		return w+s;
	}
	template<typename T1,typename T2>
	Cap1taLDebug& operator<<(const pair<T1,T2>& val){
		#ifdef DEBUGING
		(*this)<<"("<<val.first<<","<<val.second<<")";
		#endif
		return *this;
	}
	template<typename T,template<typename,typename...>class Container,typename...Args>
	Cap1taLDebug& operator<<(Container<T, Args...> container){
		#ifdef DEBUGING
		buf<<"{";
		bool fst=0;
		for(auto& val:container){
			if(!fst)	fst=true;
			else	buf<<",";
			(*this)<<val;	
		}
		buf<<"}";
		#endif
		return *this;
	}
	Cap1taLDebug& operator<<(const __int128& val){
		#ifdef DEBUGING
		buf<<int128ToString(val);
		#endif
		return *this;
	}
	template<typename T>
	Cap1taLDebug& operator<<(const T& val){
		#ifdef DEBUGING
		buf<<val;
		#endif
		return *this;
	}
	Cap1taLDebug& operator<<(ostream& (*manip)(ostream&)){
		#ifdef DEBUGING
		buf<<manip;
		#endif
		return *this;
	}
};
Cap1taLDebug cein(cout);
// Cap1taLDebug cein(cerr);
std::ostream& operator<<(ostream& os,__int128 val){
	os<<Cap1taLDebug::int128ToString(val);
	return os;
}
/*

*/
bool readCMD(){
	char c=getchar();
	while(c!='c' && c!='q')	c=getchar();
	bool ret=c=='c';
	while(c>='a' && c<='z')	c=getchar();
	return ret;
}
int n,m;
int a[MAXN];
class Input{
public:
	int t,opt,x,y;
}in[MAXN];

template<typename T=long long,typename F=double>
class CVec{
public:
	T x,y;
	static T CAbs(T val){return val<0?-val:val;}
	CVec(const T& x_=0,const T& y_=0):x(x_),y(y_){}
	CVec(const CVec& tg):x(tg.x),y(tg.y){}
	F disTo(CVec tg = CVec(0,0))const{return sqrtl(CAbs(x-tg.x)*CAbs(x-tg.x)+CAbs(y-tg.y)*CAbs(y-tg.y));}
	CVec& operator+=(const CVec& tg){x+=tg.x,y+=tg.y;return *this;	}
	CVec operator+(const CVec& tg)const{return CVec(*this)+=tg;}
	CVec& operator-=(const CVec& tg){x-=tg.x,y-=tg.y;return *this;	}
	CVec operator-(const CVec& tg)const{return CVec(*this)-=tg;}
	T operator*(const CVec& tg)const{return x*tg.y+y*tg.x;}
	class iterator{
		CVec* ptr;
		int index;
	public:
		iterator(CVec* ptr_,int index_):ptr(ptr_),index(index_){}
		T& operator*(){return (index==0)?(ptr->x):(ptr->y);}
		const T& operator*()const{return (index==0)?(ptr->x):(ptr->y);}
		iterator& operator++(){index++;return *this;}
		iterator operator++(int){auto tmp=*this;index++;return tmp;}
		bool operator!=(const iterator& other)const{return index!=other.index || ptr!=other.ptr;}
	};
	iterator begin(){return iterator(this,0);}
	iterator end(){return iterator(this,2);}
	#define CVec(...) CVec<>(__VA_ARGS__)
};
template<typename T=long long,typename F=double>
class CLine{
protected:
	typedef CVec<T,F> Point;
	Point xp,yp;
public:
	void fit(){if(xp.x>yp.x || (xp.x==yp.x && xp.y>yp.y))swap(xp,yp);}
	CLine(const T& xl=0,const T& yl=0,const T& xr=0,const T& yr=0):xp(xl,yl),yp(xr,yr){fit();}
	CLine(const T& xl,const T& yl,const Point& R=Point(0,0)):xp(xl,yl),yp(R){fit();}
	CLine(const Point& L,const T& xr=0,const T& yr=0):xp(L),yp(xr,yr){fit();}
	CLine(const Point& L,const Point& R):xp(L),yp(R){fit();}
	CLine(const CLine& val):xp(val.xp),yp(val.yp){fit();}
	static CLine asFunction(F k,F b){return CLine(0,b,1,k+b);}
	static CLine asFunction(Point p,F xr,F k){return CLine(p,xr,(F)p.y+(F)(xr-p.x)*k);}
	F length(){return (yp-xp).disTo();}
	F getVal(const F& pos)const{
		if(xp.x==yp.x)	return max(xp.y,yp.y);
		return (F)xp.y+(F)(yp.y-xp.y)*(F)((F)(pos-xp.x)/(F)(yp.x-xp.x));
	}
	Point getPoint(F pos){
		return Point(pos,getVal(pos));
	}
	const Point& x(){return xp;}
	const T& xl(){return xp.x;}
	const T& xr(){return yp.x;}
	const Point& y(){return yp;}
	void setX(const Point& x_){xp=x_;fit();}
	void setY(const Point& y_){yp=y_;fit();}
	void setX1(const T& val){xp.x=val;fit();}
	void setY1(const T& val){xp.y=val;fit();}
	void setX2(const T& val){yp.x=val;fit();}
	void setY2(const T& val){yp.y=val;fit();}
	CLine& operator+=(const Point& tg){xp+=tg,yp+=tg;return *this;}
	CLine operator+(const Point& tg){return CLine(*this)+=tg;}
	CLine& operator-=(const Point& tg){xp-=tg,yp-=tg;return *this;}
	CLine operator-(const Point& tg){return CLine(*this)-=tg;}
	class iterator{
		CLine* ptr;
		int index;
	public:
		iterator(CLine* ptr_,int index_):ptr(ptr_),index(index_){}
		Point& operator*(){return (index==0)?(ptr->xp):(ptr->yp);}
		const Point& operator*()const{return (index==0)?(ptr->xp):(ptr->yp);}
		iterator& operator++(){index++;return *this;}
		iterator operator++(int){auto tmp=*this;index++;return tmp;}
		bool operator!=(const iterator& other)const{return index!=other.index || ptr!=other.ptr;}
	};
	iterator begin(){return iterator(this,0);}
	iterator end(){return iterator(this,2);}
	bool inRange(const F& pos)const{return (F)xp.x<=pos && pos<=(F)yp.x;}
	bool lessAt(const CLine& y,const F& pos)const{return getVal(pos)<y.getVal(pos);}
	bool greaterAt(const CLine& y,const F& pos)const{return getVal(pos)>y.getVal(pos);}
	#define CLine(...) CLine<>(__VA_ARGS__)
};
class SegTree{
public:
	int lc,rc;
	CLine<>* L;
}tr[MAXN*30];
int pnum;
int newNode(){
	pnum++;
	tr[pnum].L=new CLine<>(0,-1e15,2e9,-1e15);
	return pnum;
}
int rt;
void Insert(int &p,LL l,LL r,CLine<> k){
	if(!p)	p=newNode();
	if(k.xl()<=l && r<=k.xr()){
		LL mid=(l+r)>>1ll;
		if(k.greaterAt(*tr[p].L,mid)){
			swap(k,*tr[p].L);
		}
		bool gl=k.greaterAt(*tr[p].L,l);
		bool gr=k.greaterAt(*tr[p].L,r);
		if(!gl && !gr)	return ;//FW
		if(gl)	Insert(tr[p].lc,l,mid,k);
		if(gr)	Insert(tr[p].rc,mid+1,r,k);
		return ;
	}
	LL mid=(l+r)>>1ll;
	if(k.xl()<=mid){
		Insert(tr[p].lc,l,mid,k);
	}
	if(k.xr()>mid){
		Insert(tr[p].rc,mid+1,r,k);
	}
	return ;
}
LL Query(int p,LL l,LL r,LL pos){
	if(!p)	return LLONG_MIN;
	if(l==r)	return tr[p].L->getVal(pos);
	LL mid=(l+r)>>1ll;
	if(pos<=mid)	return max(Query(tr[p].lc,l,mid,pos),(LL)tr[p].L->getVal(pos));
	else	return max(Query(tr[p].rc,mid+1,r,pos),(LL)tr[p].L->getVal(pos));
}
CLine<> lst[MAXN];
void PushSeg(CLine<> x){
	Insert(rt,0,2e9,x);
	if((x.x().y<0)||(x.y().y<0)){
		x.setY1(-x.x().y);
		x.setY2(-x.y().y);
		Insert(rt,0,2e9,x);
	}
}
void solve(bool SPE){ 
	n=RIN,m=RIN;
	foru(i,1,n){
		a[i]=RIN;
	}
	#ifdef DEBUGING
	if(SPE){
		
	}
	#endif
	foru(i,1,m){
		in[i].t=RIN;
		in[i].opt=readCMD();
		if(in[i].opt){
			in[i].x=RIN,in[i].y=RIN;
		}
	}
	foru(i,1,n){
		lst[i]=CLine(0,a[i],2e9,a[i]);
	}
	foru(i,1,m){
		if(in[i].opt!=1)	continue;
		// auto [t,opt,x,y]=in[i];
		auto t=in[i].t;
		auto opt=in[i].opt;
		auto x=in[i].x;
		auto y=in[i].y;
		if(lst[x].x().x<t){
			//Add
			auto add=CLine(lst[x].x(),lst[x].getPoint(t));
			// cein<<add<<endl;
			PushSeg(add);
		}
		lst[x]=CLine<>::asFunction(lst[x].getPoint(t),2e9,y);
	}
	foru(i,1,n){
		auto add=lst[i];
		// cein<<add<<endl;
		PushSeg(add);
	}
	foru(i,1,m){
		if(in[i].opt==1)	continue;
		auto t=in[i].t;
		auto opt=in[i].opt;
		auto x=in[i].x;
		auto y=in[i].y;
		printf("%lld\n",Query(rt,0,2e9,t));
	}
	
	return ;
}
/*
检查文件读写
检查多测清空
检查数组大小
*/
signed main()
{
	// #define RFILE
	// #define MULTITEST
	// #define TESTCASEID
	
	#ifdef RFILE
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
	#endif
	
	#ifdef MULTITEST
	int T=RIN;
	#else
	int T=1;
	#endif
	
	#ifdef TESTCASEID
	ID=RIN;
	#endif
	
	for(int i=1;i<=T;i++) solve(i==0);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 26116kb

input:

1999 2000
199 8854 -9513 9848 8434 -6615 -6770 4057 -9730 686 1586 6806 -511 -6328 -2250 2785 -4083 -3961 -711 9606 -9391 1041 -2844 -4889 993 -6955 -1982 -5300 9053 -5275 3950 -7977 -3652 8624 -716 -2013 -5229 -3686 -4602 -5031 9777 3802 491 -1354 -26 -3366 5285 5805 -7098 2233 -5967 -1318 -4553 63...

output:

86968438
360434523
838136414
913544562
969488608
1039885818
1109817781
1176515896
1251176599
1310476524
1510654766
1541254290
1558186230
1650869533
1683894444
1758250067
1785951331
1924000031
1993298953
2050165865
2254081337
2698178666
2750011758
2975976887
3216807039
3276625599
3332455240
335270492...

result:

wrong answer 4th numbers differ - expected: '913544563', found: '913544562'

Test #2:

score: 0
Wrong Answer
time: 5ms
memory: 26468kb

input:

1999 2000
6817 4353 -8180 954 -2553 1768 4986 -889 7032 -450 1234 -7637 9636 380 3607 -2296 -4881 -9025 2375 -1561 -8807 -3103 4385 8883 -2887 -1185 1960 6711 3478 -1056 -1717 -534 -9885 -6301 6011 5965 -9833 -5181 5329 3688 -6837 9023 64 -8326 3021 -7193 -9218 -4699 2354 -4720 1621 7361 -5233 9211 ...

output:

9999
6877566
19288910
55025322
173050121
235131941
259226075
297353495
487371773
672366281
768849281
844199177
852243863
1019578655
1077348683
1147535075
1160789843
1226398283
1261072277
1340915371
1413759421
1576022921
1664672671
1707990671
1778999971
1838562221
1977886871
2055492321
2318326971
235...

result:

wrong answer 101st numbers differ - expected: '9473364052', found: '9473364051'

Test #3:

score: 10
Accepted
time: 206ms
memory: 105972kb

input:

99659 99039
-39276177 -64464963 -70081363 -443045475 -655771408 -409419920 -285052520 -312069074 -936205590 -10621715 -908116392 -660740279 -953732094 -591542519 -194540162 -139991296 -705911340 -778931920 -474438963 -518208970 -59960466 -981034014 -514533441 -217486555 -711871023 -615144144 -631291...

output:

999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
...

result:

ok 49673 numbers

Test #4:

score: 0
Wrong Answer
time: 305ms
memory: 113716kb

input:

99572 579859
-100705410 -669206879 -432488010 -384767624 -742351351 -839681487 -968882737 -976751481 57117493 -959321678 -819420190 -325014480 -636525861 -382469947 -876672604 -213012287 -209210199 -875230847 -920443172 -731589320 -946964322 -789362448 -872075805 -828546101 51836817 -913319025 -8404...

output:

999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999959652
999959652
999959652
999959652
999959652
999959652
999959652
999959652
999959652
999959652
999959652
999959652
999959652
999959652
999959652
...

result:

wrong answer 16th numbers differ - expected: '999964257', found: '999959652'

Test #5:

score: 0
Wrong Answer
time: 278ms
memory: 111488kb

input:

99320 577219
-525813544 -959369807 -718451747 -533082399 -787662356 -531754846 -650759294 -381852570 -979346470 -644489626 -425559804 -332888497 -203462089 -292970440 -958637976 -533593640 53499163 -331134986 -296264838 -806780896 -651958364 -547743072 -590243769 -75974484 -843772303 -367318307 -443...

output:

999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
...

result:

wrong answer 1st numbers differ - expected: '999992360', found: '999978927'

Test #6:

score: 0
Wrong Answer
time: 19ms
memory: 26504kb

input:

90498 99230
-33558917 30715649 81001133 -12438113 81315374 -70949846 -71212693 66569129 -16194103 -63049353 -79869090 97189792 61301532 53180861 -26423528 -30279746 32502058 7951680 -97121356 -5044511 -4113729 82719257 96311627 80260870 -29075735 -31473462 -27928703 81572824 -89715849 85470402 -5284...

output:

106294952
110163416
118535792
121674188
127268720
127704968
131859284
137162984
139716728
142361108
151520324
153761324
159719396
164628680
167492180
175844636
185014808
186302636
187034696
195742724
204533420
207048320
213505388
220715432
226279088
230415476
231647528
234046892
240457148
243998924
...

result:

wrong answer 404th numbers differ - expected: '2063297531', found: '2063297530'

Test #7:

score: 0
Wrong Answer
time: 14ms
memory: 26000kb

input:

99124 99428
-29121705 73122072 14759978 -93785828 -52964748 50664810 -67789167 38732351 -57330970 48764999 -73647685 92261655 2267455 -21312555 -51092994 33675829 40607569 -85559394 -93024695 24124094 -45466947 -66665193 -99870070 -58435829 -56724651 -98854388 86610996 59912463 -27223092 85984568 94...

output:

106340510
113640698
116739890
122754640
124220766
127865950
128706392
135771234
142501746
142918910
150583550
157918850
162749170
171812008
180577442
182247096
185391794
194654232
201310892
209518444
210866742
213027412
213683098
222590248
225580256
231447498
239671018
249411498
250792730
251150014
...

result:

wrong answer 403rd numbers differ - expected: '2094505914', found: '2094505913'

Test #8:

score: 0
Wrong Answer
time: 187ms
memory: 103580kb

input:

99538 99031
-501609067 -774687736 -928215759 -477038092 -823455674 -871460165 -852927043 -704708804 -775793387 -521621627 -923721630 -811686668 -952989802 -841891941 -482572032 -509003031 -595485934 -831251065 -616219801 -580804479 -951849211 -783134298 -505096225 -625789647 -520043618 -798430551 -6...

output:

999996555
999996555
999996555
999996555
999996555
999996555
999996555
999996555
999996555
999996555
999996555
999996555
999996555
1003771859
1005263811
1005937379
1006453139
1010634605
1020280585
1024269825
1028141905
1038638165
1047767365
1050993325
1054639205
1056180845
1067217665
1072164485
10888...

result:

wrong answer 816th numbers differ - expected: '8281624497', found: '8281624496'

Test #9:

score: 0
Wrong Answer
time: 298ms
memory: 57528kb

input:

99483 590517
-508842 -191922 830365 -321837 163127 -225035 -3981 -222030 721775 -244372 -342954 -692168 -156349 -853744 -606213 687012 -401837 -920227 -198596 -14000 -345069 -628969 -386394 -590462 97339 -974255 -551821 -623120 -673402 -567398 278012 511781 29418 -975780 -416796 902045 -565858 -2455...

output:

7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342434
7342...

result:

wrong answer 1st numbers differ - expected: '999991', found: '7342434'

Test #10:

score: 0
Wrong Answer
time: 299ms
memory: 58252kb

input:

99801 597343
-32417 984702 259080 747296 807167 169192 454040 -426594 582296 321692 800273 962596 -968901 42596 -304443 574664 936854 271860 902411 38804 -688175 55613 31189 -930407 -544084 -164683 -442201 118338 -858190 -109300 682685 896380 -887043 357053 -908865 890420 -680972 632527 -106741 -668...

output:

2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799535
2799...

result:

wrong answer 1st numbers differ - expected: '999992', found: '2799535'