QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#657505#2788. HorsesPioneer#34 742ms46688kbC++202.9kb2024-10-19 14:53:422024-10-19 14:53:44

Judging History

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

  • [2024-10-19 14:53:44]
  • 评测
  • 测评结果:34
  • 用时:742ms
  • 内存:46688kb
  • [2024-10-19 14:53:42]
  • 提交

answer

#include "horses.h"
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const ll inf=1e9;
const int mod=1e9+7;
const int MAX=5e5+10;

struct segtree{
	int t[4*MAX];
	bool mark[4*MAX];

	segtree(){
		memset(mark,0,sizeof(mark));
	}

	void update(int v,int tl,int tr,int pos,int x){
		if(tl==tr){
			t[v]=x;
			return;
		}
		int tm=(tl+tr)/2;
		if(pos<=tm)update(2*v,tl,tm,pos,x);
		else update(2*v+1,tm+1,tr,pos,x);
		mark[v]=(mark[2*v]|mark[2*v+1]);
		if(t[2*v]*1ll*t[2*v+1]>=mod){
			mark[v]=1;
		}
		t[v]=(t[2*v]*1ll*t[2*v+1])%mod;
	}

	pair<int,bool> mrg(pair<int,bool> a,pair<int,bool> b){
		pair<int,bool> res={a.first*1ll*b.first%mod,(a.second|b.second)};
		if(a.first*1ll*b.first>=mod){
			res.second=1;
		}
		return res;
	}

	pair<int,bool> get(int v,int tl,int tr,int l,int r){
		if(l>r||tl>r||l>tr)return {1,0};
		if(l<=tl&&tr<=r)return {t[v],mark[v]};
		int tm=(tl+tr)/2;
		return mrg(get(2*v,tl,tm,l,r),get(2*v+1,tm+1,tr,l,r));
	}
}tx;

struct segtreeMx{
	pair<int,int> t[MAX];

	pair<int,int> mrg(pair<int,int> a,pair<int,int> b){
		if(a.first>=b.first)return a;
		else return b;
	}

	void update(int v,int tl,int tr,int pos,int x){
		if(tl==tr){
			t[v]={x,tl};
			return;
		}
		int tm=(tl+tr)/2;
		if(pos<=tm)update(2*v,tl,tm,pos,x);
		else update(2*v+1,tm+1,tr,pos,x);
		t[v]=mrg(t[2*v],t[2*v+1]);
	}

	pair<int,int> get(int v,int tl,int tr,int l,int r){
		if(l>r||tl>r||l>tr)return {0,0};
		if(l<=tl&&tr<=r)return t[v];
		int tm=(tl+tr)/2;
		return mrg(get(2*v,tl,tm,l,r),get(2*v+1,tm+1,tr,l,r));
	}
}ty;

int n;
set<int> st;
int x[MAX];
int y[MAX];

int get(int pos){
	return tx.get(1,1,n,1,pos).first*1ll*y[pos]%mod;
}

int get(){
	{
		int pos=n;
		int per=x[n]*1ll*y[n]%mod;
		bool bf=0;
		if(x[n]*1ll*y[n]>=mod)bf=1;
		for(int i=n-1;i>=max(1,n-1000);i--){
			if(!bf&&y[i]>=per){
				pos=i;
				per=y[i];
				bf=0;
			}
			if(per*1ll*x[i]>=mod){
				bf=1;
			}
			per=per*1ll*x[i]%mod;
		}
		return get(pos);
	}
	st.insert(1);
	vector<int> vec;
	int pos=ty.get(1,1,n,*st.rbegin(),n).second;
	vec.push_back(*st.rbegin());
	st.erase(--st.end());
	while(!st.empty()){
		int pos1=ty.get(1,1,n,*st.rbegin(),vec.back()-1).second;
		vec.push_back(*st.rbegin());
		st.erase(--st.end());
		pair<int,bool> bf=tx.get(1,1,n,pos1+1,pos);
		if(bf.second||bf.first*1ll*y[pos]>=mod)break;
		if(bf.first*y[pos]<=y[pos1])pos=pos1;
	}
	for(int x:vec)st.insert(x);
	return get(pos);
}

