QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533193#391. Commandozhicheng0 121ms3960kbC++141.0kb2024-08-25 18:19:492024-08-25 18:19:49

Judging History

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

  • [2024-08-25 18:19:49]
  • 评测
  • 测评结果:0
  • 用时:121ms
  • 内存:3960kb
  • [2024-08-25 18:19:49]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int now,las;
ll s[1000010];
vector<pair<ll,ll> >p;
vector<long double>v;
ll calc(int x,ll y){
	return p[x].first*y+p[x].second;
}
ll query(ll x){
	while(las+1<v.size()&&v[las+1]<=x){
		las++;
	}
	return las<v.size()?calc(las,x):0;
}
long double intersect(ll a,ll b,ll c,ll d){
	return 1.0*(b-d)/(c-a);
}
void update(ll x,ll y){
	while(now>=2&&intersect(x,y,p[now-1].first,p[now-1].second)<=intersect(p[now-1].first,p[now-1].second,p[now-2].first,p[now-2].second)){
		now--;
		p.pop_back();
		v.pop_back();
	}
	v.push_back(now>=1?intersect(x,y,p[now-1].first,p[now-1].second):-1e18);
	p.push_back({x,y});
	now++;
}
int main(){
	int t,n;
	ll ans,a,b,c,x;
	scanf("%d",&t);
	while(t--){
		p.clear();
		v.clear();
		now=las=0;
		scanf("%d%lld%lld%lld",&n,&a,&b,&c);
		update(0,0);
		for(int i=1;i<=n;i++){
			scanf("%lld",&x);
			s[i]=s[i-1]+x;
			ans=query(s[i])+a*s[i]*s[i]+b*s[i]+c;
			update(-2*a*s[i],a*s[i]*s[i]-b*s[i]+ans);
		}
		printf("%lld\n",ans);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3820kb

input:

500
-1 100 -1000
12 58 12 11 22 59 41 54 5 16 87 74 88 55 21 50 16 79 94 10 96 90 22 12 60 6 78 96 59 8 52 3 51 63 59 96 90 56 57 25 38 62 89 47 12 77 3 14 62 75 65 76 66 18 29 4 54 62 41 47 22 50 73 30 43 58 91 69 33 68 59 23 82 79 94 34 12 63 17 81 49 7 10 13 51 91 86 44 31 82 59 92 73 30 31 23 48...

output:

94701610191616
2358066
4434272
18658178
3862416
381426
10028156
15270970
18437400
4492348
7872913
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772
141772...

result:

wrong answer 1st lines differ - expected: '362631', found: '94701610191616'

Test #2:

score: 0
Wrong Answer
time: 1ms
memory: 3764kb

input:

1000
-1 120 -1200
59 29 3 17 27 65 62 34 100 99 92 8 90 10 23 72 65 99 59 25 56 59 70 40 20 63 97 41 39 82 97 85 58 5 48 60 16 6 22 44 24 13 47 34 18 75 34 73 37 79 66 41 99 39 68 38 45 10 12 53 57 72 20 70 34 19 87 39 22 15 41 79 46 56 88 62 41 58 46 100 9 30 84 45 55 67 30 4 17 67 16 47 7 63 36 93...

output:

94242627812096
409267
8414916
398605
2713670
5095308
3465988
1879347
985249
9330128
13825794
2114282
1053880
24102925
1635062
412848
14479835
125515
5609540
22015913
10716858
3202500
14000523
7117339
8934015
8934015
8934015
8934015
8934015
8934015
8934015
8934015
8934015
8934015
8934015
8934015
8934...

result:

wrong answer 1st lines differ - expected: '1588599', found: '94242627812096'

Test #3:

score: 0
Wrong Answer
time: 10ms
memory: 3960kb

input:

5000
-1 130 -2000
4 89 66 15 64 66 19 17 43 88 21 7 73 99 97 33 57 11 4 50 86 29 68 34 45 53 82 16 54 90 65 26 30 97 57 84 61 74 84 78 73 83 13 48 95 41 6 9 48 52 100 67 30 67 76 4 96 42 76 26 64 39 47 27 48 13 93 52 27 2 14 62 72 75 12 98 99 11 23 85 59 38 97 87 56 29 66 93 89 92 50 80 9 14 36 73 8...

output:

94078466657024
22171436
9712734
1710851
856698
490679
1002360
22181504
8240014
24982467
2984093
4287452
19894100
202631
4790053
13303804
3621936
20816262
11527658
6981919
9449925
11268877
19606647
10072728
18541360
19272583
5441992
10321970
21528156
18207610
1667516
7651984
32196872
12510871
1787961...

result:

wrong answer 1st lines differ - expected: '7042743', found: '94078466657024'

Test #4:

score: 0
Wrong Answer
time: 23ms
memory: 3892kb

input:

8000
-1 160 -2000
14 82 61 85 41 10 34 17 47 91 87 79 28 1 3 17 96 24 34 58 85 72 95 56 57 6 64 2 2 33 36 90 13 79 5 83 16 23 63 69 36 63 91 65 66 33 99 67 5 68 12 85 84 40 9 50 40 33 20 78 50 40 58 95 2 83 36 89 70 11 23 18 88 43 39 18 89 10 84 13 97 57 13 52 31 90 22 13 36 68 83 17 34 89 2 44 25 2...

output:

94012841544448
16606352
1022231
8033199
10962220
14672638
12365112
4671888
20367900
14379843
7369992
1801345
7404641
13771652
24145665
2047822
19568032
18744601
18216355
2581914
12292139
1013744
7233712
16476542
16112079
5575126
7632034
5019273
5783024
17884580
3226616
846790
32216634
11394428
27672...

result:

wrong answer 1st lines differ - expected: '23226559', found: '94012841544448'

Test #5:

score: 0
Wrong Answer
time: 18ms
memory: 3888kb

input:

10000
-2 200 0
82 20 17 6 91 4 25 5 38 6 5 92 38 83 65 86 24 75 48 52 12 52 90 29 38 40 59 42 47 86 16 84 73 54 22 10 16 60 85 85 82 15 50 36 46 91 76 41 41 95 87 41 53 7 22 43 61 76 31 12 56 89 77 9 13 31 53 50 24 28 84 86 3 12 79 83 55 83 40 15 19 73 37 95 17 40 58 98 29 8 28 9 19 33 19 18 20 25 7...

output:

94242451073792
942549
7771945
6144878
2806034
6168304
3205697
20302253
2551542
5211508
2125893
9798918
11294109
10211182
3278213
1423463
4232617
24732503
15428365
4780554
545501
12342474
1299496
7244940
2194187
25033592
1367457
2380639
23799301
14521752
412988
1588992
83758
28740465
27027968
2536604...

result:

wrong answer 1st lines differ - expected: '33519580', found: '94242451073792'

Test #6:

score: 0
Wrong Answer
time: 121ms
memory: 3816kb

input:

100000
-1 2000 -500000
5 99 54 71 99 95 65 24 22 88 59 83 63 87 55 79 35 22 99 6 73 70 35 92 60 46 45 87 44 62 18 45 53 53 16 54 36 31 21 71 97 14 38 43 64 67 35 2 52 28 66 72 80 71 66 3 4 17 62 51 92 55 94 40 39 33 13 93 23 94 64 72 12 48 70 81 30 80 17 48 50 75 79 98 22 94 28 91 48 95 60 17 61 26 ...

output:

94229374327552
19190538
13891262
12114468
3796938
11882467
7865354
17478267
521873
3448216
373625
25774376
1478525
566683
990835
1535304
2845241
11672498
5682399
2854847
19641057
13949802
3209077
2600182
4607686
11295718
2967416
10516
15383587
657721
14480726
4009508
4338586
1986596
18494100
211644
...

result:

wrong answer 1st lines differ - expected: '2946453946', found: '94229374327552'

Test #7:

score: 0
Time Limit Exceeded

input:

500000
-3 6000 -500000
68 30 8 100 90 57 94 23 23 91 52 83 31 78 39 4 76 11 60 42 34 50 59 57 5 5 79 74 59 48 11 60 98 76 79 43 37 34 78 20 66 67 54 93 76 78 70 42 2 25 31 4 84 91 67 9 20 46 2 29 40 20 37 39 1 68 16 3 44 38 78 86 28 71 40 6 3 22 58 96 25 25 9 43 49 72 14 99 11 90 49 82 82 82 17 85 7...

output:

94914401815296
991620
4232618
1792862
21779203
2013780
12381684
8202839
22170818
6754726
4575643
2742239
8029812
7301289
2773170
9357499
2699184
28593040
11691317
1426567
13126681
23327741
17742624
9575310
25399666
4033538
21115384
503389
7420740
14647629
8552760
2820507
10314576
19908081
124748
166...

result:


Test #8:

score: 0
Time Limit Exceeded

input:

800000
-1 12000 -30000000
16 53 4 96 38 47 74 96 94 42 54 77 49 42 59 87 56 2 94 67 17 64 77 10 93 56 28 50 53 85 85 1 12 67 29 58 37 34 7 56 65 40 64 64 40 73 20 27 28 92 56 88 66 19 52 10 80 31 20 85 99 77 41 62 50 16 17 40 79 19 99 74 48 18 95 78 100 48 34 54 35 80 21 89 43 65 3 96 24 33 52 95 39...

output:

94335493315328
997926
6381048
7077943
12668418
31999467
7267583
4849423
14944032
8238283
10322158
3372952
29753656
996967
12277105
9578490
16974373
28300619
6733197
3515704
74838
10730252
19734318
4084529
17874879
11960094
8080215
12957771
7332666
11684917
2839588
12600532
17489434
4230318
1571538
2...

result:


Test #9:

score: 0
Time Limit Exceeded

input:

1000000
-1 9000 -16000000
25 30 52 90 93 83 35 52 100 5 84 6 99 66 4 81 71 79 34 43 37 12 77 1 19 63 10 5 60 5 41 5 44 21 84 88 50 94 22 30 81 99 57 14 12 81 59 9 53 46 39 88 77 27 99 6 18 67 36 73 88 65 68 82 72 42 59 99 38 40 61 88 30 2 35 88 38 41 96 65 86 66 74 70 80 98 69 84 8 54 3 19 34 6 64 7...

output:

94619861211904
4782266
15605028
8304656
13547120
566404
8945556
5763067
239424
5732913
13433934
18704341
6032007
26465764
4986266
2842780
7984618
6048261
20902516
3150559
8458522
10614058
6380937
18110009
467293
1251035
23107866
6209101
146128
3417169
8880157
2861099
4849682
18528788
3900580
1808982...

result:


Test #10:

score: 0
Time Limit Exceeded

input:

1000000
-2 10000 -6000000
35 74 95 59 82 69 27 94 29 57 73 89 86 61 20 20 93 21 82 93 16 25 71 20 20 72 9 11 11 73 33 56 35 37 5 67 74 10 18 42 72 24 20 66 87 31 36 64 37 40 48 60 19 47 57 41 43 20 54 72 15 52 56 69 92 98 74 28 98 71 57 4 78 31 27 26 68 85 29 100 55 93 57 4 73 4 3 18 27 28 26 96 95 ...

output:

94512234691328
22066028
17773142
12181648
26759183
23079350
15263336
30034273
259392
15726072
117307
2890255
2393506
5456508
7019354
5905494
27805601
6004573
8515772
2931717
13139569
4590322
6308049
14654432
5642718
1864149
6897792
13007284
1335123
16849693
1075152
3151038
6330285
122798
48019
78576...

result: