QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#831294#8951. 澡堂275307894a#10 10ms6116kbC++142.2kb2024-12-25 12:59:372024-12-25 12:59:37

Judging History

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

  • [2024-12-25 12:59:37]
  • 评测
  • 测评结果:10
  • 用时:10ms
  • 内存:6116kb
  • [2024-12-25 12:59:37]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=2e5+5,M=(1<<28)+5,K=1000+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,m,q,T,X[N],Y[N];
int A[N];
ll ans[N];
void work(){
	
}
void Solve(){
	scanf("%d%d%d%d",&n,&m,&q,&T);
	for(int i=1;i<=n;i++) scanf("%d",&A[i]);
	for(int i=1;i<=q;i++) scanf("%d%d",&X[i],&Y[i]);
	for(int i=1;i<=q;i++){
		if(Y[i]>=A[X[i]]){
			int p=UB(A+1,A+n+1,Y[i])-A-1;
			for(int k=0;k<m;k++){
				ll mx=-1e18;
				auto merge=[&](int x){
					if(mx<x) mx=x+T;
					else ans[i]+=mx-x,mx+=T;
				};
				gdb(p);
				for(int j=1;j<X[i];j++) if(j%m==k) merge(A[j]);
				for(int j=X[i]+1;j<=p;j++) if((j-1)%m==k) merge(A[j]);
				if(p%m==k) merge(Y[i]);
				for(int j=p+1;j<=n;j++) if(j%m==k) merge(A[j]);
			}
		}else{
			int p=LB(A+1,A+n+1,Y[i])-A;
			for(int k=0;k<m;k++){
				ll mx=-1e18;
				auto merge=[&](int x){
					if(mx<x) mx=x+T;
					else ans[i]+=mx-x,mx+=T;
				};
				gdb(p);
				for(int j=1;j<p;j++) if(j%m==k) merge(A[j]);
				if(p%m==k) merge(Y[i]);
				for(int j=p;j<X[i];j++) if((j+1)%m==k) merge(A[j]);
				for(int j=X[i]+1;j<=n;j++) if(j%m==k) merge(A[j]);
			}
		}
	}
	for(int i=1;i<=q;i++) printf("%lld\n",ans[i]);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 10ms
memory: 6104kb

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: 10
Accepted
time: 6ms
memory: 6104kb

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
5739420
4991040
4831250
8044764
4747488
4297386
7059595
4985536
7791557
4450596
5708031
4408748
5511682
3977461
5126955
4570217
3960587
6060994
4619639
6617992
5548191
4048923
4200581
5648172
4915001
6247217
3840511
5690071
5159446
3355278
5730086
4592285
4686...

result:

ok 1000 lines

Test #3:

score: 10
Accepted
time: 6ms
memory: 6080kb

input:

1000 5 1000 26455
5755 9335 12488 13480 16017 32210 35790 38943 39935 42472 58665 62245 65398 66390 68927 85120 88700 91853 92845 95382 111575 115155 118308 119300 121837 138030 141610 144763 145755 148292 164485 168065 171218 172210 174747 190940 194520 197673 198665 201202 217395 220975 224128 225...

output:

3759363
2722461
1547992
1048857
2015166
2141100
1365260
3621432
2012670
2816278
953073
910376
959437
3872474
2174732
3202845
2220674
3598113
1366417
1009053
896353
856859
1073992
4270759
2501724
1112987
1322084
1846494
2453774
3339534
1661853
1633223
3031189
4018416
1709729
4499620
1118329
3768062
3...

result:

ok 1000 lines

Test #4:

score: 10
Accepted
time: 10ms
memory: 6116kb

input:

1000 5 1000 16722
3139 3641 7653 10814 14321 19860 20362 24374 27535 31042 36581 37083 41095 44256 47763 53302 53804 57816 60977 64484 70023 70525 74537 77698 81205 86744 87246 91258 94419 97926 103465 103967 107979 111140 114647 120186 120688 124700 127861 131368 136907 137409 141421 144582 148089 ...

output:

3512079
3034475
2734835
1941064
2519290
2440084
3414880
4562356
3334182
4126409
4618632
2050759
3791748
2933951
2726789
4788327
4132574
2963481
3636642
3025088
2699802
2034322
3616015
3451068
3111762
2892910
2940932
3444821
3086673
2603997
2440367
2753422
3618666
2391844
3572522
2602010
3080548
3836...

result:

ok 1000 lines

Test #5:

score: 10
Accepted
time: 10ms
memory: 6096kb

input:

1000 5 1000 60555
14667 19173 23801 42385 55686 75221 79727 84355 102939 116240 135775 140281 144909 163493 176794 196329 200835 205463 224047 237348 256883 261389 266017 284601 297902 317437 321943 326571 345155 358456 377991 382497 387125 405709 419010 438545 443051 447679 466263 479564 499099 503...

output:

10089512
17345531
7817544
13187454
10823659
10325209
13800175
11316499
12145244
12378466
11235075
13238408
18390405
9571104
15996985
7081670
14198216
16953216
10752423
8494916
17169941
7074729
9619075
16441956
14197611
15099449
9910334
12491708
13648701
9675595
10825715
9884233
13371337
15375812
824...

result:

ok 1000 lines

Subtask #2:

score: 0
Runtime Error

Test #6:

score: 0
Runtime Error

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:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Test #26:

score: 0
Time Limit Exceeded

input:

200000 5 50000 8448
68 1932 1956 2079 2363 3189 3837 3927 4312 4516 4526 4753 6972 7443 8556 9446 10246 11909 12189 12533 12576 12675 12739 13333 14022 14534 14827 15649 15946 16794 17011 17202 18405 18566 18855 19263 19294 19432 19934 19935 20100 20117 21221 21435 21437 21790 21956 21978 23322 2500...

output:


result:


Subtask #5:

score: 0
Runtime Error

Test #36:

score: 0
Runtime Error

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:


result:


Subtask #6:

score: 0
Skipped

Dependency #3:

0%