int init(int N, int X[], int Y[]) {
	n=N;
	for(int i=0;i<N;i++){
		y[i+1]=Y[i];
		x[i+1]=X[i];
		tx.update(1,1,N,i+1,X[i]);
		ty.update(1,1,N,i+1,Y[i]);
		if(X[i]!=1){
			st.insert(i+1);
		}
	}
	return get();
}

int updateX(int pos, int val) {	
	pos++;
	if(x[pos]!=1)st.erase(pos);
	x[pos]=val;
	tx.update(1,1,n,pos,val);
	if(x[pos]!=1)st.insert(pos);
	return get();
}

int updateY(int pos, int val) {
	pos++;
	y[pos]=val;
	ty.update(1,1,n,pos,val);
	return get();
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 17
Accepted

Test #1:

score: 17
Accepted
time: 2ms
memory: 13476kb

input:

1
2
3
0

output:

6

result:

ok single line: '6'

Test #2:

score: 17
Accepted
time: 3ms
memory: 13628kb

input:

10
2 1 1 5 2 1 1 10 5 1
3 5 7 9 4 1 4 10 10 9
0

output:

10000

result:

ok single line: '10000'

Test #3:

score: 17
Accepted
time: 0ms
memory: 12808kb

input:

10
10 10 10 1 1 1 1 1 1 1
2 3 4 2 7 6 5 4 3 2
0

output:

7000

result:

ok single line: '7000'

Test #4:

score: 17
Accepted
time: 2ms
memory: 13224kb

input:

10
9 1 1 1 1 1 1 1 1 2
4 1 1 1 1 1 1 1 1 2
0

output:

36

result:

ok single line: '36'

Test #5:

score: 17
Accepted
time: 1ms
memory: 12480kb

input:

10
1 1 1 1 1 1 1 1 1 1
1 2 3 4 5 6 7 8 9 10
0

output:

10

result:

ok single line: '10'

Test #6:

score: 17
Accepted
time: 1ms
memory: 12588kb

input:

10
1 1 1 1 1 1 1 1 1 1
10 9 8 7 6 5 4 3 2 1
0

output:

10

result:

ok single line: '10'

Test #7:

score: 17
Accepted
time: 0ms
memory: 12620kb

input:

10
10 10 10 1 1 1 1 1 1 1
10 10 2 3 4 5 6 7 8 9
0

output:

9000

result:

ok single line: '9000'

Test #8:

score: 17
Accepted
time: 0ms
memory: 12708kb

input:

10
10 10 10 1 1 1 1 1 1 1
10 10 9 8 7 6 5 4 3 2
0

output:

9000

result:

ok single line: '9000'

Test #9:

score: 17
Accepted
time: 2ms
memory: 13188kb

input:

10
1 1 1 1 2 2 1 1 1 1
8 8 8 8 1 1 2 2 2 2
0

output:

8

result:

ok single line: '8'

Test #10:

score: 17
Accepted
time: 0ms
memory: 12160kb

input:

10
1 1 1 1 1 1 1 1 1 1
1 2 3 4 5 9 8 7 6 1
0

output:

9

result:

ok single line: '9'

Test #11:

score: 17
Accepted
time: 2ms
memory: 12456kb

input:

2
2 5
9 7
0

output:

70

result:

ok single line: '70'

Test #12:

score: 17
Accepted
time: 0ms
memory: 12308kb

input:

1
1
1
0

output:

1

result:

ok single line: '1'

Test #13:

score: 17
Accepted
time: 1ms
memory: 12484kb

input:

7
7 1 1 6 2 3 2
7 6 5 4 3 7 1
0

output:

1764

result:

ok single line: '1764'

Test #14:

score: 17
Accepted
time: 0ms
memory: 13152kb

input:

1
10
10
0

output:

100

result:

ok single line: '100'

Test #15:

score: 17
Accepted
time: 2ms
memory: 12676kb

input:

2
1 4
7 2
0

output:

8

result:

ok single line: '8'

Test #16:

score: 17
Accepted
time: 0ms
memory: 13856kb

input:

10
1 10 1 10 1 1 10 1 1 1
7 3 10 10 4 10 1 4 5 10
0

output:

10000

result:

ok single line: '10000'

Test #17:

score: 17
Accepted
time: 2ms
memory: 13504kb

input:

6
1 1 1 1 1 1
1 1 1 1 1 1
0

output:

1

result:

ok single line: '1'

Test #18:

score: 17
Accepted
time: 0ms
memory: 13852kb

input:

4
1 2 4 8
8 4 2 1
0

output:

64

result:

ok single line: '64'

Test #19:

score: 17
Accepted
time: 0ms
memory: 13924kb

input:

6
1 2 2 3 1 1
7 1 1 2 1 1
0

output:

24

result:

ok single line: '24'

Test #20:

score: 17
Accepted
time: 2ms
memory: 12088kb

input:

10
2 1 1 5 2 1 1 10 5 1
3 5 7 9 4 1 4 10 7 9
0

output:

9000

result:

ok single line: '9000'

Subtask #2:

score: 17
Accepted

Dependency #1:

100%
Accepted

Test #21:

score: 17
Accepted
time: 0ms
memory: 13244kb

input:

10
10 10 10 10 10 10 1 1 1 1
1 1 1 1 9 5 4 7 3 2
5
1 5 1
2 5 123456789
1 5 1
1 8 987654321
1 9 777777777

output:

7000000
900000
678813585
678813585
294225928
75803567

result:

ok 6 lines

Test #22:

score: 17
Accepted
time: 1ms
memory: 12016kb

input:

10
3 2 7 5 11 13 107 23 51 3
1 1 1 1 1000000000 1 1 1 1 1
16
1 1 1
1 2 1
1 0 1
1 8 1
1 7 1
1 9 1
1 1 25
1 8 123456789
1 4 1
1 6 1
1 3 1
1 5 1
1 5 12345
1 6 123456
1 7 1234567
2 4 3

output:

999983837
999991922
999998852
999999622
999999622
999999622
999999622
999990382
539408243
49037113
617280725
123456145
999999832
851238418
489396978
354709175
354709175

result:

ok 17 lines

Test #23:

score: 17
Accepted
time: 3ms
memory: 12884kb

input:

1000
179278145 423054674 671968267 409599985 828900464 393298292 569389961 360810107 205374067 618910650 76768983 62623743 225944805 498579132 917750714 600860488 642568763 21949846 852642376 283772010 299085842 669257630 544180666 249770466 320727298 612199337 15873453 726595389 219129403 876893450...

output:

394559852
394559852
394559852
394559852
868802752
868802752
868802752
868802752
165967503
244287754
244287754
270995710
270995710
270995710
247981131
247981131
237849527
24662481
24662481
451435926
989677577
989677577
704081481
704081481
704081481
704081481
704081481
631761803
631761803
631761803
80...

result:

ok 1001 lines

Test #24:

score: 17
Accepted
time: 3ms
memory: 12296kb

input:

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

858314903
362189740
362189740
362189740
362189740
362189740
347762296
347762296
347762296
347762296
347762296
347762296
297139175
297139175
56337247
56337247
56337247
919555391
919555391
223551221
223551221
223551221
674943421
674943421
674943421
674943421
674943421
160231649
160231649
242692758
242...

result:

ok 1001 lines

Test #25:

score: 17
Accepted
time: 3ms
memory: 13744kb

input:

1000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000000...

output:

426490853
426490853
426490853
426490853
224787023
224787023
110744712
110744712
110744712
682644373
841322190
841322190
594096835
973115198
7681374
712091041
712091041
712091041
712091041
712091041
712091041
712091041
326844140
326844140
163422070
326844140
326844140
326844140
163422070
163422070
16...

result:

ok 1001 lines

Test #26:

score: 17
Accepted
time: 3ms
memory: 13288kb

input:

1000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000000...

output:

426490853
224787023
110744712
110744712
110744712
110744712
110744712
110744712
110744712
110744712
841322190
188193663
188193663
973115198
973115198
486557599
486557599
486557599
501920347
501920347
214011381
214011381
214011381
214011381
214011381
214011381
214011381
214011381
540855521
81711035
8...

result:

ok 1001 lines

Test #27:

score: 17
Accepted
time: 3ms
memory: 13172kb

input:

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1
111838200
111838200
141345155
141345155
141345155
347215940
347215940
462493672
462493672
462493672
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
475246965
47524696...

result:

ok 1001 lines

Test #28:

score: 17
Accepted
time: 6ms
memory: 12328kb

input:

999
1 2 1 6 1 7 1 8 1 2 1 9 1 4 1 2 1 6 1 6 1 10 1 3 1 7 1 2 1 8 1 5 1 5 1 2 1 9 1 6 1 9 1 9 1 4 1 8 1 10 1 4 1 2 1 7 1 4 1 9 1 3 1 10 1 6 1 3 1 10 1 9 1 4 1 2 1 10 1 2 1 4 1 10 1 3 1 7 1 9 1 2 1 4 1 5 1 6 1 2 1 10 1 8 1 2 1 5 1 6 1 6 1 8 1 3 1 10 1 9 1 3 1 3 1 4 1 6 1 5 1 6 1 5 1 6 1 4 1 2 1 8 1 2 ...

output:

894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
894825221
...

result:

ok 1001 lines

Test #29:

score: 17
Accepted
time: 7ms
memory: 12128kb

input:

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1
2
2
4
8
16
16
32
32
16
8
4
2
2
2
2
4
4
4
8
8
8
8
4
2
4
4
8
16
32
32
16
16
8
4
2
2
2
2
2
2
4
2
2
2
2
2
2
4
4
4
2
4
4
8
16
32
32
16
8
4
4
2
2
4
4
2
2
4
4
4
8
16
16
8
16
16
16
8
16
8
4
2
2
2
4
8
16
32
32
16
16
16
8
4
8
8
4
4
4
2
1
1
1
1
1
2
2
4
4
8
8
8
8
16
16
16
32
16
8
8
4
2
4
4
2
2
4
2
4
4
8
8
8
4...

result:

ok 1001 lines

Test #30:

score: 17
Accepted
time: 7ms
memory: 12136kb

input:

1000
449878747 910674510 165143519 796141357 640922692 573949623 473255861 694971928 923936963 520980628 407779878 356558322 959023188 533793940 402247935 460440718 261337138 763084309 477743089 457285505 21664165 849032387 495576190 421984304 467773902 838138184 169975811 805107419 502174869 375370...

output:

392927667
3019699
252703129
967234835
690465334
745063314
648310471
594657147
797483498
960494972
217493779
741093774
398194406
336083786
400370081
595436661
30471347
875039519
60963593
516858978
480652068
726643394
673856666
237413719
45909014
783589282
600072636
214213285
409343465
506112870
19369...

result:

ok 1001 lines

Test #31:

score: 17
Accepted
time: 8ms
memory: 13384kb

input:

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
2097152
4194304
8388608
16777216
33554432
67108864
134217728
268435456
536870912
536870912
536870912
536870912
536870912
536...

result:

ok 1001 lines

Test #32:

score: 17
Accepted
time: 3ms
memory: 12084kb

input:

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

73741817
999999993
1000000000
1000000000
73741817
999999993
1000000000
1000000000
73741817
999999993
1000000000
1000000000
73741817
999999993
1000000000
1000000000
73741817
999999993
1000000000
1000000000
73741817
999999993
1000000000
1000000000
73741817
999999993
1000000000
1000000000
73741817
9999...

result:

ok 1001 lines

Subtask #3:

score: 0
Wrong Answer

Test #33:

score: 0
Wrong Answer
time: 742ms
memory: 46688kb

input:

500000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...

output:

942713367
942713367
590416038
946135722
170737482
170737482
170737482
170737482
170737482
877695782
107743536
107743536
107743536
107743536
107743536
842685874
842685874
842685874
842685874
842685874
214274943
214274943
214274943
214274943
214274943
10116410
10116410
10116410
10116410
10116410
50714...

result:

wrong answer 1st lines differ - expected: '967631222', found: '942713367'

Subtask #4:

score: 0
Wrong Answer

Dependency #2:

100%
Accepted

Test #37:

score: 0
Wrong Answer
time: 164ms
memory: 23444kb

input:

500000
179278145 423054674 671968267 409599985 828900464 393298292 569389961 360810107 205374067 618910650 76768983 62623743 225944805 498579132 917750714 600860488 642568763 21949846 852642376 283772010 299085842 669257630 544180666 249770466 320727298 612199337 15873453 726595389 219129403 8768934...

output:

191402115
455205619
548467500
548467500
548467500
548467500
548467500
647326229
647326229
250954039
527161755
80618055
774283322
567894903
482995062
327190006
892864573
118404252
307554713
95725814
316790058
729373549
396369369
396369369
396369369
396369369
327813023
230795095
421236044
640703387
64...

result:

wrong answer 1st lines differ - expected: '394559852', found: '191402115'

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%