QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#563015#1643. Archeologistsprime-idealWA 65ms25356kbC++204.0kb2024-09-14 00:12:082024-09-14 00:12:08

Judging History

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

  • [2024-09-14 00:12:08]
  • 评测
  • 测评结果:WA
  • 用时:65ms
  • 内存:25356kb
  • [2024-09-14 00:12:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define forw(_,l,r) for(auto _=(l);_<(r);++_)
#define fors(_,r,l) for(auto _=(r);_>(l);--_)
#define RN return
#define MT make_tuple
#define fastio cin.tie(0),cout.tie(0),ios::sync_with_stdio(0);
void read(){}
template<typename T,typename...Types>
void read(T& x, Types&...args){
  x=0; char c=' '; bool sgn=0;
  while(isspace(c))c=getchar();
  if(c=='-')c=getchar(),sgn=1;
  while(isdigit(c))x=10*x+c-'0',c=getchar();
  if(sgn)x=-x;
  read(args...);
}

typedef vector<int> vi;
typedef long long ll;
const int NUM=250000*2+10;
const ll INFL=0x3f3f3f3f3f3f3f3f;
random_device rd;
mt19937 gen0(rd());
auto gen(){auto x=gen0();RN x<0?-x:x;}
struct tree{
  typedef int vec[NUM];
	typedef ll vecl[NUM];
	vecl data{},taga{},tagb{};
  vec siz{},rnd{},fa{},sn[2]{}; 
	int top=1,size=0;
  tree(){
    data[1]=INFL,siz[1]=1;tagb[1]=1;
  }
  inline int ssiz(int id,int opt){RN siz[sn[opt][id]];}
  inline int sid(int id){RN sn[1][fa[id]]==id;}
  void descend(int id){//id!=0
    ll t=taga[id];
		if(t){
			taga[id]=0;data[id]+=t;
			forw(i,0,2)taga[sn[i][id]]+=t;
		}t=tagb[id];
		if(t){
			tagb[id]=0;
			int lsiz=ssiz(id,0);
			tagb[sn[0][id]]+=t;
			data[id]+=t*lsiz;
			taga[sn[1][id]]+=t*lsiz+t;
			tagb[sn[1][id]]+=t;
		}
  }
  void sync(int id){
    siz[id]=siz[sn[0][id]]+siz[sn[1][id]]+1;
  }
  void rsync(int id){if(id)sync(id),rsync(fa[id]);}
  void rotate(int id){if(fa[id]&(-2)){
    int lt=sid(id),rt=lt^1;
    int nds[]={sn[lt][id],id,sn[rt][id],fa[id],sn[rt][fa[id]],fa[fa[id]]};
		for(int i:{3,1,4,0,2})descend(nds[i]);
    sn[sid(nds[3])][nds[5]]=nds[1];
    fa[nds[1]]=nds[5], sn[rt][nds[1]]=nds[3],
    fa[nds[3]]=nds[1], sn[lt][nds[3]]=nds[2];
    fa[nds[2]]=nds[3];
    sync(nds[3]); sync(id);
  }}
  void _ins(int rk,int d,int& id,int f){
    if(id==0){
      id=++top;
      tie(fa[id],rnd[id],siz[id],data[id])
      =MT(f     ,gen()  ,1      ,d       );
      rsync(f);
      for(int e=id;e;e=fa[e])if(rnd[e]<rnd[fa[e]])rotate(e);
    }else{
			descend(id);
      int lsiz=ssiz(id,0);
      if(rk<=lsiz)_ins(rk,d,sn[0][id],id);
      else _ins(rk-lsiz-1,d,sn[1][id],id);
    }
  }
  ll& _find_ele(int id,int rk){
		descend(id);
    int lsiz=ssiz(id,0),chd;
    if(rk<lsiz&&(chd=sn[0][id]))RN _find_ele(chd,rk);
    else if(rk>lsiz&&(chd=sn[1][id]))RN _find_ele(chd,rk-lsiz-1);
    else RN data[id];
  }
  void erase(int rk,char mode=0){
		if(mode==0){--size;}
    int id=mode?rk:&_find_ele(1,rk)-data;
    char opt=bool(sn[1][id])*2+bool(sn[0][id]);
    if(opt==3){
      int leaf=sn[0][id];
			while(descend(leaf),sn[1][leaf])leaf=sn[1][leaf];
      data[id]=data[leaf];rsync(id);erase(leaf,1); 
    }else{
      int son=0;if(opt)son=sn[opt-1][id],fa[son]=fa[id];
      sn[sid(id)][fa[id]]=son;rsync(fa[id]);
    }
  }
  void _inc(int id,int l,int r,ll a,ll b){
    descend(id);
		int lsiz=ssiz(id,0),chd,l2=l,r2=r;
		if(l==0&&r==siz[id]){taga[id]+=a,tagb[id]+=b;RN;}
		if(l<=lsiz&&r>lsiz)data[id]+=a+b*lsiz,r2=lsiz,l2=r2+1;
		if(l<=lsiz&&l!=r2&&(chd=sn[0][id]))_inc(chd,l,r2,a,b);
		if(r>lsiz&&l2!=r&&(chd=sn[1][id]))_inc(chd,l2-lsiz-1,r-lsiz-1,a+b*(lsiz+1),b);
  }
  void insert(int rk,int d){++size;int t=1;_ins(rk,d,t,0);}
	void inc(int k){RN _inc(1,0,size,0,k);}
  ll& operator[](int rk){RN _find_ele(1,rk);}
  void print(vi& v,int id=1){
		descend(id);
    int chd;
    if(chd=sn[0][id])print(v,chd);
		if(id!=1){v.push_back(data[id]);}
    if(chd=sn[1][id])print(v,chd);
  }
}tr;

int find_max_id(){
	int l=0,m1,m2,r=tr.size-1,d,t;ll mx=-INFL;
	for(;d=r-l,t=d/3,m1=l+t,m2=m1+t,d>=3;){
		ll y0=tr[l],y1=tr[m1],y2=tr[m2],y3=tr[r];
		if(y1<=y2)l=m1; if(y1>=y2)r=m2;
	}int id=l;
	forw(i,l,r+1)if(tr[i]>mx)mx=tr[i],id=i;
	RN id;
}

int main()
{
	tr.insert(0,0); int n; read(n);
	forw(i,0,n+1){
		int p=0;if(i<n)read(p);
		int id=find_max_id();ll x=tr[id];
		forw(_,0,2)tr.insert(id,x);
		tr.erase(0); tr.inc(p);
		// vi v;tr.print(v);
		// for(auto x:v)cout<<x<<' '; cout<<endl;
	}cout<<tr[0];
  RN 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 3 -4 2 1

output:

8

result:

ok single line: '8'

Test #2:

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

input:

4
1 1 -2 3

output:

5

result:

ok single line: '5'

Test #3:

score: 0
Accepted
time: 5ms
memory: 25356kb

input:

5
-1 -3 0 -5 -4

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 2ms
memory: 25160kb

input:

100
0 -269 232 121 -422 -439 -69 478 -385 -351 38 271 -100 -153 -438 -143 41 50 200 60 92 266 340 282 -212 73 -337 70 -439 291 -191 428 303 -439 -92 -174 247 -398 2 -72 199 141 -145 -138 -226 34 120 -265 -351 20 -366 330 -381 -234 239 29 -358 -371 100 96 -179 249 380 15 201 -492 -159 -495 -366 -302 ...

output:

35977

result:

ok single line: '35977'

Test #5:

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

input:

100
376 200 164 331 396 -419 186 358 318 344 -485 58 -185 -499 -216 489 -149 -43 485 -114 -288 -489 -495 335 385 -152 -495 -64 476 438 292 -481 83 -242 -236 -34 -183 230 474 446 463 434 -481 445 220 -491 -418 72 90 -40 302 -223 251 432 118 319 -493 -209 291 203 -200 -490 -435 -260 332 -434 223 300 -...

output:

48045

result:

ok single line: '48045'

Test #6:

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

input:

100
-313 -36 144 -76 368 -176 -8 112 52 -161 -125 145 -101 5 -308 -49 -71 26 -288 211 195 97 186 107 141 238 292 -32 -60 120 -18 288 184 13 299 -370 34 -166 272 -208 204 275 -161 -85 338 147 -54 8 -170 -143 -142 279 171 -233 -47 106 -394 -125 176 -83 -15 -319 -267 -98 -346 -161 37 244 148 322 139 80...

output:

52502

result:

ok single line: '52502'

Test #7:

score: 0
Accepted
time: 3ms
memory: 25356kb

input:

100
-263 -142 260 72 233 413 218 -30 33 97 74 416 -51 -213 417 -345 356 372 85 358 -414 -10 369 -425 245 300 442 98 -374 105 -226 385 77 458 31 106 -75 134 -470 441 -57 110 332 -434 65 388 127 427 121 -377 -187 -290 -282 -436 -177 -40 -293 275 289 476 -170 -150 125 -235 132 -205 395 478 -43 -47 -318...

output:

104040

result:

ok single line: '104040'

Test #8:

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

input:

100
-285 -256 -109 -129 497 -96 286 275 -200 -161 -156 -368 479 422 64 -196 402 185 -114 8 26 439 76 179 -457 -182 -453 -334 438 449 227 246 -39 443 -98 194 159 105 -291 194 392 311 -71 430 296 239 -388 429 -118 -215 124 -33 -257 354 -335 -286 170 -21 -438 -375 -401 -22 43 466 90 29 434 431 -260 194...

output:

138349

result:

ok single line: '138349'

Test #9:

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

input:

100
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1...

output:

2550000

result:

ok single line: '2550000'

Test #10:

score: 0
Accepted
time: 52ms
memory: 25356kb

input:

10000
-1274 -2991 182 -4874 4603 2872 2444 1624 -4616 -1007 -882 -2944 2538 1107 4134 -1636 -2325 2088 4951 -1800 -3119 -3085 -3200 808 -236 -356 -2499 3414 -261 -4334 4899 -2886 2014 3019 -259 -2248 -545 -2750 -242 -2536 -3227 -2675 -3231 4357 1154 2170 3614 4299 -3633 3682 -3890 2690 1491 3677 145...

output:

199899353

result:

ok single line: '199899353'

Test #11:

score: 0
Accepted
time: 62ms
memory: 25120kb

input:

10000
-4800 2893 2719 4158 4791 733 4130 4194 -4745 -4525 -4759 -1673 -1963 3591 -1922 3264 -3983 3838 -1119 4620 4707 2501 -2222 -4267 -2718 -3848 2426 -4686 -3593 -4530 -4462 1067 231 584 3862 -2219 3017 3534 3644 4906 -3339 4669 738 -3877 -2412 2156 -4994 4718 -262 2666 -3462 -4559 222 932 -2492 ...

output:

557524676

result:

ok single line: '557524676'

Test #12:

score: 0
Accepted
time: 61ms
memory: 25128kb

input:

10000
4872 -1054 3601 -373 490 1283 -1775 4864 -2516 4513 -4642 -839 3461 872 -3982 -4053 4064 -581 429 958 431 -4324 -1513 -1994 3732 3433 -21 3187 -195 -3194 3612 -2037 -2430 3668 -369 871 4739 -2259 3856 -4288 3012 -2833 -4061 4681 -1753 604 2448 -1366 3913 4162 581 -2334 3615 -3356 -4967 4283 -1...

output:

641238704

result:

ok single line: '641238704'

Test #13:

score: 0
Accepted
time: 58ms
memory: 25356kb

input:

10000
-4403 -1750 -2813 -1606 -2909 1768 2406 199 -2215 -2268 125 -3199 594 -73 1598 2113 -2887 -3554 3939 -2359 -3560 2601 -3481 -295 -3484 351 -376 -2744 4681 1457 1174 500 -4425 -3499 -1199 -4146 511 2729 -968 3981 -1600 -676 -2439 -677 -3641 3339 -1356 4030 1263 -3995 -289 1755 1570 -4153 1950 3...

output:

825849477

result:

ok single line: '825849477'

Test #14:

score: 0
Accepted
time: 65ms
memory: 25112kb

input:

10000
1592 -1249 1133 1803 1833 4557 1378 130 -4148 -1130 -2104 -3657 -4901 -875 -74 -4790 598 -4233 -927 -1867 2716 1015 -830 -1656 -4754 -4115 3552 -89 -2514 2623 404 -1149 1447 -3295 2101 -4605 1004 -2977 -2521 -1013 2148 2935 3959 -2805 -4873 2619 -3185 2947 4515 -4962 3993 3875 4872 3600 -2107 ...

output:

739499123

result:

ok single line: '739499123'

Test #15:

score: -100
Wrong Answer
time: 56ms
memory: 25112kb

input:

10000
100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 ...

output:

902992609376

result:

wrong answer 1st lines differ - expected: '2500500000000', found: '902992609376'