# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
746097 |
2023-05-21T12:26:50 Z |
Boomyday |
Horses (IOI15_horses) |
C++17 |
|
37 ms |
42316 KB |
//
// 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;
while (i > 0){
seg[i] = max(seg[1<<i], seg[(1<<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(){
ll neg_amount = 1;
ll pos_amount = 1;
ll best = 0;
auto ptr = brks.end();
ptr--; ptr--;
int dist = 0;
while(ptr != brks.begin() && neg_amount < 1e9 + 7){
neg_amount *= X[*ptr];
ptr--; dist++;
}
best = max(best, pos_amount*query(*ptr, *next(ptr)-1));
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:113:7: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
113 | l += sz; r += sz;
| ~~^~~~~
horses.cpp:113:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
113 | l += sz; r += sz;
| ~~^~~~~
horses.cpp: In function 'll solve()':
horses.cpp:133:34: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
133 | while(ptr != brks.begin() && neg_amount < 1e9 + 7){
| ^~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:173:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
173 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:181:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
181 | return solve();
| ~~~~~^~
horses.cpp:194:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
194 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:201:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
201 | return solve();
| ~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
37 ms |
42316 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |