QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#626501#8951. 澡堂OccDreamer20 424ms354616kbC++145.0kb2024-10-10 09:44:362024-10-10 09:44:39

Judging History

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

  • [2024-10-10 09:44:39]
  • 评测
  • 测评结果:20
  • 用时:424ms
  • 内存:354616kb
  • [2024-10-10 09:44:36]
  • 提交

answer

#include<bits/stdc++.h>

#define vc vector
#define db double
#define fi first
#define se second
#define ll long long
#define mk make_pair
#define pb push_back
#define RI register int
#define PI pair<int,int>
#define ull unsigned long long
#define err cerr << "   -_-   " << endl
#define debug cerr << " ------------------- " << endl

#define input(x) freopen(#x".in","r",stdin)
#define output(x) freopen(#x".out","w",stdout)

#define NO puts("No")
#define YES puts("Yes")

//#define OccDreamer
#define int long long

using namespace std;

namespace IO{
	inline int read(){
		int X=0, W=0; char ch=getchar();
		while(!isdigit(ch)) W|=ch=='-', ch=getchar();
		while(isdigit(ch)) X=(X<<1)+(X<<3)+(ch^48), ch=getchar();
		return W?-X:X;
	}
	inline void write(ll x){
		if(x<0) x=-x, putchar('-');
		if(x>9) write(x/10);
		putchar(x%10+'0');
	}
	inline void sprint(ll x){write(x), putchar(32);}
	inline void eprint(ll x){write(x), putchar(10);}
}using namespace IO;

const int MAXN = 1e6+5;
const int mod = 998244353;
const ll inf = 1e18;

int n, m, q, T, anc[20][MAXN], b[MAXN];
int len[MAXN], nxt[MAXN], topf, stk[MAXN], x, t;

vc<ll> num[10];

ll S, sum[20][MAXN], a[MAXN], ans, nowmaxn[10], maxr[10];

inline void prework(){
	for(int i=0;i<m;++i){
		topf=0; stk[0]=num[i].back()+m;
		for(int j=len[i];j>=1;--j){
			//(i,j) - > j*m+i
			while(topf && a[stk[topf]]<a[num[i][j]]) --topf;
			nxt[num[i][j]]=stk[topf]; stk[++topf]=num[i][j];
		}
	}
	for(int i=1;i<=n;++i)
		sum[0][i]=1ll*(nxt[i]-i)/m*a[i], anc[0][i]=nxt[i];
	for(int i=1;i<=19;++i)
		for(int j=1;j<=n;++j) sum[i][j]=sum[i-1][j]+sum[i-1][anc[i-1][j]], anc[i][j]=anc[i-1][anc[i-1][j]];
	return ;
}

inline pair<ll,ll> add(ll maxn, int g, int l, int r, ll delta){
	if(l>r) return mk(maxn,0ll);
	int p=num[g][l], pos=r, lmt=num[g][r];
	if(a[p]+delta>maxn) pos=p;
	else{
		int now=p;
		for(int i=19;i>=0;--i)
			if(anc[i][now] && a[anc[i][now]]+delta<=maxn) now=anc[i][now];
		now=anc[0][now];
		if(now==0 || now>lmt) pos=-1;
		else pos=now;
	}
	if(pos==-1) return mk(maxn,maxn*(r-l+1));
	ll co=maxn*(pos-p)/m; int now=pos;
	//cerr << "co=" << co << ' ' << now << ' ' << lmt << endl;
	for(int i=19;i>=0;--i)
		if(anc[i][now] && anc[i][now]<=lmt) co+=sum[i][now]+delta*((anc[i][now]-now)/m), now=anc[i][now];
	co+=(a[now]+delta)*((lmt-now)/m+1);
	return mk(a[now]+delta,co);
}	

inline int lower_bound(int x, int v){
	int l=1, r=len[x], mid;
	while(l<=r){
		mid=(l+r)>>1;
		if(num[x][mid]>=v) r=mid-1;
		else l=mid+1;
	}
	return l;
}

inline int upper_bound(int x, int v){
	int l=1, r=len[x], mid;
	while(l<=r){
		mid=(l+r)>>1;
		if(num[x][mid]>v) r=mid-1;
		else l=mid+1;
	}
	return l;
}

inline void show(){
	for(int i=0;i<m;++i) cout << "group:" << i << ' ' << nowmaxn[i] << ' ' << maxr[i] << endl;
	cout << "ans=" << ans << endl;	
}

inline void solve(){
	x=read(), t=read(); ans=0;
	int newrk=upper_bound(b+1,b+1+n,t)-b;
	// oldrk : x
	// newrk : newrk
	//cerr << "oldrk:" << x << ' ' << "newrk:" << newrk << endl;
	for(int i=0;i<m;++i) nowmaxn[i]=-inf, maxr[i]=0;
	int lmt=min(x,newrk), lmt2=max(x,newrk); pair<ll,ll> tmp;
	for(int i=0;i<m;++i){
		int u=lower_bound(i,lmt)-1; maxr[i]=u;
		//cerr << "u=" << u << endl;
		tmp=add(nowmaxn[i],i,1,u,0); ans+=tmp.se; nowmaxn[i]=tmp.fi;
	}
	//show();
	int which=newrk%m, l, r, delta;
	if(newrk<=x){
		if(nowmaxn[which]<1ll*t-1ll*maxr[which]*T-T) ans+=1ll*t-1ll*maxr[which]*T-T, nowmaxn[which]=1ll*t-1ll*maxr[which]*T-T;
		else ans+=nowmaxn[which]; maxr[which]++;
		l=newrk, r=x-1, delta=-1;
		for(int i=0;i<m;++i){
			int u=(i+delta+m)%m;
			int L=lower_bound(u,l);
			int R=upper_bound(u,r)-1;
			tmp=add(nowmaxn[i],u,L,R,1ll*(L-maxr[i]-1)*T); ans+=tmp.se; nowmaxn[i]=tmp.fi; maxr[i]+=R-L+1;
		}
	}
	else{
		delta=1; 
		l=x+1, r=newrk, delta=1;
		for(int i=0;i<m;++i){
			int u=(i+delta+m)%m;
			int L=lower_bound(u,l);
			int R=upper_bound(u,r)-1;
			//cerr << "range:" << i << ' ' << u << ' ' << L << ' ' << R << ' ' << "l=" << l << endl;
			tmp=add(nowmaxn[i],u,L,R,1ll*(L-maxr[i]-1)*T); ans+=tmp.se; nowmaxn[i]=tmp.fi; maxr[i]+=R-L+1;
		}
		if(nowmaxn[which]<1ll*t-1ll*maxr[which]*T-T) ans+=1ll*t-1ll*maxr[which]*T-T, nowmaxn[which]=1ll*t-1ll*maxr[which]*T-T;
		else ans+=nowmaxn[which]; maxr[which]++;
	}
	//show();
	for(int i=0;i<m;++i){
		int u=upper_bound(i,lmt2);
		//cerr << "range:" << u << ' ' << len[i] << ' ' << which << endl;
		tmp=add(nowmaxn[i],i,u,len[i],0); ans+=tmp.se; nowmaxn[i]=tmp.fi; maxr[i]=len[i];	
	}
	//show();
	//cerr << "ans=" << ans << endl;
	//cerr << "S=" << S << endl;
	eprint(ans-(S-b[x]+t));
}

signed main(){
	n=read(), m=read(), q=read(), T=read();
	for(int i=0;i<m;++i) num[i].pb(0);
	for(int i=1;i<=n;++i) a[i]=read(), num[i%m].pb(i), S+=a[i], b[i]=a[i];
	for(int i=0;i<m;++i) len[i]=signed(num[i].size())-1;
	for(int i=0;i<m;++i)
		for(int j=1;j<=len[i];++j) a[num[i][j]]-=1ll*j*T, S-=1ll*j*T;
	prework(); while(q--) solve();
	return 0;
}




















































Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 0ms
memory: 93844kb

input:

1000 5 1000 1969617
59993 133807 154199 240894 438118 483699 540258 892751 922552 1049554 1092961 1153394 1287745 1315664 1372758 1550447 1634967 1817853 1825455 2023239 2064188 2117896 2250036 2453036 2492474 2794776 2917935 3047993 3153958 3163156 3237767 3443614 3664074 3716235 3801008 3822067 40...

output:

145473107761
145400375427
145403718605
145444938654
145438908460
145436948885
145405212826
145454120934
145460664260
145458475414
145433391640
145459823384
145401672860
145361079139
145486629489
145451768180
145426177956
145368877047
145384484360
145392373415
145514759762
145437334277
145471143810
1...

result:

ok 1000 lines

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 93840kb

input:

1000 5 1000 36167
8215 12748 13176 18886 28740 44382 48915 49343 55053 64907 80549 85082 85510 91220 101074 116716 121249 121677 127387 137241 152883 157416 157844 163554 173408 189050 193583 194011 199721 209575 225217 229750 230178 235888 245742 261384 265917 266345 272055 281909 297551 302084 302...

output:

5383542
4273384
5583092
4487507
4540778
5719020
4991040
4831250
8044764
4747488
4297386
7059595
4985536
7791557
4450596
5708031
4408748
5511682
3977461
5126955
4570217
3960587
6060994
4619639
6617992
5523490
4048923
4200581
5648172
4915001
6247217
3840511
5690071
5159446
3355278
5730086
4592285
4686...

result:

wrong answer 6th lines differ - expected: '5739420', found: '5719020'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 20
Accepted
time: 228ms
memory: 350212kb

input:

1000000 1 100000 1165
83 197 266 277 299 529 538 601 629 760 792 1081 1208 1211 1387 1726 1873 1932 2198 2437 2448 2584 2715 2813 3113 3169 3207 3386 3934 4013 4032 4057 4137 4213 4396 4666 4754 4786 4856 4917 4966 5054 5124 5151 5196 5505 5548 5583 5730 5763 6031 6161 6169 6372 6446 6517 6712 6744 ...

output:

532526465394304
532526382684731
532526432382169
532526335149396
532526336776485
532526441654485
532526419072018
532526448365904
532526461590885
532526446716107
532526451559614
532526448428416
532526467783803
532526436578785
532526455446447
532526418608776
532526437618228
532526421765463
532526361938...

result:

ok 100000 lines

Test #7:

score: 20
Accepted
time: 255ms
memory: 350312kb

input:

1000000 1 100000 320
81 176 196 266 277 418 437 447 561 667 671 686 708 916 945 987 1077 1147 1343 1447 1459 1622 1739 1821 1907 2052 2211 2334 2483 2502 2553 2681 2879 2899 2996 3003 3075 3089 3141 3197 3312 3411 3450 3488 3525 3711 3870 4033 4066 4103 4216 4290 4341 4406 4500 4578 4600 4655 4697 4...

output:

110078125101649
110078095701794
110078065549730
110078084700891
110078055599406
110078147872941
110078125921229
110078050034681
110078131570282
110078020684010
110078081392840
110078123741061
110078124999461
110078092777746
110078093138994
110078104230505
110078088736720
110078130160314
110078088020...

result:

ok 100000 lines

Test #8:

score: 20
Accepted
time: 364ms
memory: 352296kb

input:

1000000 1 100000 6
1 7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97 103 109 115 121 127 133 139 145 151 157 163 169 175 181 187 193 199 205 211 217 223 229 235 241 247 253 259 265 271 277 283 289 295 301 307 313 319 325 331 337 343 349 355 361 367 373 379 385 391 397 403 409 415 421 427 433 439 445 ...

output:

5553833
8401453
8535183
8590839
6718701
6182541
5451207
4876437
6914671
6145580
8711335
8930675
5425001
5823370
6065908
7711946
7515358
5634147
4547534
5257419
6534174
5697110
6912866
4423285
8364102
6852541
6022633
6206653
5816343
6654555
6229974
8683850
5257837
5409556
4751045
5008105
6904326
4916...

result:

ok 100000 lines

Test #9:

score: 0
Wrong Answer
time: 353ms
memory: 354616kb

input:

1000000 1 100000 16
16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 256 272 288 304 320 336 352 368 384 400 416 432 448 464 480 496 512 528 544 560 576 592 608 624 640 656 672 688 704 720 736 752 768 784 800 816 832 848 864 880 896 912 928 944 960 976 992 1008 1024 1040 1056 1072 1088 1104 112...

output:

22046919
14316263
14215908
12574050
16811434
13552137
12066124
20830193
13340915
17693977
14052719
24225895
16627442
13796572
20050839
23326520
17991222
12248487
20532603
23738604
21615231
20091979
17370185
12410457
17205185
19921674
18529918
11452550
17698666
15112642
12609850
9807652
14635569
1680...

result:

wrong answer 1st lines differ - expected: '22191202', found: '22046919'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 20
Accepted

Test #36:

score: 20
Accepted
time: 414ms
memory: 352364kb

