QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#151563#2788. HorsesAbdelmagedNour#17 505ms41132kbC++202.3kb2023-08-27 00:31:102024-07-04 01:51:50

Judging History

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

  • [2024-07-04 01:51:50]
  • 评测
  • 测评结果:17
  • 用时:505ms
  • 内存:41132kb
  • [2023-08-27 00:31:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
//#include "grader.cpp"
#include "horses.h"
const int mod=(1e9)+7,MAXN=500005;
int add(int a,int b){
	a+=b;
    if(a>=mod)a-=mod;
    return a;
}
int sub(int a,int b){
    a-=b;
    if(a<0)a+=mod;
    return a;
}
int mul(int a,int b){
	return(a*1LL*b)%mod;
}
int power(int x,int n){
    int res=1;
    while(n){
        if(n&1)res=mul(res,x);
        x=mul(x,x);
        n>>=1;
    }
    return res;
}
int inv(int a){
	return power(a,mod-2);
}
int divide(int a,int b){
	return mul(a,inv(b));
}
int x[MAXN],y[MAXN],n;
set<int>not_one;
int bit[MAXN],tree[1<<20];
void upd(int i,int val){
    for(;i<=n;i+=i&-i)bit[i]=mul(bit[i],val);
}
int qry(int i){
	int res=1;
    for(;i>=1;i-=i&-i)res=mul(res,bit[i]);
	return res;
}
void update(int l,int r,int p,int idx,int val){
    if(l==r){
        tree[p]=val;
        return;
    }
    int md=(l+r)>>1;
    if(md>=idx)update(l,md,p*2+1,idx,val);
    else update(md+1,r,p*2+2,idx,val);
    tree[p]=max(tree[p*2+1],tree[p*2+2]);
}
int query(int l,int r,int p,int l_q,int r_q){
    if(l>r_q||r<l_q)return 0;
    if(l>=l_q&&r<=r_q)return tree[p];
    int md=(l+r)>>1;
    return max(query(l,md,p*2+1,l_q,r_q),query(md+1,r,p*2+2,l_q,r_q));
}
int solve(){
	long long cur_factor=1,all_factor=1;
	int last=n+1;
	long long ans=0,best=0;
	for(auto it=not_one.rbegin();it!=not_one.rend();it++){
		int cur_pos=*it;
	    int cur_y=query(1,n,0,cur_pos,last-1);
		if(cur_y>best*cur_factor) {
			best=cur_y;
			ans=mul(qry(cur_pos),cur_y);
			cur_factor=1;
		}
		cur_factor*=x[cur_pos];
		all_factor*=x[cur_pos];
		if(all_factor>mod)break;
		last=cur_pos;
	}
	return ans;
}
int init(int N, int X[], int Y[]) {
	n=N;
	x[0]=y[0]=1;
	for(int i=1;i<=n;i++)x[i]=X[i-1],y[i]=Y[i-1];
	for(int i=0;i<=n;i++)bit[i]=1;
	for(int i=1;i<=n;i++){
		upd(i,x[i]);
		update(1,n,0,i,y[i]);
	}
	for(int i=1;i<=n;i++){
		if(x[i]>1)not_one.insert(i);
	}
	not_one.insert(1);
	return solve();
}
int updateX(int pos,int val){	
    pos++;
    upd(pos,divide(val,x[pos]));
	if(x[pos]>1&&pos>1)not_one.erase(pos);
    x[pos]=val;
    if(x[pos]>1)not_one.insert(pos);
    return solve();
}

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

詳細信息

Subtask #1:

score: 17
Accepted

Test #1:

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

input:

1
2
3
0

output:

6

result:

ok single line: '6'

Test #2:

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

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: 0
Accepted
time: 0ms
memory: 9900kb

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: 0
Accepted
time: 1ms
memory: 9924kb

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: 0
Accepted
time: 0ms
memory: 9920kb

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: 0
Accepted
time: 1ms
memory: 7916kb

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: 0
Accepted
time: 0ms
memory: 9924kb

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: 0
Accepted
time: 1ms
memory: 7928kb

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: 0
Accepted
time: 0ms
memory: 9972kb

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: 0
Accepted
time: 1ms
memory: 9976kb

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: 0
Accepted
time: 2ms
memory: 9976kb

input:

2
2 5
9 7
0

output:

70

result:

ok single line: '70'

Test #12:

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

input:

1
1
1
0

output:

1

result:

ok single line: '1'

Test #13:

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

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: 0
Accepted
time: 1ms
memory: 7864kb

input:

1
10
10
0

output:

100

result:

ok single line: '100'

Test #15:

score: 0
Accepted
time: 1ms
memory: 10088kb

input:

2
1 4
7 2
0

output:

8

result:

ok single line: '8'

Test #16:

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

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: 0
Accepted
time: 1ms
memory: 9964kb

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: 0
Accepted
time: 0ms
memory: 10088kb

input:

4
1 2 4 8
8 4 2 1
0

output:

64

result:

ok single line: '64'

Test #19:

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

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: 0
Accepted
time: 2ms
memory: 9964kb

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: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #21:

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

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
567881362
567881362
294225928
75803567

result:

wrong answer 3rd lines differ - expected: '678813585', found: '567881362'

Subtask #3:

score: 0
Wrong Answer

Test #33:

score: 0
Wrong Answer
time: 505ms
memory: 41132kb

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:

967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
967631222
...

result:

wrong answer 3rd lines differ - expected: '795463654', found: '967631222'

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%