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 <bits/stdc++.h>
#include "horses.h"
using namespace std;
const long long mod = 1e9+7;
int n;
long long seg[2000100], x[500100], y[500100], lazy[2000100];
void build (int now = 1, int l = 0, int r = n-1) {
lazy[now] = 1;
if (l == r) return void(seg[now] = (x[l]*y[l])%mod);
int mid = (l+r)/2;
build(now*2, l, mid); build(now*2+1, mid+1, r);
seg[now] = max(seg[now*2], seg[now*2+1]);
}
void push (int now) {
if (lazy[now] == 1) return;
lazy[now*2] *= lazy[now];
lazy[now*2] %= mod;
lazy[now*2+1] *= lazy[now];
lazy[now*2+1] %= mod;
seg[now] *= lazy[now];
seg[now] %= mod;
lazy[now] = 1;
}
long long query (int now = 1) {
push(now);
return seg[now];
}
void update (int a, int b, long long val, int now = 1, int l = 0, int r = n-1) {
push(now);
if (r < a or b < l) return;
if (a <= l and r <= b) {
lazy[now] *= val;
lazy[now] %= mod;
push(now);
return;
}
int mid = (l+r)/2;
update(a, b, val, now*2, l, mid); update(a, b, val, now*2+1, mid+1, r);
seg[now] = max(seg[now*2], seg[now*2+1]);
}
long long inverse (long long a, long long n = mod-2) {
if (n == 1) return a;
long long r = inverse(a, n/2);
r *= r;
r %= mod;
if (n&1) return (r*a) % mod;
return r;
}
int init(int N, int X[], int Y[]) {
n = N;
x[0] = X[0];
for (int i = 1; i < n; i++) {
x[i] = X[i]*x[i-1];
x[i] %= mod;
}
for (int i = 0; i < n; i++) y[i] = Y[i];
build(); // for (int i = 0; i < n; i++) cerr << x[i]*y[i] << endl;
for (int i = 0; i < n; i++) x[i] = X[i];
return (int)query();
}
int updateX(int pos, int val) {
update(pos, n-1, inverse(x[pos]));
x[pos] = val;
update(pos, n-1, x[pos]);
return query();
}
int updateY(int pos, int val) {
update(pos, pos, inverse(y[pos]));
assert(((inverse(y[pos]) * y[pos]) % mod) == 1);
y[pos] = val;
update(pos, pos, y[pos]);
return query();
}
Compilation message (stderr)
horses.cpp: In function 'long long int inverse(long long int, long long int)':
horses.cpp:47:52: warning: declaration of 'n' shadows a global declaration [-Wshadow]
long long inverse (long long a, long long n = mod-2) {
^
horses.cpp:6:5: note: shadowed declaration is here
int n;
^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:73:14: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return query();
~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:81:14: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return query();
~~~~~^~
# | 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... |