#include <horses.h>
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define p_b pop_back
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll sz = 5e5+5, mod = 1e9+7;
ll a[sz], b[sz], segtree[4*sz], segtree2[4*sz], n;
void build(ll v, ll l, ll r)
{
if(l == r)
{
segtree[v] = a[l];
return;
}
else
{
ll mid = (l + r) / 2;
build(2*v, l, mid);
build(2*v+1, mid+1, r);
segtree[v] = ((segtree[2*v] * segtree[2*v+1]) % mod);
}
}
void update(ll v, ll l, ll r, ll idx, ll val)
{
if(l == r)
segtree[v] = val;
else
{
ll mid = (l + r) / 2;
if(idx <= mid)
update(2*v, l, mid, idx, val);
else
update(2*v+1, mid+1, r, idx, val);
segtree[v] = ((segtree[2*v] * segtree[2*v+1]) % mod);
}
}
ll findans(ll v, ll l, ll r, ll tl, ll tr)
{
if(tl > tr)
return 1;
if(l == tl && r == tr)
return segtree[v];
else
{
ll mid = (l + r) / 2;
ll lans = findans(2*v, l, mid, tl, min(mid, tr));
ll rans = findans(2*v+1, mid+1, r, max(mid+1, tl), tr);
return ((lans % mod) * (rans % mod)) % mod;
}
}
void build2(ll v, ll l, ll r)
{
if(l == r){
segtree2[v] = ((findans(1, 1, n, 1, l) * b[l]) % mod);
return;
}
ll mid = (l + r) / 2;
build2(2*v, l, mid);
build2(2*v+1, mid+1, r);
segtree2[v] = max(segtree2[2*v], segtree2[2*v+1]);
}
void update2(ll v, ll l, ll r, ll idx, ll val)
{
if(l == r)
segtree2[v] = ((findans(1, 1, n, 1, l) * val) % mod);
else
{
ll mid = (l + r) / 2;
if(idx <= mid)
update2(2*v, l, mid, idx, val);
else
update2(2*v+1, mid+1, r, idx, val);
segtree2[v] = max(segtree2[2*v], segtree2[2*v+1]);
}
}
ll findans2(ll v, ll l, ll r, ll tl, ll tr)
{
if(tl > tr)
return LLONG_MIN;
if(l == tl && r == tr)
return segtree2[v];
else
{
ll mid = (l + r) / 2;
ll lans = findans2(2*v, l, mid, tl, min(mid, tr));
ll rans = findans2(2*v+1, mid+1, r, max(mid+1, tl), tr);
return max(lans, rans);
}
}
int init(int N, int X[], int Y[]) {
n = N;
for(ll i = 1; i <= n; i++)
{
a[i] = X[i-1];
b[i] = Y[i-1];
}
build(1, 1, n);
build2(1, 1, n);
return findans2(1, 1, n, 1, n) % mod;
}
int updateX(int pos, int val) {
pos++;
update(1, 1, n, pos, val);
return findans(1, 1, n, 1, n);
}
int updateY(int pos, int val) {
pos++;
update2(1, 1, n, pos, val);
return findans2(1, 1, n, 1, n);
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:114:36: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
114 | return findans2(1, 1, n, 1, n) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:119:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
119 | return findans(1, 1, n, 1, n);
| ~~~~~~~^~~~~~~~~~~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:124:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
124 | return findans2(1, 1, n, 1, n);
| ~~~~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6592 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6488 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6600 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
117 ms |
35832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
0 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6488 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6592 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6744 KB |
Output is correct |
21 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |