#include "horses.h"
#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define pb push_back
#define left (h<<1),l,(l+r)>>1
#define right ((h<<1)|1),((l+r)>>1) + 1,r
using namespace std;
const int mod = 1000000007,N = 500005;
ll x[N],y[N],ans;
int n;
struct {
ll nam;
ll maxy;
int id;
//id = (l,r) shualedshi 1sgan(x[i]) gansxvavebuli sul marjvena ricxvis indexi
} t[4*N];
void upd(int h,int l,int r,int idx){
if (l == r){
t[h].id = 0;
if (x[l] != 1) t[h].id = l;
t[h].nam = x[l];
t[h].maxy = y[l];
return;
}
if (idx > (l + r)/2) upd(right,idx);
else upd(left,idx);
if (x[t[h*2 + 1].id] > 1){
t[h].id = t[h*2 + 1].id;
}else if (x[t[h*2].id] > 1){
t[h].id =t[h*2].id;
}else{
t[h].id=0;
}
t[h].maxy = max(t[h*2].maxy, t[h*2+1].maxy);
t[h].nam = (t[h*2].nam * t[h*2+1].nam)%mod;
}
ll getnam (int h,int l,int r,int L,int R){
if (r < L || R < l) return 1;
if (L <= l && r <= R) return t[h].nam;
ll X = getnam(left,L,R),Y = getnam(right,L,R);
return (X*Y)%mod;
}
ll getid(int h,int l,int r,int L,int R){
if (r < L || R < l) return 0LL;
if (L <= l && r <= R) return t[h].id;
int X = getid(left,L,R),Y = getid(right,L,R);
if (x[Y] > 1) return Y;
if (x[X] > 1) return X;
return 0;
}
ll getmaxy(int h,int l,int r,int L,int R){
if (r < L || R < l) return 0LL;
if (L <= l && r <= R) return t[h].maxy;
return max(getmaxy(left,L,R),getmaxy(right,L,R));
}
void go(){
vector <pair<ll,ll>> vec; vec.clear();
int r = n;
for (int o = 1; o <= 60; o++){
if (r < 1) break;
if (x[r] != 1LL) {
vec.pb({x[r],y[r]});
r--;
continue;
}
int res = getid(1,1,n,1,r) + 1;
vec.pb({1LL,getmaxy(1,1,n,res,r)});
r = res - 1;
}
reverse(vec.begin(),vec.end());
ll k = 1LL,yy = vec[0].s,p = vec[0].f;
bool q=0;
ans = (p*yy)%mod;
for (int j = 1; j<vec.size(); j++){
ll X = vec[j].f,Y = vec[j].s;
p = (p * X)%mod;
if (!q && k < 1e9) k *= X;
if (k >= 1e9) q=1;
if (q || (k*Y >= yy)){
yy = Y;
ans = (p * Y)%mod;
k=1LL; q=0;
}
}
ans = (ans * getnam(1,1,n,1,r))%mod;
}
int init(int N, int X[], int Y[]) {
n=N;
for (int i = 1;i <= n; i++)
x[i] = X[i-1],y[i] = Y[i-1],upd(1,1,n,i);
go();
return ans;
}
int updateX(int pos, int val) {
pos++;
x[pos] = val;
upd(1,1,n,pos);
go();
return ans;
}
int updateY(int pos, int val) {
pos++;
y[pos]=val;
upd(1,1,n,pos);
go();
return ans;
}
Compilation message
horses.cpp: In function 'long long int getid(int, int, int, int, int)':
horses.cpp:56:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
56 | int X = getid(left,L,R),Y = getid(right,L,R);
| ~~~~~^~~~~~~~~~
horses.cpp:56:36: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
56 | int X = getid(left,L,R),Y = getid(right,L,R);
| ~~~~~^~~~~~~~~~~
horses.cpp: In function 'void go()':
horses.cpp:79:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
79 | int res = getid(1,1,n,1,r) + 1;
| ~~~~~~~~~~~~~~~~~^~~
horses.cpp:88:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for (int j = 1; j<vec.size(); j++){
| ~^~~~~~~~~~~
horses.cpp:91:15: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
91 | if (!q && k < 1e9) k *= X;
| ^
horses.cpp:92:9: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
92 | if (k >= 1e9) q=1;
| ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:104:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
104 | int init(int N, int X[], int Y[]) {
| ~~~~^
horses.cpp:11:28: note: shadowed declaration is here
11 | const int mod = 1000000007,N = 500005;
| ^
horses.cpp:110:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
110 | return ans;
| ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:118:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
118 | return ans;
| ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:126:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
126 | return ans;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
304 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
304 KB |
Output is correct |
23 |
Correct |
6 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
6 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
263 ms |
41380 KB |
Output is correct |
2 |
Correct |
344 ms |
50188 KB |
Output is correct |
3 |
Correct |
333 ms |
41420 KB |
Output is correct |
4 |
Correct |
337 ms |
45280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
9 ms |
312 KB |
Output is correct |
24 |
Correct |
3 ms |
316 KB |
Output is correct |
25 |
Correct |
3 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
340 KB |
Output is correct |
27 |
Correct |
5 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
412 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
7 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
6 ms |
320 KB |
Output is correct |
33 |
Correct |
248 ms |
40680 KB |
Output is correct |
34 |
Correct |
169 ms |
40652 KB |
Output is correct |
35 |
Correct |
197 ms |
47716 KB |
Output is correct |
36 |
Correct |
186 ms |
47540 KB |
Output is correct |
37 |
Correct |
270 ms |
38800 KB |
Output is correct |
38 |
Correct |
202 ms |
39700 KB |
Output is correct |
39 |
Correct |
142 ms |
38732 KB |
Output is correct |
40 |
Correct |
147 ms |
42676 KB |
Output is correct |
41 |
Correct |
127 ms |
38788 KB |
Output is correct |
42 |
Correct |
217 ms |
38848 KB |
Output is correct |
43 |
Correct |
155 ms |
43016 KB |
Output is correct |
44 |
Correct |
141 ms |
42972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
304 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
300 KB |
Output is correct |
23 |
Correct |
7 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
6 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
320 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Correct |
282 ms |
41380 KB |
Output is correct |
34 |
Correct |
335 ms |
50256 KB |
Output is correct |
35 |
Correct |
298 ms |
41432 KB |
Output is correct |
36 |
Correct |
304 ms |
45280 KB |
Output is correct |
37 |
Correct |
249 ms |
40652 KB |
Output is correct |
38 |
Correct |
141 ms |
40640 KB |
Output is correct |
39 |
Correct |
171 ms |
47640 KB |
Output is correct |
40 |
Correct |
164 ms |
47496 KB |
Output is correct |
41 |
Correct |
230 ms |
38788 KB |
Output is correct |
42 |
Correct |
173 ms |
39652 KB |
Output is correct |
43 |
Correct |
127 ms |
38860 KB |
Output is correct |
44 |
Correct |
150 ms |
42620 KB |
Output is correct |
45 |
Correct |
126 ms |
38732 KB |
Output is correct |
46 |
Correct |
216 ms |
38944 KB |
Output is correct |
47 |
Correct |
137 ms |
43028 KB |
Output is correct |
48 |
Correct |
130 ms |
42940 KB |
Output is correct |
49 |
Correct |
1160 ms |
42612 KB |
Output is correct |
50 |
Correct |
340 ms |
42712 KB |
Output is correct |
51 |
Correct |
402 ms |
49484 KB |
Output is correct |
52 |
Correct |
317 ms |
49036 KB |
Output is correct |
53 |
Correct |
1105 ms |
41132 KB |
Output is correct |
54 |
Correct |
655 ms |
41528 KB |
Output is correct |
55 |
Correct |
244 ms |
39904 KB |
Output is correct |
56 |
Correct |
304 ms |
44492 KB |
Output is correct |
57 |
Correct |
215 ms |
40432 KB |
Output is correct |
58 |
Correct |
1042 ms |
41008 KB |
Output is correct |
59 |
Correct |
137 ms |
42952 KB |
Output is correct |