# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
126543 | Eug1ena | Horses (IOI15_horses) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
lint power(lint base, lint exponent){
if(exponent & 1){
return power(base, exponent - 1) * base % mod;
}else if(exponent){
lint root = power(base, exponent / 2);
return root * root % mod;
}else{
return 1;
}
}
struct segtree{
int sz = 1;
vector<pair<double, lint>> data;
vector<pair<lint, lint>> lazy;
segtree(int n){
while(n > sz){
sz *= 2;
}
data.resize(sz * 2 - 1, {0.0, 1});
lazy.resize(sz * 2 - 1, {0.0, 1});
}
pair<double, lint> muldev(pair<double, lint> a, pair<lint, lint> b){
a.first += log(b.first) - log(b.second);
a.second = (a.second * b.first) % mod * power(b.second, mod - 2) % mod;
}
void eval(int l, int r, int now){
data[now] = muldev(data[now], lazy[now]);
if(r - l > 1){
lazy[now * 2 + 1].first = (lazy[now * 2 + 1].first * lazy[now].first) % mod;
lazy[now * 2 + 1].second = (lazy[now * 2 + 1].second * lazy[now].second) % mod;
lazy[now * 2 + 2].first = (lazy[now * 2 + 2].first * lazy[now].first) % mod;
lazy[now * 2 + 2].second = (lazy[now * 2 + 2].second * lazy[now].second) % mod;
}
lazy[now] = {1, 1};
}
pair<double, lint> maximum(int a, int b, int l, int r, int now){
eval(l, r, now);
if(a <= l && r <= b){
return data[now];
}else if(r <= a || b <= l){
return {0.0, 1};
}else{
return max(maximum(a, b, l, (l + r) / 2, now * 2 + 1), maximum(a, b, (l + r) / 2, r, now * 2 + 2));
}
}
void change(int a, in)
};
int main(){
}