//
// Created by adavy on 2/11/2023.
//
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!
using ii = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vii = vector<ii>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;
// pairs
#define mp make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define len(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front
const int MOD = 1e9+9; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const ld PI = acos((ld)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
#include <stdio.h>
#include <assert.h>
struct Modular {
int value;
static const int MOD_value = MOD;
Modular(long long v = 0) { value = v % MOD; if (value < 0) value += MOD;}
Modular(long long a, long long b) : value(0){ *this += a; *this /= b;}
Modular& operator+=(Modular const& b) {value += b.value; if (value >= MOD) value -= MOD; return *this;}
Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += MOD;return *this;}
Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD;return *this;}
friend Modular mexp(Modular a, long long e) {
Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
return res;
}
friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }
Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
friend Modular operator+(Modular a, Modular const b) { return a += b; }
friend Modular operator-(Modular a, Modular const b) { return a -= b; }
friend Modular operator-(Modular const a) { return 0 - a; }
friend Modular operator*(Modular a, Modular const b) { return a *= b; }
friend Modular operator/(Modular a, Modular const b) { return a /= b; }
friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};
vl X, Y;
ll sz;
vl seg;
set<int> brks;
Modular totalX = 1;
void update(int i, ll x){
i += sz;
seg[i] = x;
i >>= 1;
//cout << i << endl;
while (i > 0){
seg[i] = max(seg[2*i], seg[2*i+1]);
i >>= 1;
}
}
ll query(int l, int r){
l += sz; r += sz;
ll ans = 0;
while(l<=r){
if (l&1) ans = max(ans, seg[l++]);
if (!(r&1)) ans = max(ans, seg[r--]);
l>>=1;
r>>=1;
}
return ans;
}
ll solve(){
//cout << totalX << endl;
ll neg_amount = 1;
ll pos_amount = 1;
ll best = 0;
auto ptr = brks.end();
ptr--; ptr--;
int dist = 0;
//cout << *ptr << endl;
while(ptr != brks.begin() && neg_amount < 1e9 + 7){
neg_amount *= X[*ptr];
ptr--; dist++;
}
//cout << *ptr << " " << *next(ptr)-1 << endl;
//cout << sz << " "<< query(0, 4) << endl;
best = max(best, pos_amount*query(*ptr, *next(ptr)-1));
//cout << best << endl;
F0R(_, dist){
ptr++;
pos_amount*= X[*ptr];
best = max(best, pos_amount*query(*ptr, *next(ptr)-1));
}
return (totalX*best/neg_amount).value;
}
int init(int N, int Xi[], int Yi[]) {
sz = 1<<(ll)(log2(N)+1);
seg.rsz(2*sz);
fill(all(seg),0);
/*
ll myHorses = 1;
ll bestScr = 0;*/
brks.insert(N);
brks.insert(0);
X = vl(Xi, Xi+N);
Y = vl(Yi, Yi+N);
F0R(i, N){
totalX *= X[i];
update(i, Y[i]);
if (X[i] > 1) brks.insert(i);
}
/*
F0R(i, N){
myHorses *= X[i];
bestScr = max(bestScr, myHorses*Y[i]);
}*/
return solve();
}
int updateX(int pos, int val) {
totalX /= X[pos];
if (pos==0){
X[pos] = val;
totalX *= X[pos];
return solve();
}
if (val==1){
if (X[pos]!=1) brks.erase(pos);
X[pos] = val;
}
else {
brks.insert(pos);
X[pos] = val;
}
totalX *= X[pos];
return solve();
}
int updateY(int pos, int val) {
Y[pos] = val;
update(pos, Y[pos]);
return solve();
}
/*
int main(){
int n; cin >> n;
int x[n], y[n];
F0R(i, n) cin >> x[i];
F0R(i, n) cin >> y[i];
cout << init(n, x, y) << endl;
//cout << updateY(1, 2) << endl;
}
*/
Compilation message
horses.cpp: In constructor 'Modular::Modular(long long int)':
horses.cpp:71:42: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
71 | Modular(long long v = 0) { value = v % MOD; if (value < 0) value += MOD;}
| ~~^~~~~
horses.cpp: In member function 'Modular& Modular::operator*=(const Modular&)':
horses.cpp:76:79: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
76 | Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD;return *this;}
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void update(int, ll)':
horses.cpp:103:7: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
103 | i += sz;
| ~~^~~~~
horses.cpp: In function 'll query(int, int)':
horses.cpp:114:7: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
114 | l += sz; r += sz;
| ~~^~~~~
horses.cpp:114:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
114 | l += sz; r += sz;
| ~~^~~~~
horses.cpp: In function 'll solve()':
horses.cpp:137:34: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
137 | while(ptr != brks.begin() && neg_amount < 1e9 + 7){
| ^~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:182:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
182 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:190:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
190 | return solve();
| ~~~~~^~
horses.cpp:203:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
203 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:210:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
210 | return solve();
| ~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 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 |
300 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
216 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 |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 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 |
216 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
304 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
240 ms |
46452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
216 KB |
Output is correct |
5 |
Correct |
1 ms |
216 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
212 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 |
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 |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
21 |
Incorrect |
0 ms |
300 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
216 KB |
Output is correct |
4 |
Correct |
1 ms |
224 KB |
Output is correct |
5 |
Correct |
1 ms |
224 KB |
Output is correct |
6 |
Correct |
0 ms |
224 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
224 KB |
Output is correct |
9 |
Correct |
1 ms |
224 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
224 KB |
Output is correct |
12 |
Correct |
1 ms |
224 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
0 ms |
224 KB |
Output is correct |
15 |
Correct |
1 ms |
224 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
0 ms |
224 KB |
Output is correct |
18 |
Correct |
0 ms |
308 KB |
Output is correct |
19 |
Correct |
1 ms |
224 KB |
Output is correct |
20 |
Correct |
0 ms |
216 KB |
Output is correct |
21 |
Incorrect |
1 ms |
216 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |