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>
using namespace std;
typedef long long ll;
const int MAXN = 5e5 + 10;
const ll MOD = 1e9 + 7;
#define esq(x) x << 1
#define dir(x) (x<<1) | 1
#define mid(x,y,t) ((x+y)>>1) + t
ll Y[MAXN], X[MAXN];
int n;
struct nodeseg
{
ll v, id, xm;
bool flag;
nodeseg(ll _v = 0, ll _id = 0, ll _xm = 0, bool f = 0){
v = _v;
id = _id;
xm = _xm;
flag = f;
}
nodeseg operator + (nodeseg b){
if(flag && b.flag) return nodeseg(0,0,0,1);
if(flag) return b;
if(b.flag) return *this;
nodeseg ans;
if(v >= b.v){
ans.id = id;
ans.v = v;
}else{
ans.id = b.id;
ans.v = b.v;
}
ans.xm = (xm * b.xm)%MOD;
return ans;
}
}seg[4*MAXN];
void build(int node, int x, int y){
if(x == y){
seg[node] = nodeseg(Y[x], x, X[x], 0);
return;
}
build(esq(node), x, mid(x,y,0));
build(dir(node), mid(x,y,1), y);
seg[node] = seg[esq(node)] + seg[dir(node)];
}
void update(int node, int x, int y, int id, int t){
if(x > id || y < id ) return;
if(x == y){
seg[node].v = Y[x];
seg[node].xm = X[x];
return;
}
update(esq(node), x, mid(x,y,0), id, t);
update(dir(node), mid(x,y,1), y, id, t);
seg[node] = seg[esq(node)] + seg[dir(node)];
}
nodeseg query(int node, int x, int y, int l, int r){
if(x > r || y < l ) return nodeseg(0,0,1,1);
if(x >= l && y <= r) return seg[node];
nodeseg e = query(esq(node), x, mid(x,y,0), l, r);
nodeseg d = query(dir(node), mid(x,y,1), y, l, r);
return e + d;
}
set<int> ids;
ll makeans(){
set<int> :: iterator it = ids.end();
it--;
ll ans = 0, id = 0;
int r = n;
while(true){
//printf("%d %d\n", r, *it);
nodeseg q = query(1,1,n,*it,r);
if(q.v >= ans) ans = q.v, id = q.id;
ans *= X[*it];
r = *it -1;
//printf("%d %d\n", r, *it);
if(it == ids.begin()) break;
if(ans > (ll) 1e9) break;
it--;
}
//printf("%d\n", r);
if(it == ids.begin() &&r >0 ){
nodeseg q = query(1,1,n,1,r);
if(q.v >= ans) ans = q.v, id = q.id;
}
return (query(1,1,n,1,id).xm*Y[id])%MOD;
}
int init(int N, int x[], int y[]) {
n = N;
for(int i = 0; i < N; i++){
X[i+1] = x[i];
Y[i+1] = y[i];
}
build(1,1,n);
for(int i = 1; i <= n; i++) if(X[i] >= 2) ids.insert(i);
return makeans();
}
int updateX(int pos, int val) {
pos++;
ids.erase(pos);
X[pos] = val;
if(X[pos] >= 2) ids.insert(pos);
update(1,1,n,pos,1);
return makeans();
}
int updateY(int pos, int val) {
pos++;
Y[pos] = val;
update(1,1,n,pos,0);
return makeans();
}
Compilation message (stderr)
horses.cpp: In function 'll makeans()':
horses.cpp:101:24: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
101 | return (query(1,1,n,1,id).xm*Y[id])%MOD;
| ^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:114:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
114 | return makeans();
| ~~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:124:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
124 | return makeans();
| ~~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:131:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
131 | return makeans();
| ~~~~~~~^~
# | 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... |