This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*input
3
2 1 3
3 4 1
1
2 1 2
*/
#include "horses.h"
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const ll INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-6;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll sub(ll a,ll b){
ll x=a-b;
while(x<0) x+=MOD;
while(x>MOD) x-=MOD;
return x;
}
ll mult(ll a,ll b){
return (a*b)%MOD;
}
ll mypow(ll a,ll b){
if(b<=0) return 1;
ll res=1LL;
while(b){
if(b&1) res=(res*a)%MOD;
a=(a*a)%MOD;
b>>=1;
}
return res;
}
const int maxn=5e5+5;
const ll maxlg=__lg(maxn)+2;
int val[4*maxn],md[4*maxn];
inline void mdf(int idx,int l,int r,int p,int x){
if(l==r){
val[idx]=md[idx]=x;
return;
}
int mid=(l+r)>>1;
if(p<=mid){
mdf(idx<<1,l,mid,p,x);
}
else{
mdf(idx<<1|1,mid+1,r,p,x);
}
val[idx]=min((ll)INF,(ll)val[idx<<1]*val[idx<<1|1]);
md[idx]=mult(md[idx<<1],md[idx<<1|1]);
}
inline int qv(int idx,int l,int r,int ql,int qr){
if(ql>qr) return 1;
if(ql<=l and r<=qr) return val[idx];
int mid=(l+r)>>1;
if(qr<=mid) return qv(idx<<1,l,mid,ql,qr);
if(ql>mid) return qv(idx<<1|1,mid+1,r,ql,qr);
return min((ll)INF,(ll)qv(idx<<1,l,mid,ql,qr)*qv(idx<<1|1,mid+1,r,ql,qr));
}
inline int qm(int idx,int l,int r,int ql,int qr){
if(ql>qr) return 1;
if(ql<=l and r<=qr) return md[idx];
int mid=(l+r)>>1;
if(qr<=mid) return qm(idx<<1,l,mid,ql,qr);
if(ql>mid) return qm(idx<<1|1,mid+1,r,ql,qr);
return mult(qm(idx<<1,l,mid,ql,qr),qm(idx<<1|1,mid+1,r,ql,qr));
}
int opt[4*maxn];
int y[maxn],n;
void build(int idx,int l,int r){
if(l==r){
opt[idx]=l;
return;
}
int mid=(l+r)>>1;
build(idx<<1,l,mid);
build(idx<<1|1,mid+1,r);
}
void upd(int idx,int l,int r,int p){
if(l==r){
return;
}
int mid=(l+r)>>1;
if(p<=mid){
upd(idx<<1,l,mid,p);
}
else{
upd(idx<<1|1,mid+1,r,p);
}
if(y[opt[idx<<1|1]]*(ll)qv(1,0,n-1,opt[idx<<1]+1,opt[idx<<1|1])>=y[opt[idx<<1]]) opt[idx]=opt[idx<<1|1];
else opt[idx]=opt[idx<<1];
}
int init(int N, int X[], int Y[]) {
n=N;
REP(i,n) mdf(1,0,n-1,i,X[i]);
build(1,0,n-1);
REP(i,n) y[i]=Y[i],upd(1,0,n-1,i);
return mult(y[opt[1]],qm(1,0,n-1,0,opt[1]));
}
int updateX(int pos, int val) {
mdf(1,0,n-1,pos,val);
upd(1,0,n-1,pos);
return mult(y[opt[1]],qm(1,0,n-1,0,opt[1]));
}
int updateY(int pos, int val) {
y[pos]=val;
upd(1,0,n-1,pos);
return mult(y[opt[1]],qm(1,0,n-1,0,opt[1]));
}
Compilation message (stderr)
horses.cpp: In function 'void mdf(int, int, int, int, int)':
horses.cpp:72:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
72 | val[idx]=min((ll)INF,(ll)val[idx<<1]*val[idx<<1|1]);
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:73:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
73 | md[idx]=mult(md[idx<<1],md[idx<<1|1]);
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int qv(int, int, int, int, int)':
horses.cpp:81:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
81 | return min((ll)INF,(ll)qv(idx<<1,l,mid,ql,qr)*qv(idx<<1|1,mid+1,r,ql,qr));
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int qm(int, int, int, int, int)':
horses.cpp:89:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
89 | return mult(qm(idx<<1,l,mid,ql,qr),qm(idx<<1|1,mid+1,r,ql,qr));
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:121:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
121 | return mult(y[opt[1]],qm(1,0,n-1,0,opt[1]));
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:124:26: warning: declaration of 'val' shadows a global declaration [-Wshadow]
124 | int updateX(int pos, int val) {
| ~~~~^~~
horses.cpp:59:5: note: shadowed declaration is here
59 | int val[4*maxn],md[4*maxn];
| ^~~
horses.cpp:127:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
127 | return mult(y[opt[1]],qm(1,0,n-1,0,opt[1]));
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:130:26: warning: declaration of 'val' shadows a global declaration [-Wshadow]
130 | int updateY(int pos, int val) {
| ~~~~^~~
horses.cpp:59:5: note: shadowed declaration is here
59 | int val[4*maxn],md[4*maxn];
| ^~~
horses.cpp:133:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
133 | return mult(y[opt[1]],qm(1,0,n-1,0,opt[1]));
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |