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 "horses.h"
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;
const int mod=1e9+7, Log=30, maxn=5e5, Log1=19, pot=(1<<Log1);
inline int sum(int a, int b){
if(a+b>=mod){
return a+b-mod;
}
if(a+b<0){
return a+b+mod;
}
return a+b;
}
inline int mul(int a, int b){
return (ll)a*b%mod;
}
inline int pote(int a, int b){
int sol=1;
for(int i=0; i<Log; i++){
if((1<<i)&b){
sol=mul(sol, a);
}
a=mul(a, a);
}
return sol;
}
inline int dij(int a, int b){
return mul(a, pote(b, mod-2));
}
int t[pot*2];
int prop[pot*2];
int a[maxn];
int b[maxn];
void precompute(){
for(int i=1; i<pot*2; i++){
prop[i]=1;
}
}
void propagate(int x){
if(prop[x]==1){
return;
}
t[x]=mul(t[x], prop[x]);
if(x<pot){
prop[x*2]=mul(prop[x*2], prop[x]);
prop[x*2+1]=mul(prop[x*2+1], prop[x]);
}
prop[x]=1;
}
void update(int L, int D, int x, int l, int d, int val){
propagate(x);
if(L>=l && D<=d){
t[x]=mul(t[x], val);
if(x<pot){
prop[x*2]=mul(prop[x*2], val);
prop[x*2+1]=mul(prop[x*2+1], val);
}
return;
}
if((L+D)/2>=l){
update(L, (L+D)/2, x*2, l, d, val);
}
if((L+D)/2+1<=d){
update((L+D)/2+1, D, x*2+1, l, d, val);
}
t[x]=max(t[x*2], t[x*2+1]);
}
int init(int n, int x[], int y[]){
int val=1;
for(int i=0; i<n; i++){
a[i]=x[i];
b[i]=y[i];
val=mul(val, a[i]);
update(0, pot-1, 1, i, i, mul(val, b[i]));
}
return t[1];
}
int updateX(int pos, int val) {
update(0, pot-1, 1, pos, pot-1, dij(val, a[pos]));
a[pos]=val;
return t[1];
}
int updateY(int pos, int val) {
update(0, pot-1, 1, pos, pos, dij(val, b[pos]));
b[pos]=val;
return t[1];
}
Compilation message (stderr)
horses.cpp: In function 'int mul(int, int)':
horses.cpp:23:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
23 | return (ll)a*b%mod;
| ~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |