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>
using namespace std;
#include "horses.h"
//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()
const int MX = 5e5+10;
const int MOD = 1e9+7;
ll n, x[MX], y[MX];
ll segX[MX*2];
ll segY[MX*2];
set<int> corX;
void buildSeg() {
RE(i,n) segX[i+n] = x[i];
RE(i,n) segY[i+n] = y[i];
REV(i,1,n) segX[i] = (segX[i*2]*segX[i*2+1])%MOD;
REV(i,1,n) segY[i] = max(segY[i*2], segY[i*2+1]);
}
void setSegX(int i, ll v) {
for(segX[i+=n]=v; i>1; i/=2) segX[i/2] = (segX[i]*segX[i^1])%MOD;
}
void setSegY(int i, ll v) {
for(segY[i+=n]=v; i>1; i/=2) segY[i/2] = max(segY[i], segY[i^1]);
}
ll getSegX(int l, int r) {
ll res = 1;
for(l+=n, r+=n; l<r; l/=2, r/=2) {
if(l&1) res = (res*segX[l++])%MOD;
if(r&1) res = (res*segX[--r])%MOD;
}
return res;
}
ll getSegY(int l, int r) {
ll res = 0;
for(l+=n, r+=n; l<r; l/=2, r/=2) {
if(l&1) res = max(res, segY[l++]);
if(r&1) res = max(res, segY[--r]);
}
return res;
}
int getAns() {
ll bst = 1;
int i=n;
auto it = corX.end();
while(it != corX.begin()) {
--it;
bst = x[*it]*max(bst, getSegY(*it,i));
i = *it;
if(bst >= INF) {
break;
}
}
bst = max(bst, getSegY(0,n));
bst %= MOD;
bst = (bst*getSegX(0,i))%MOD;
return bst;
}
int init(int N, int X[], int Y[]) {
n=N;
RE(i,n) x[i]=X[i];
RE(i,n) y[i]=Y[i];
RE(i,n) if(x[i] != 1) corX.insert(i);
buildSeg();
return getAns();
}
int updateX(int pos, int val) {
corX.erase(pos);
x[pos] = val;
if(val != 1) corX.insert(pos);
setSegX(pos, val);
return getAns();
}
int updateY(int pos, int val) {
y[pos] = val;
setSegY(pos, val);
return getAns();
}
Compilation message (stderr)
horses.cpp: In function 'void setSegX(int, ll)':
horses.cpp:42:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
42 | for(segX[i+=n]=v; i>1; i/=2) segX[i/2] = (segX[i]*segX[i^1])%MOD;
| ~^~~
horses.cpp: In function 'void setSegY(int, ll)':
horses.cpp:45:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
45 | for(segY[i+=n]=v; i>1; i/=2) segY[i/2] = max(segY[i], segY[i^1]);
| ~^~~
horses.cpp: In function 'll getSegX(int, int)':
horses.cpp:49:10: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
49 | for(l+=n, r+=n; l<r; l/=2, r/=2) {
| ~^~~
horses.cpp:49:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
49 | for(l+=n, r+=n; l<r; l/=2, r/=2) {
| ~^~~
horses.cpp: In function 'll getSegY(int, int)':
horses.cpp:57:10: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
57 | for(l+=n, r+=n; l<r; l/=2, r/=2) {
| ~^~~
horses.cpp:57:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
57 | for(l+=n, r+=n; l<r; l/=2, r/=2) {
| ~^~~
horses.cpp: In function 'int getAns()':
horses.cpp:66:11: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
66 | int i=n;
| ^
horses.cpp:72:12: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
72 | if(bst >= INF) {
| ^~~
horses.cpp:76:30: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
76 | bst = max(bst, getSegY(0,n));
| ^
horses.cpp:79:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
79 | return bst;
| ^~~
# | 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... |