#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<long long> x, y;
struct SegTree {
int size = 1;
vector<long long> pr;
void init(){
while(size < (int)x.size())
size <<= 1;
pr.resize(size << 1, 1);
build(0, 0, size);
}
void build(int ind, int lx, int rx){
if(lx + 1 == rx){
if(lx < x.size())
pr[ind] = x[lx];
return;
}
int mid = (lx + rx) >> 1;
build((ind << 1) + 1, lx, mid);
build((ind << 1) + 2, mid, rx);
pr[ind] = (pr[(ind << 1) + 1] * pr[(ind << 1) + 2]) % mod;
}
void change(int pos, int val, int x, int lx, int rx){
if(lx + 1 == rx){
pr[x] = val;
return;
}
int mid = (lx + rx) >> 1;
if(pos < mid)
change(pos, val, (x << 1) + 1, lx, mid);
else
change(pos, val, (x << 1) + 2, mid, rx);
pr[x] = (pr[(x << 1) + 1] * pr[(x << 1) + 2]) % mod;
}
void change(int pos, int val){
change(pos, val, 0, 0, size);
}
long long get(int l, int r, int ind, int lx, int rx){
if(l <= lx and rx <= r)
return pr[ind];
if(r <= lx or rx <= l)
return 1ll;
int mid = (lx + rx) >> 1;
return (get(l, r, (ind << 1) + 1, lx, mid) * get(l, r, (ind << 1) + 2, mid, rx)) % mod;
}
long long get(int l, int r){
return get(l, r, 0, 0, size);
}
};
SegTree s;
int init(int n, int X[], int Y[]) {
x.resize(n);
y.resize(n);
for(int i = 0; i < n; i ++)
x[i] = X[i], y[i] = Y[i];
s.init();
long long y1 = 0, p = 1, ans = 1;
for(int i = n - 1; i >= 0; i --){
if(p > 1e9 or y1 * p > 1e9)
return ans;
if(y[i] > y1 * p){
y1 = y[i];
p = 1;
ans = (y1 * s.get(0, i + 1)) % mod;
}
p = p * x[i];
}
return ans;
}
int updateX(int pos, int val) {
x[pos] = val;
s.change(pos, val);
int n = (int)x.size();
long long y1 = 0, p = 1, ans = 1;
for(int i = n - 1; i >= 0; i --){
if(p > 1e9 or y1 * p > 1e9)
return ans;
if(y[i] > y1 * p){
y1 = y[i];
p = 1;
ans = (y1 * s.get(0, i + 1)) % mod;
}
p = p * x[i];
}
return ans;
}
int updateY(int pos, int val) {
y[pos] = val;
int n = (int)x.size();
long long y1 = 0, p = 1, ans = 1;
for(int i = n - 1; i >= 0; i --){
if(p > 1e9 or y1 * p > 1e9)
return ans;
if(y[i] > y1 * p){
y1 = y[i];
p = 1;
ans = (y1 * s.get(0, i + 1)) % mod;
}
p = p * x[i];
}
return ans;
}
Compilation message
horses.cpp: In member function 'void SegTree::build(int, int, int)':
horses.cpp:22:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | if(lx < x.size())
| ~~~^~~~~~~~~~
horses.cpp: In member function 'void SegTree::change(int, int, int, int, int)':
horses.cpp:32:36: warning: declaration of 'x' shadows a global declaration [-Wshadow]
32 | void change(int pos, int val, int x, int lx, int rx){
| ~~~~^
horses.cpp:6:19: note: shadowed declaration is here
6 | vector<long long> x, y;
| ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:73:6: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
73 | if(p > 1e9 or y1 * p > 1e9)
| ^
horses.cpp:73:20: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
73 | if(p > 1e9 or y1 * p > 1e9)
| ~~~^~~
horses.cpp:74:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
74 | return ans;
| ^~~
horses.cpp:82:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
82 | return ans;
| ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:91:6: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
91 | if(p > 1e9 or y1 * p > 1e9)
| ^
horses.cpp:91:20: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
91 | if(p > 1e9 or y1 * p > 1e9)
| ~~~^~~
horses.cpp:92:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
92 | return ans;
| ^~~
horses.cpp:100:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
100 | return ans;
| ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:108:6: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
108 | if(p > 1e9 or y1 * p > 1e9)
| ^
horses.cpp:108:20: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
108 | if(p > 1e9 or y1 * p > 1e9)
| ~~~^~~
horses.cpp:109:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
109 | return ans;
| ^~~
horses.cpp:117:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
117 | return ans;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
496 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
516 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
22852 KB |
Output is correct |
2 |
Correct |
82 ms |
33948 KB |
Output is correct |
3 |
Correct |
49 ms |
25104 KB |
Output is correct |
4 |
Correct |
75 ms |
29012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
53 ms |
24196 KB |
Output is correct |
34 |
Correct |
27 ms |
24412 KB |
Output is correct |
35 |
Correct |
53 ms |
31140 KB |
Output is correct |
36 |
Correct |
48 ms |
31172 KB |
Output is correct |
37 |
Correct |
296 ms |
22364 KB |
Output is correct |
38 |
Correct |
24 ms |
23384 KB |
Output is correct |
39 |
Execution timed out |
1569 ms |
22576 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
49 ms |
25004 KB |
Output is correct |
34 |
Correct |
84 ms |
33964 KB |
Output is correct |
35 |
Correct |
57 ms |
25172 KB |
Output is correct |
36 |
Correct |
75 ms |
28916 KB |
Output is correct |
37 |
Correct |
53 ms |
24412 KB |
Output is correct |
38 |
Correct |
27 ms |
24248 KB |
Output is correct |
39 |
Correct |
52 ms |
31300 KB |
Output is correct |
40 |
Correct |
48 ms |
31060 KB |
Output is correct |
41 |
Correct |
304 ms |
22356 KB |
Output is correct |
42 |
Correct |
25 ms |
23380 KB |
Output is correct |
43 |
Execution timed out |
1554 ms |
22448 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |