#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define M 1000000007LL
struct SEG1{
ll seg[1<<20];
SEG1(void){
for(int i=0;i<1<<20;i++)seg[i]=1;
}
void update(int a,ll x){
a+=(1<<19)-1;
seg[a]=x%M;
while(a>0){
a=(a-1)/2;
seg[a]=seg[a*2+1]*seg[a*2+2]%M;
}
}
ll query(int a,int b,int l=0,int r=(1<<19)-1,int k=0){
if(r<a||b<l)return 1;
if(a<=l&&r<=b)return seg[k];
return query(a,b,l,(l+r-1)/2,k*2+1)*query(a,b,(l+r+1)/2,r,k*2+2)%M;
}
}seg1;
struct SEG2{
ll seg[1<<20];
SEG2(void){
for(int i=0;i<1<<20;i++)seg[i]=0;
}
void update(int a,ll x){
a+=(1<<19)-1;
seg[a]=x;
while(a>0){
a=(a-1)/2;
seg[a]=max(seg[a*2+1],seg[a*2+2]);
}
}
ll query(int a,int b,int l=0,int r=(1<<19)-1,int k=0){
if(r<a||b<l)return 0;
if(a<=l&&r<=b)return seg[k];
return max(query(a,b,l,(l+r-1)/2,k*2+1),query(a,b,(l+r+1)/2,r,k*2+2));
}
}seg2;
ll n,x[500005],y[500005];
set<ll>p;
int solve(void){
auto it=p.find(n);
vector<ll>a,b,c;
int la=n;
ll s=1;
while(1){
it--;
int v=*it;
a.push_back(v);
b.push_back(s);
c.push_back(seg2.query(v,la-1));
if(it==p.begin()||s*x[v]>=1000000000)break;
s*=x[v];
la=v;
}
pair<ll,int>ma=make_pair(-1,-1);
for(int i=0;i<a.size();i++){
ma=max(ma,make_pair(s/b[i]*c[i],i));
}
return seg1.query(0,a[ma.second])*c[ma.second]%M;
}
int init(int N,int X[],int Y[]) {
n=N;
p.insert(n);
for(int i=0;i<n;i++){
x[i]=X[i];
seg1.update(i,x[i]);
if(i==0||x[i]>1)p.insert(i);
y[i]=Y[i];
seg2.update(i,y[i]);
}
return solve();
}
int updateX(int pos,int val) {
x[pos]=val;
seg1.update(pos,val);
if(x[pos]>1)p.insert(pos);
else if(pos!=0)p.erase(pos);
return solve();
}
int updateY(int pos, int val) {
y[pos]=val;
seg2.update(pos,val);
return solve();
}
Compilation message
horses.cpp: In function 'int solve()':
horses.cpp:52:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
52 | int la=n;
| ^
horses.cpp:56:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
56 | int v=*it;
| ^~~
horses.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i=0;i<a.size();i++){
| ~^~~~~~~~~
horses.cpp:68:34: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
68 | return seg1.query(0,a[ma.second])*c[ma.second]%M;
| ^
horses.cpp:68:48: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
68 | return seg1.query(0,a[ma.second])*c[ma.second]%M;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16720 KB |
Output is correct |
2 |
Correct |
8 ms |
16652 KB |
Output is correct |
3 |
Correct |
8 ms |
16716 KB |
Output is correct |
4 |
Correct |
8 ms |
16716 KB |
Output is correct |
5 |
Correct |
8 ms |
16716 KB |
Output is correct |
6 |
Correct |
8 ms |
16636 KB |
Output is correct |
7 |
Correct |
10 ms |
16716 KB |
Output is correct |
8 |
Correct |
10 ms |
16640 KB |
Output is correct |
9 |
Correct |
8 ms |
16636 KB |
Output is correct |
10 |
Correct |
8 ms |
16716 KB |
Output is correct |
11 |
Correct |
10 ms |
16716 KB |
Output is correct |
12 |
Correct |
8 ms |
16720 KB |
Output is correct |
13 |
Correct |
8 ms |
16676 KB |
Output is correct |
14 |
Correct |
10 ms |
16716 KB |
Output is correct |
15 |
Correct |
8 ms |
16716 KB |
Output is correct |
16 |
Correct |
8 ms |
16656 KB |
Output is correct |
17 |
Correct |
9 ms |
16716 KB |
Output is correct |
18 |
Correct |
8 ms |
16716 KB |
Output is correct |
19 |
Correct |
8 ms |
16720 KB |
Output is correct |
20 |
Correct |
8 ms |
16720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16716 KB |
Output is correct |
2 |
Correct |
9 ms |
16712 KB |
Output is correct |
3 |
Correct |
8 ms |
16716 KB |
Output is correct |
4 |
Correct |
8 ms |
16720 KB |
Output is correct |
5 |
Correct |
8 ms |
16716 KB |
Output is correct |
6 |
Correct |
9 ms |
16716 KB |
Output is correct |
7 |
Correct |
9 ms |
16712 KB |
Output is correct |
8 |
Correct |
10 ms |
16620 KB |
Output is correct |
9 |
Correct |
9 ms |
16716 KB |
Output is correct |
10 |
Correct |
8 ms |
16720 KB |
Output is correct |
11 |
Correct |
9 ms |
16716 KB |
Output is correct |
12 |
Correct |
10 ms |
16716 KB |
Output is correct |
13 |
Correct |
9 ms |
16724 KB |
Output is correct |
14 |
Correct |
8 ms |
16716 KB |
Output is correct |
15 |
Correct |
8 ms |
16716 KB |
Output is correct |
16 |
Correct |
8 ms |
16700 KB |
Output is correct |
17 |
Correct |
8 ms |
16716 KB |
Output is correct |
18 |
Correct |
8 ms |
16716 KB |
Output is correct |
19 |
Correct |
8 ms |
16720 KB |
Output is correct |
20 |
Correct |
11 ms |
16696 KB |
Output is correct |
21 |
Correct |
9 ms |
16716 KB |
Output is correct |
22 |
Correct |
10 ms |
16716 KB |
Output is correct |
23 |
Correct |
12 ms |
16716 KB |
Output is correct |
24 |
Correct |
9 ms |
16716 KB |
Output is correct |
25 |
Correct |
11 ms |
16724 KB |
Output is correct |
26 |
Correct |
10 ms |
16732 KB |
Output is correct |
27 |
Correct |
13 ms |
16716 KB |
Output is correct |
28 |
Correct |
11 ms |
16716 KB |
Output is correct |
29 |
Correct |
10 ms |
16724 KB |
Output is correct |
30 |
Correct |
10 ms |
16712 KB |
Output is correct |
31 |
Correct |
12 ms |
16716 KB |
Output is correct |
32 |
Correct |
13 ms |
16732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
790 ms |
56792 KB |
Output is correct |
2 |
Correct |
461 ms |
65476 KB |
Output is correct |
3 |
Correct |
522 ms |
56704 KB |
Output is correct |
4 |
Correct |
608 ms |
60500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16716 KB |
Output is correct |
2 |
Correct |
8 ms |
16616 KB |
Output is correct |
3 |
Correct |
8 ms |
16716 KB |
Output is correct |
4 |
Correct |
8 ms |
16716 KB |
Output is correct |
5 |
Correct |
8 ms |
16716 KB |
Output is correct |
6 |
Correct |
9 ms |
16640 KB |
Output is correct |
7 |
Correct |
9 ms |
16716 KB |
Output is correct |
8 |
Correct |
8 ms |
16724 KB |
Output is correct |
9 |
Correct |
8 ms |
16716 KB |
Output is correct |
10 |
Correct |
8 ms |
16768 KB |
Output is correct |
11 |
Correct |
8 ms |
16720 KB |
Output is correct |
12 |
Correct |
8 ms |
16712 KB |
Output is correct |
13 |
Correct |
8 ms |
16716 KB |
Output is correct |
14 |
Correct |
8 ms |
16652 KB |
Output is correct |
15 |
Correct |
8 ms |
16716 KB |
Output is correct |
16 |
Correct |
9 ms |
16716 KB |
Output is correct |
17 |
Correct |
9 ms |
16652 KB |
Output is correct |
18 |
Correct |
8 ms |
16716 KB |
Output is correct |
19 |
Correct |
8 ms |
16716 KB |
Output is correct |
20 |
Correct |
8 ms |
16664 KB |
Output is correct |
21 |
Correct |
8 ms |
16716 KB |
Output is correct |
22 |
Correct |
8 ms |
16724 KB |
Output is correct |
23 |
Correct |
10 ms |
16716 KB |
Output is correct |
24 |
Correct |
11 ms |
16716 KB |
Output is correct |
25 |
Correct |
13 ms |
16952 KB |
Output is correct |
26 |
Correct |
11 ms |
16716 KB |
Output is correct |
27 |
Correct |
17 ms |
16728 KB |
Output is correct |
28 |
Correct |
11 ms |
16780 KB |
Output is correct |
29 |
Correct |
10 ms |
16756 KB |
Output is correct |
30 |
Correct |
10 ms |
16716 KB |
Output is correct |
31 |
Correct |
12 ms |
16692 KB |
Output is correct |
32 |
Correct |
13 ms |
16716 KB |
Output is correct |
33 |
Correct |
144 ms |
32504 KB |
Output is correct |
34 |
Correct |
144 ms |
29804 KB |
Output is correct |
35 |
Correct |
356 ms |
53184 KB |
Output is correct |
36 |
Correct |
380 ms |
53304 KB |
Output is correct |
37 |
Correct |
184 ms |
29772 KB |
Output is correct |
38 |
Correct |
223 ms |
41752 KB |
Output is correct |
39 |
Correct |
142 ms |
29608 KB |
Output is correct |
40 |
Correct |
352 ms |
53068 KB |
Output is correct |
41 |
Correct |
156 ms |
29636 KB |
Output is correct |
42 |
Correct |
168 ms |
29704 KB |
Output is correct |
43 |
Correct |
330 ms |
53020 KB |
Output is correct |
44 |
Correct |
337 ms |
53008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16716 KB |
Output is correct |
2 |
Correct |
8 ms |
16696 KB |
Output is correct |
3 |
Correct |
10 ms |
16716 KB |
Output is correct |
4 |
Correct |
9 ms |
16720 KB |
Output is correct |
5 |
Correct |
11 ms |
16740 KB |
Output is correct |
6 |
Correct |
11 ms |
16720 KB |
Output is correct |
7 |
Correct |
9 ms |
16716 KB |
Output is correct |
8 |
Correct |
8 ms |
16716 KB |
Output is correct |
9 |
Correct |
9 ms |
16716 KB |
Output is correct |
10 |
Correct |
8 ms |
16716 KB |
Output is correct |
11 |
Correct |
8 ms |
16648 KB |
Output is correct |
12 |
Correct |
8 ms |
16676 KB |
Output is correct |
13 |
Correct |
9 ms |
16716 KB |
Output is correct |
14 |
Correct |
9 ms |
16716 KB |
Output is correct |
15 |
Correct |
8 ms |
16692 KB |
Output is correct |
16 |
Correct |
8 ms |
16716 KB |
Output is correct |
17 |
Correct |
8 ms |
16628 KB |
Output is correct |
18 |
Correct |
8 ms |
16716 KB |
Output is correct |
19 |
Correct |
8 ms |
16720 KB |
Output is correct |
20 |
Correct |
8 ms |
16720 KB |
Output is correct |
21 |
Correct |
8 ms |
16716 KB |
Output is correct |
22 |
Correct |
9 ms |
16720 KB |
Output is correct |
23 |
Correct |
13 ms |
16692 KB |
Output is correct |
24 |
Correct |
10 ms |
16728 KB |
Output is correct |
25 |
Correct |
11 ms |
16716 KB |
Output is correct |
26 |
Correct |
9 ms |
16740 KB |
Output is correct |
27 |
Correct |
14 ms |
16860 KB |
Output is correct |
28 |
Correct |
11 ms |
16828 KB |
Output is correct |
29 |
Correct |
11 ms |
16692 KB |
Output is correct |
30 |
Correct |
10 ms |
16732 KB |
Output is correct |
31 |
Correct |
12 ms |
16752 KB |
Output is correct |
32 |
Correct |
14 ms |
16708 KB |
Output is correct |
33 |
Correct |
813 ms |
56308 KB |
Output is correct |
34 |
Correct |
501 ms |
54088 KB |
Output is correct |
35 |
Correct |
516 ms |
54016 KB |
Output is correct |
36 |
Correct |
623 ms |
54084 KB |
Output is correct |
37 |
Correct |
147 ms |
29732 KB |
Output is correct |
38 |
Correct |
143 ms |
29716 KB |
Output is correct |
39 |
Correct |
360 ms |
53148 KB |
Output is correct |
40 |
Correct |
374 ms |
53128 KB |
Output is correct |
41 |
Correct |
178 ms |
29768 KB |
Output is correct |
42 |
Correct |
243 ms |
41672 KB |
Output is correct |
43 |
Correct |
139 ms |
29516 KB |
Output is correct |
44 |
Correct |
327 ms |
53172 KB |
Output is correct |
45 |
Correct |
155 ms |
29636 KB |
Output is correct |
46 |
Correct |
165 ms |
29804 KB |
Output is correct |
47 |
Correct |
326 ms |
53064 KB |
Output is correct |
48 |
Correct |
361 ms |
53172 KB |
Output is correct |
49 |
Correct |
285 ms |
31712 KB |
Output is correct |
50 |
Correct |
250 ms |
31708 KB |
Output is correct |
51 |
Correct |
528 ms |
54088 KB |
Output is correct |
52 |
Correct |
429 ms |
54092 KB |
Output is correct |
53 |
Correct |
715 ms |
31784 KB |
Output is correct |
54 |
Correct |
452 ms |
44528 KB |
Output is correct |
55 |
Correct |
252 ms |
29788 KB |
Output is correct |
56 |
Correct |
526 ms |
54136 KB |
Output is correct |
57 |
Correct |
499 ms |
30560 KB |
Output is correct |
58 |
Correct |
565 ms |
30664 KB |
Output is correct |
59 |
Correct |
327 ms |
53064 KB |
Output is correct |