#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN=5e5, M=1e9+7;
int n, sty[2*mxN], cy[mxN];
ll stx[2*mxN];
set<int> s;
ll qryx(int l, int r) {
ll b=1;
for(l+=n, r+=n; l<r; ++l/=2, r/=2) {
if(l&1)
b=b*stx[l]%M;
if(r&1)
b=b*stx[r-1]%M;
}
return b;
}
int qryy(int l, int r) {
int b=0;
for(l+=n, r+=n; l<r; ++l/=2, r/=2) {
if(l&1)
b=max(sty[l], b);
if(r&1)
b=max(sty[r-1], b);
}
return b;
}
int c() {
ll mx=0;
auto it=s.end();
while(mx<1e9&&*it) {
--it;
mx=max((ll)cy[*it], mx);
mx*=stx[n+*it];
}
return mx%M*qryx(0, *it)%M;
}
int updateX(int i, int x) {
s.erase(i);
if(!i||x>1)
s.insert(i);
int j=n+i;
for(stx[j]=x; j/=2;)
stx[j]=stx[2*j]*stx[2*j+1]%M;
auto it=s.upper_bound(i);
int r=*it, l=*--it;
cy[l]=qryy(l, r);
if(l) {
r=*it, l=*--it;
cy[l]=qryy(l, r);
}
return c();
}
int updateY(int i, int x) {
int j=n+i;
for(sty[j]=x; j/=2;)
sty[j]=max(sty[2*j], sty[2*j+1]);
auto it=s.upper_bound(i);
int r=*it, l=*--it;
cy[l]=qryy(l, r);
return c();
}
int init(int n, int* x, int* y) {
::n=n;
for(int i=0; i<n; ++i) {
stx[n+i]=x[i];
sty[n+i]=y[i];
if(!i||x[i]>1)
s.insert(s.end(), i);
}
s.insert(s.end(), n);
for(int i=n-1; i; --i) {
stx[i]=stx[2*i]*stx[2*i+1]%M;
sty[i]=max(sty[2*i], sty[2*i+1]);
}
for(auto it=s.begin(); *it<n;) {
int l=*it, r=*++it;
cy[l]=qryy(l, r);
}
return c();
}
Compilation message
horses.cpp: In function 'int c()':
horses.cpp:37:8: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
37 | while(mx<1e9&&*it) {
| ^~
horses.cpp:42:26: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
42 | return mx%M*qryx(0, *it)%M;
| ~~~~~~~~~~~~~~~~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:72:31: warning: declaration of 'n' shadows a global declaration [-Wshadow]
72 | int init(int n, int* x, int* y) {
| ^
horses.cpp:8:5: note: shadowed declaration is here
8 | int n, sty[2*mxN], cy[mxN];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
416 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
512 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
42488 KB |
Output is correct |
2 |
Correct |
341 ms |
55088 KB |
Output is correct |
3 |
Correct |
298 ms |
46200 KB |
Output is correct |
4 |
Correct |
341 ms |
50040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
512 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
41 ms |
22136 KB |
Output is correct |
34 |
Correct |
41 ms |
22136 KB |
Output is correct |
35 |
Correct |
139 ms |
52472 KB |
Output is correct |
36 |
Correct |
150 ms |
52344 KB |
Output is correct |
37 |
Correct |
33 ms |
19320 KB |
Output is correct |
38 |
Correct |
70 ms |
32964 KB |
Output is correct |
39 |
Correct |
26 ms |
18048 KB |
Output is correct |
40 |
Correct |
114 ms |
47528 KB |
Output is correct |
41 |
Correct |
25 ms |
18296 KB |
Output is correct |
42 |
Correct |
28 ms |
18176 KB |
Output is correct |
43 |
Correct |
111 ms |
47864 KB |
Output is correct |
44 |
Correct |
110 ms |
47864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
512 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
33 |
Correct |
176 ms |
46236 KB |
Output is correct |
34 |
Correct |
331 ms |
55032 KB |
Output is correct |
35 |
Correct |
298 ms |
46200 KB |
Output is correct |
36 |
Correct |
355 ms |
50152 KB |
Output is correct |
37 |
Correct |
42 ms |
22136 KB |
Output is correct |
38 |
Correct |
43 ms |
22136 KB |
Output is correct |
39 |
Correct |
134 ms |
52600 KB |
Output is correct |
40 |
Correct |
133 ms |
52344 KB |
Output is correct |
41 |
Correct |
32 ms |
19320 KB |
Output is correct |
42 |
Correct |
71 ms |
33124 KB |
Output is correct |
43 |
Correct |
26 ms |
18176 KB |
Output is correct |
44 |
Correct |
112 ms |
47572 KB |
Output is correct |
45 |
Correct |
25 ms |
18176 KB |
Output is correct |
46 |
Correct |
26 ms |
18168 KB |
Output is correct |
47 |
Correct |
109 ms |
47992 KB |
Output is correct |
48 |
Correct |
110 ms |
47864 KB |
Output is correct |
49 |
Correct |
140 ms |
25132 KB |
Output is correct |
50 |
Correct |
138 ms |
25080 KB |
Output is correct |
51 |
Correct |
204 ms |
54264 KB |
Output is correct |
52 |
Correct |
202 ms |
53880 KB |
Output is correct |
53 |
Correct |
143 ms |
22392 KB |
Output is correct |
54 |
Correct |
145 ms |
36984 KB |
Output is correct |
55 |
Correct |
76 ms |
19192 KB |
Output is correct |
56 |
Correct |
181 ms |
49272 KB |
Output is correct |
57 |
Correct |
63 ms |
19832 KB |
Output is correct |
58 |
Correct |
84 ms |
20216 KB |
Output is correct |
59 |
Correct |
106 ms |
47868 KB |
Output is correct |