This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* [Author : Hoang Duy Vu] - THPT Chuyen Nguyen Du */
//#pragma GCC optimize(" unroll-loops")
//#pragma gcc optimize("Ofast")
//#pragma GCC optimization("Ofast")
//#pragma optimize(Ofast)
#include "horses.h"
#include <bits/stdc++.h>
#define All(x) (x).begin(),(x).end()
#define ll long long
#define C make_pair
#define fi first
#define se second
#define two second.first
#define thr second.second
#define TASK "txt"
#define ld long double
using namespace std;
template<typename T> bool maximize(T &res, const T &val) {
if (res < val) { res = val; return true; } return false; }
template<typename T> bool minimize(T &res, const T &val) {
if (res > val) { res = val; return true; } return false; }
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
const int LOG = 20;
const ll INF = 1e9;
const ll LNF = 1e18 + 7;
const ll mod = 1e9 + 7;
const int N = 5e5 + 100;
struct SegmentTree
{
vector <ll> f;
int n;
SegmentTree(int _n = 0)
{
n = _n;
f.assign(n*4,1);
}
void update(int i , int l , int r , int x , ll val)
{
if (l > x || r < x) return ;
if (l == r)
{
f[i] = val;
return ;
}
int m = (l + r) >> 1;
update(i*2,l,m,x,val);
update(i*2+1,m+1,r,x,val);
f[i] = (f[i*2]*f[i*2+1]) % mod;
}
ll get(int i , int l , int r , int c)
{
if (c < l) return 1;
if (r <= c) return f[i];
int m = (l + r) >> 1;
return (get(i*2,l,m,c)*get(i*2+1,m+1,r,c)) % mod;
}
};
struct SegmentTree2
{
vector <ll> f;
int n;
SegmentTree2(int _n = 0)
{
n = _n;
f.assign(n*4,0);
}
void update(int i , int l , int r , int x , ll val)
{
if (l > x || r < x) return ;
if (l == r)
{
f[i] = val;
return ;
}
int m = (l + r) >> 1;
update(i*2,l,m,x,val);
update(i*2+1,m+1,r,x,val);
f[i] = max(f[i*2],f[i*2+1]);
}
ll get(int i , int l , int r , int d , int c)
{
if (c < l || d > r || d > c) return 0;
if (d <= l && r <= c) return f[i];
int m = (l + r) >> 1;
return max(get(i*2,l,m,d,c),get(i*2+1,m+1,r,d,c));
}
};
SegmentTree2 Mx = 0;
SegmentTree IT = 0;
ll w[N] , val[N];
int n;
set <int> p;
ll calc() {
auto l = p.end();
l--;
l--;
auto r = l;
r++;
ll res = 0;
// cout << (*l) << " " << (*r) << "\n";
while (true)
{
int d = (*l) + 1;
int c = (*r) - 1;
if (d <= c)
{
ll gt = Mx.get(1,1,n,d,c);
maximize(res,gt);
}
if (d == 1) break;
maximize(res,val[(*l)]);
res = res * w[(*l)];
if (res >= 1e9)
{
res = res % mod;
res = (res * IT.get(1,1,n,(*l) - 1)) % mod;
return res;
}
l--;
r--;
}
return res;
}
int init(int Nx, int X[], int Y[]) {
n = Nx;
p.insert(0);
p.insert(n + 1);
IT = n;
Mx = n;
for (int i = 1 ; i <= n ; i++)
{
w[i] = X[i - 1], val[i] = Y[i - 1];
if (w[i] > 1) p.insert(i);
IT.update(1,1,n,i,w[i]);
Mx.update(1,1,n,i,val[i]);
}
return calc();
}
int updateX(int pos, int gt) {
pos++;
if (w[pos] == gt) return calc();
IT.update(1,1,n,pos,gt);
if (w[pos] == 1) p.insert(pos);
else if (gt == 1) p.erase(pos);
w[pos] = gt;
return calc();
}
int updateY(int pos, int gt) {
pos++;
Mx.update(1,1,n,pos,gt);
val[pos] = gt;
return calc();
}
// int main()
// {
// ios_base::sync_with_stdio(0);
// cin.tie(NULL); cout.tie(NULL);
// if(fopen(TASK".inp", "r")){
// freopen(TASK".inp","r",stdin);
// freopen(TASK".out","w",stdout);
// }
// int x[N] , y[N];
// int t;
// cin >> t;
// for (int i = 0 ; i < t ; i++) cin >> x[i] >> y[i];
// cout << init(t,x,y) << "\n";
// int q;
// cin >> q;
// while (q--)
// {
// int id , g , h;
// cin >> id >> g >> h;
// if (id == 1) cout << updateX(g,h) << "\n";
// else cout << updateY(g,h) << "\n";
// }
// return 0;
// }
Compilation message (stderr)
horses.cpp: In function 'long long int calc()':
horses.cpp:140:13: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
140 | if (res >= 1e9)
| ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:169:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
169 | return calc();
| ~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:174:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
174 | if (w[pos] == gt) return calc();
| ~~~~^~
horses.cpp:179:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
179 | return calc();
| ~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:186:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
186 | return calc();
| ~~~~^~
# | 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... |