QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#151565#2788. HorsesAbdelmagedNour#17 494ms51076kbC++202.3kb2023-08-27 00:35:192024-07-04 01:51:50

Judging History

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

  • [2024-07-04 01:51:50]
  • 评测
  • 测评结果:17
  • 用时:494ms
  • 内存:51076kb
  • [2023-08-27 00:35:19]
  • 提交

answer

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

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 17
Accepted

Test #1:

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

input:

1
2
3
0

output:

6

result:

ok single line: '6'

Test #2:

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

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: 1ms
memory: 9904kb

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: 9892kb

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: 1ms
memory: 9960kb

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

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: 9908kb

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: 2ms
memory: 9948kb

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: 1ms
memory: 10032kb

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: 10036kb

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: 1ms
memory: 9904kb

input:

2
2 5
9 7
0

output:

70

result:

ok single line: '70'

Test #12:

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

input:

1
1
1
0

output:

1

result:

ok single line: '1'

Test #13:

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

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: 0ms
memory: 10092kb

input:

1
10
10
0

output:

100

result:

ok single line: '100'

Test #15:

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

input:

2
1 4
7 2
0

output:

8

result:

ok single line: '8'

Test #16:

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

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: 0ms
memory: 9884kb

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: 2ms
memory: 10028kb

input:

4
1 2 4 8
8 4 2 1
0

output:

64

result:

ok single line: '64'

Test #19:

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

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: 1ms
memory: 9904kb

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: 9964kb

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: 494ms
memory: 51076kb

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%