#include <bits/stdc++.h>
#include "horses.h"
#define MAX 1000001
#define INF LLONG_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define gett(x,m) get<m>(x)
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define sorta(a,sz) sort(a,a+sz)
#define inputar(a,b){\
for(int i=0;i<b;i++){\
cin >> a[i];\
}\
}
#define inputvec(a,b){\
for(int i=0;i<b;i++){\
ll num;\
cin >> num;\
a.pb(num);\
}\
}
#define outputar(a,b){\
for(int i=0;i<b;i++){\
cout << a[i] << " ";\
}\
cout << "\n";\
}
#define outputvec(a){\
for(auto x:a){\
cout << x << " ";\
}\
cout << "\n";\
}
#define reset(a,n,v){\
for(int i=0;i<n;i++){\
a[i]=v;\
}\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
int n;
vector<ll> X1,Y1;
struct segtree_mul{
int size;
vector<ll> muls;
void build(vector<ll> &a,int x,int lx,int rx){
if(rx-lx==1){
if(lx<(int)a.size()){
muls[x]=a[lx];
}
return;
}
int m=(lx+rx)/2;
build(a,2*x+1,lx,m);
build(a,2*x+2,m,rx);
muls[x]=muls[2*x+1]*muls[2*x+2];
muls[x]%=MOD;
}
void build(vector<ll> &a){
build(a,0,0,size);
}
void init(int n){
size=1;
while(size<n){
size*=2;
}
muls.assign(2*size,1);
}
ll mul(int l,int r,int x,int lx,int rx){
if(lx>=r || rx<=l){
return 1;
}
if(lx>=l && rx<=r){
return muls[x];
}
ll s1,s2;
int m=(lx+rx)/2;
s1=mul(l,r,2*x+1,lx,m);
s2=mul(l,r,2*x+2,m,rx);
return (s1*s2)%MOD;
}
ll mul(int l,int r){
return mul(l,r,0,0,size);
}
void set(int i,int v,int x,int lx,int rx){
if(rx-lx==1){
muls[x]=v;
return;
}
int m=(lx+rx)/2;
if(i<m){
set(i,v,2*x+1,lx,m);
}
else{
set(i,v,2*x+2,m,rx);
}
muls[x]=muls[2*x+1]*muls[2*x+2];
muls[x]%=MOD;
}
void set(int i,int v){
set(i,v,0,0,size);
}
};
struct segtree_max{
int size;
vector<pll> maxs;
void build(vector<ll> &a,int x,int lx,int rx){
if(rx-lx==1){
if(lx<(int)a.size()){
maxs[x]=mp(a[lx],lx);
}
return;
}
int m=(lx+rx)/2;
build(a,2*x+1,lx,m);
build(a,2*x+2,m,rx);
maxs[x]=max(maxs[2*x+1],maxs[2*x+2]);
}
void build(vector<ll> &a){
build(a,0,0,size);
}
void init(int n){
size=1;
while(size<n){
size*=2;
}
maxs.assign(2*size,mp(0,0));
}
pll get_max(int l,int r,int x,int lx,int rx){
if(lx>=r || rx<=l){
return mp(0,0);
}
if(lx>=l && rx<=r){
return maxs[x];
}
pll s1,s2;
int m=(lx+rx)/2;
s1=get_max(l,r,2*x+1,lx,m);
s2=get_max(l,r,2*x+2,m,rx);
return max(s1,s2);
}
pll get_max(int l,int r){
return get_max(l,r,0,0,size);
}
void set(int i,int v,int x,int lx,int rx){
if(rx-lx==1){
maxs[x]=mp(v,i);
return;
}
int m=(lx+rx)/2;
if(i<m){
set(i,v,2*x+1,lx,m);
}
else{
set(i,v,2*x+2,m,rx);
}
maxs[x]=max(maxs[2*x+1],maxs[2*x+2]);
}
void set(int i,int v){
set(i,v,0,0,size);
}
};
segtree_mul st_mul;
segtree_max st_max;
set<ll> b;
int init(int N, int X[], int Y[]) {
n=N;
X1.resize(n);
Y1.resize(n);
b.ins(-1);
for(int i=0;i<N;i++){
if(X[i]!=1){
b.ins(i);
}
X1[i]=X[i];
Y1[i]=Y[i];
}
st_mul.init(n);
st_mul.build(X1);
st_max.init(n);
st_max.build(Y1);
ll h=n-1;
ll cnt=0;
vector<ll> a;
while(h>=0){
if(X1[h]==1){
auto it=b.upper_bound(h);
--it;
pll p=st_max.get_max(*it+1,h+1);
h=p.ss;
}
a.pb(h);
h--;
cnt++;
if(cnt==60){
break;
}
}
reverse(all(a));
ll sz=(ll)a.size();
ll h1=1;
ll ind=0;
for(int i=1;i<sz;i++){
if(h1>MOD/X1[a[i]]){
h1=MOD;
}
else{
h1*=X1[a[i]];
}
if(h1>Y1[a[ind]]/Y1[a[i]]){
ind=i;
h1=1;
}
}
ll res1=st_mul.mul(0,a[ind]+1)*Y1[a[ind]];
res1%=MOD;
return res1;
}
int updateX(int pos, int val) {
st_mul.set(pos,val);
if(X1[pos]==1 && val!=1){
b.ins(pos);
}
else if(val==1){
b.erase(pos);
}
X1[pos]=val;
ll h=n-1;
ll cnt=0;
vector<ll> a;
while(h>=0){
if(X1[h]==1){
auto it=b.upper_bound(h);
--it;
pll p=st_max.get_max(*it+1,h+1);
h=p.ss;
}
a.pb(h);
h--;
cnt++;
if(cnt==60){
break;
}
}
reverse(all(a));
ll sz=(ll)a.size();
ll h1=1;
ll ind=0;
for(int i=1;i<sz;i++){
if(h1>MOD/X1[a[i]]){
h1=MOD;
}
else{
h1*=X1[a[i]];
}
if(h1>Y1[a[ind]]/Y1[a[i]]){
ind=i;
h1=1;
}
}
ll res1=st_mul.mul(0,a[ind]+1)*Y1[a[ind]];
res1%=MOD;
return res1;
}
int updateY(int pos, int val){
st_max.set(pos,val);
Y1[pos]=val;
ll h=n-1;
ll cnt=0;
vector<ll> a;
while(h>=0){
if(X1[h]==1){
auto it=b.upper_bound(h);
--it;
pll p=st_max.get_max(*it+1,h+1);
h=p.ss;
}
a.pb(h);
h--;
cnt++;
if(cnt==60){
break;
}
}
reverse(all(a));
ll sz=(ll)a.size();
ll h1=1;
ll ind=0;
for(int i=1;i<sz;i++){
if(h1>MOD/X1[a[i]]){
h1=MOD;
}
else{
h1*=X1[a[i]];
}
if(h1>Y1[a[ind]]/Y1[a[i]]){
ind=i;
h1=1;
}
}
ll res1=st_mul.mul(0,a[ind]+1)*Y1[a[ind]];
res1%=MOD;
return res1;
}
/*
int X[MAX],Y[MAX],m,x,y,z;
int main(){
cin >> n;
for(int i=0;i<n;i++){
cin >> X[i];
}
for(int i=0;i<n;i++){
cin >> Y[i];
}
cout << init(n,X,Y) << "\n";
cin >> m;
for(int i=0;i<m;i++){
cin >> x >> y >> z;
if(x==1){
cout << updateX(y,z) << "\n";
}
else{
cout << updateY(y,z) << "\n";
}
}
}
*/
Compilation message
horses.cpp: In member function 'void segtree_mul::init(int)':
horses.cpp:76:19: warning: declaration of 'n' shadows a global declaration [-Wshadow]
76 | void init(int n){
| ~~~~^
horses.cpp:55:5: note: shadowed declaration is here
55 | int n;
| ^
horses.cpp: In member function 'void segtree_max::init(int)':
horses.cpp:136:19: warning: declaration of 'n' shadows a global declaration [-Wshadow]
136 | void init(int n){
| ~~~~^
horses.cpp:55:5: note: shadowed declaration is here
55 | int n;
| ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:203:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
203 | pll p=st_max.get_max(*it+1,h+1);
| ~~~^~
horses.cpp:203:32: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
203 | pll p=st_max.get_max(*it+1,h+1);
| ~^~
horses.cpp:229:29: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
229 | ll res1=st_mul.mul(0,a[ind]+1)*Y1[a[ind]];
horses.cpp:231:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
231 | return res1;
| ^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:249:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
249 | pll p=st_max.get_max(*it+1,h+1);
| ~~~^~
horses.cpp:249:32: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
249 | pll p=st_max.get_max(*it+1,h+1);
| ~^~
horses.cpp:275:29: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
275 | ll res1=st_mul.mul(0,a[ind]+1)*Y1[a[ind]];
horses.cpp:277:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
277 | return res1;
| ^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:290:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
290 | pll p=st_max.get_max(*it+1,h+1);
| ~~~^~
horses.cpp:290:32: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
290 | pll p=st_max.get_max(*it+1,h+1);
| ~^~
horses.cpp:316:29: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
316 | ll res1=st_mul.mul(0,a[ind]+1)*Y1[a[ind]];
horses.cpp:318:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
318 | return res1;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
5 ms |
520 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Incorrect |
5 ms |
348 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
251 ms |
61268 KB |
Output is correct |
2 |
Correct |
273 ms |
61264 KB |
Output is correct |
3 |
Correct |
284 ms |
61064 KB |
Output is correct |
4 |
Correct |
286 ms |
61264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
5 ms |
520 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
344 KB |
Output is correct |
27 |
Incorrect |
5 ms |
348 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
352 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
352 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
5 ms |
516 KB |
Output is correct |
24 |
Correct |
2 ms |
524 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Incorrect |
5 ms |
348 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |