#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define f first
#define s second
#define pi pair<ll,ll>
#define vi vector<ll>
#define vd vector<double>
#define vpi vector<pi>
#define pb push_back
#define INF 1e18
#define endl '\n'
//#define int ll
#define pii pair<pi,ll>
const int mod = 1e9+7;
vd x, y;
vi ox, oy;
const int MAX = 500000;
int n;
struct dt {
double sum, pref;
ll mulx,ans;
};
dt t[MAX*4];
dt make_data(int i){
dt a;
a.sum = x[i];
a.mulx = ox[i];
a.pref = x[i] + y[i];
a.ans = (ox[i]*oy[i])%mod;
return a;
}
dt combine(dt a, dt b){
dt hold;
hold.sum = a.sum+ b.sum;
hold.mulx = ((a.mulx % mod) * (b.mulx % mod))%mod;
if(a.pref > a.sum+b.pref){
hold.pref = a.pref;
hold.ans = a.ans;
}
else{
hold.pref = a.sum+ b.pref;
hold.ans = a.mulx * b.ans;
}
return hold;
}
void build(int v,int l,int r){
if(l==r){
t[v] = make_data(l);
return;
}
int m = (l+r)/2;
build(v*2,l,m);
build(v*2+1,m+1,r);
t[v] = combine(t[v*2],t[v*2+1]);
}
int initialize(int N, int a[], int b[]){
n = N;
x.resize(n+1);
y.resize(n+1);
ox.resize(n+1);
oy.resize(n+1);
x[0]=0;
y[0]=0;
for(int i =1 ; i <= n; i++){
ox[i] = a[i-1];
oy[i] = b[i-1];
x[i] =log10(ox[i]);
y[i] = log10(oy[i]);
}
build(1,1,n);
return t[1].ans;
}
void update(int v, int l,int r, int pos){
if(l==r){
t[v]= make_data(l);
return;
}
int m = (l+r)/2;
if(pos<=m) update(v*2,l,m,pos);
else update(v*2+1,m+1,r,pos);
t[v] = combine(t[v*2],t[v*2+1]);
}
int updateX(int pos,int val){
pos ++;
x[pos] = log10(val);
ox[pos]= val;
update(1,1,n,pos);
return t[1].ans;
}
int updateY(int pos,int val){
pos++;
y[pos] = log10(val);
oy[pos] = val;
update(1,1,n,pos);
return t[1].ans;
}
signed main(){
int n,m;
cin >> n;
int a[n];
int b[n];
for(int i =0 ; i < n; i++){
cin >> a[i];
}
for(int i =0 ; i < n; i++){
cin >> b[i];
}
cout <<initialize(n,a,b)<< endl;
cin >> m;
int type, g,h;
while(m--){
cin >> type >> g >> h;
if(type==1) cout << updateX(g,h) << endl;
else cout << updateY(g,h) << endl;
}
}
Compilation message
horses.cpp: In function 'int initialize(int, int*, int*)':
horses.cpp:84:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
84 | return t[1].ans;
| ~~~~~^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:108:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
108 | return t[1].ans;
| ~~~~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:116:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
116 | return t[1].ans;
| ~~~~~^~~
horses.cpp: In function 'int main()':
horses.cpp:123:8: warning: declaration of 'n' shadows a global declaration [-Wshadow]
123 | int n,m;
| ^
horses.cpp:20:5: note: shadowed declaration is here
20 | int n;
| ^
/usr/bin/ld: /tmp/ccgu9Re7.o: in function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'; /tmp/ccjjhuF6.o:horses.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccgu9Re7.o: in function `main':
grader.c:(.text.startup+0xaa): undefined reference to `init(int, int*, int*)'
collect2: error: ld returned 1 exit status