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 <bits/stdc++.h>
#define lli long long
using namespace std;
const int N = 5e5 + 30;
const lli mod = 1e9 + 7;
int n;
lli x[N], y[N];
lli t[4*N], t1[4*N];
set <int> fp;
void upd(int q, lli v, int l = 0, int r = n - 1, int nd = 1)
{
if(q > r || q < l) return;
if(l == r)
{
t[nd] = v;
return;
}
int md = (l + r) / 2;
upd(q, v, l, md, nd * 2);
upd(q, v, md + 1, r, nd * 2 + 1);
t[nd] = max(t[nd*2], t[nd*2+1]);
}
lli qry(int l, int r, int nl = 0, int nr = n - 1, int nd = 1)
{
if(l > nr || r < nl) return 0;
if(nl==l&&r==nr) return t[nd];
int md = (nl + nr)/2;
return max(qry(l, min(md, r), nl, md, nd*2), qry(max(md + 1, l), r, md + 1, nr, nd * 2 + 1));
}
void upd1(int q, lli v, int l = 0, int r = n - 1, int nd = 1)
{
if(q > r || q < l) return;
if(l == r)
{
t1[nd] = v;
return;
}
int md = (l + r) / 2;
upd1(q, v, l, md, nd * 2);
upd1(q, v, md + 1, r, nd * 2 + 1);
t1[nd] = (t1[nd*2] * t[nd*2+1]) % mod;
}
lli qry1(int l, int r, int nl = 0, int nr = n - 1, int nd = 1)
{
if(l > nr || r < nl) return 1;
if(nl==l&&r==nr) return t1[nd];
int md = (nl + nr)/2;
return (qry1(l, min(md, r), nl, md, nd*2) * qry1(max(md + 1, l), r, md + 1, nr, nd * 2 + 1))%mod;
}
lli slv()
{
auto i1 = fp.end();
int nx = n - 1;
lli mx = 0;
do
{
--i1;
//cout << *i1 << "<-" << endl;
mx = max(mx, qry(*i1, nx));
mx *= x[*i1];
nx = (*i1) - 1;
//if(mx > mod) break;
} while (i1 != fp.begin());
mx %= mod;
//cout << "SM" << endl;
return (mx * qry1(0, nx))%mod;
}
int init(int N, int X[], int Y[])
{
n = N;
fp.insert(0);
for (int i = 0; i < n; i++)
{
x[i]=X[i], y[i]=Y[i];
if(x[i] > 1) fp.insert(i);
upd(i, y[i]);
upd1(i, x[i]);
}
//cout << "SM" << endl;
return slv();
}
int updateX(int pos, int val)
{
if(x[pos] > 1 && pos) fp.erase(pos);
x[pos] = val;
if(x[pos] > 1) fp.insert(pos);
upd1(pos, val);
return slv();
}
int updateY(int pos, int val)
{
y[pos] = val;
upd(pos, val);
return slv();
}
Compilation message (stderr)
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:72:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
72 | int init(int N, int X[], int Y[])
| ~~~~^
horses.cpp:6:11: note: shadowed declaration is here
6 | const int N = 5e5 + 30;
| ^
horses.cpp:84:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
84 | return slv();
| ~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:93:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
93 | return slv();
| ~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:100:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
100 | return slv();
| ~~~^~
# | 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... |