input:

1000000 5 100000 1887
112 168 223 393 535 558 577 631 631 678 682 1043 1099 1268 1337 1396 1437 1472 1510 1587 1804 1984 2013 2290 2294 2392 2474 2547 2694 2717 2742 2841 2880 2906 2985 3030 3047 3064 3108 3275 3375 3440 3451 3488 3950 3957 3963 4047 4086 4335 4378 4448 4490 4544 4622 4864 4875 4897...

output:

138785143191754
138785158412509
138785225283652
138785104800924
138785118976960
138785112934741
138785059838322
138785084952748
138785129256978
138785072292366
138785090484906
138785174307446
138785204546881
138785189045551
138785131284055
138785130779155
138785104455009
138785163776264
138785127154...

result:

ok 100000 lines

Test #37:

score: 20
Accepted
time: 424ms
memory: 350340kb

input:

1000000 5 100000 1360
2 310 440 496 564 709 768 791 1013 1258 1401 1456 1793 1942 2004 2015 2248 2605 2731 2819 2887 2989 3082 3114 3182 3272 3473 3613 3629 3675 3710 3828 3889 3917 4046 4275 4295 4345 4381 4458 4475 4490 4537 4622 4630 4830 4971 5220 5340 5519 5535 5543 5551 5656 5813 5831 5992 599...

output:

86025085231915
86025033609884
86025032828746
86025084541224
86025092955724
86025048967786
86024962725044
86025042711478
86024945097968
86025034268426
86025063418806
86024964850623
86025040240190
86025018749987
86024965894645
86024989632159
86025034950005
86024966000623
86024944469476
86024947144447
...

result:

ok 100000 lines

Test #38:

score: 20
Accepted
time: 404ms
memory: 352396kb

input:

1000000 5 100000 1981
61 141 241 251 283 337 477 522 786 850 855 939 1037 1071 1223 1394 1560 1653 1807 1989 2118 2154 2397 2564 2786 2923 2957 2990 3029 3170 3229 3322 3432 3434 3473 3608 3703 3802 3896 3903 3932 3978 4107 4165 4229 4282 4346 4368 4380 4432 4553 4720 5482 5599 5641 5707 5727 5915 5...

output:

148126562715560
148126450284403
148126535856592
148126454999936
148126438027968
148126444188257
148126429009715
148126495799938
148126448656482
148126479317803
148126491583599
148126550596862
148126463496330
148126547985374
148126538529415
148126537793200
148126517972390
148126520140968
148126548816...

result:

ok 100000 lines

Test #39:

score: 20
Accepted
time: 415ms
memory: 352592kb

input:

1000000 5 100000 1434
34 185 481 631 667 683 709 869 1007 1095 1263 1283 1292 1546 1685 1803 1842 1884 1909 1965 2077 2203 2438 2474 2516 2744 2864 2993 3216 3224 3246 3301 3301 3311 3357 3367 3540 3593 3603 3615 3705 3833 3868 3879 3913 3979 4091 4156 4308 4460 4532 4601 4686 4867 4915 5057 5074 50...

output:

93474964897049
93474951196530
93474872493506
93474884173414
93474898306915
93474953505373
93474982428895
93474956302229
93474948675088
93474949769211
93474973453777
93474963941319
93474927557821
93474874803110
93474861494804
93474893221692
93475000934392
93474944214506
93474891490200
93474900163979
...

result:

ok 100000 lines

Test #40:

score: 20
Accepted
time: 419ms
memory: 350332kb

input:

1000000 5 100000 1871
377 446 596 666 716 857 931 932 1130 1132 1365 1442 1477 1524 1608 1619 1679 1795 1814 1904 2054 2137 2481 2490 2515 2584 2601 2843 2896 2910 3000 3126 3132 3156 3191 3212 3280 3287 3446 3450 3458 3510 3597 3679 3760 3807 3999 4139 4214 4431 4455 4496 4508 4516 4521 4554 4637 4...

output:

137120524285093
137120537416676
137120549259163
137120496973981
137120458025501
137120538226029
137120550231150
137120614453418
137120526712182
137120514246425
137120522483980
137120466515779
137120533333202
137120542210883
137120534265862
137120492554396
137120540002565
137120514969675
137120566996...

result:

ok 100000 lines

Subtask #6:

score: 0
Skipped

Dependency #3:

0%