#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef long double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
const ll mod2=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
ll mul(ll a, ll b) {
return a*b%mod;
}
const int N=501000;
int n;
db a[N],b[N],ps[N];
ll pp[N];
struct node {
db mx,lzy;
ll f,lzyp;
}nd[4*N];
void upd(int p) {
if (nd[p+p].mx>nd[p+p+1].mx) {
nd[p].mx=nd[p+p].mx;
nd[p].f=nd[p+p].f;
} else {
nd[p].mx=nd[p+p+1].mx;
nd[p].f=nd[p+p+1].f;
}
}
void push(int p) {
nd[p].mx+=nd[p].lzy;
nd[p].f=mul(nd[p].f,nd[p].lzyp);
nd[p+p].lzy+=nd[p].lzy;
nd[p+p+1].lzy+=nd[p].lzy;
nd[p+p].lzyp=mul(nd[p+p].lzyp,nd[p].lzyp);
nd[p+p+1].lzyp=mul(nd[p+p+1].lzyp,nd[p].lzyp);
nd[p].lzy=0;
nd[p].lzyp=1;
}
void build(int p,int l,int r) {
nd[p].lzyp=1;
if (l==r) {
nd[p].mx=ps[l]+log10l(b[l]);
nd[p].f=mul(pp[l],b[l]);
return;
}
int md=l+r>>1;
build(p+p,l,md);
build(p+p+1,md+1,r);
upd(p);
}
void modify(int p,int l,int r,int ql,int qr,db x,ll y) {
push(p);
if (l>qr||r<ql) return;
if (ql<=l&&r<=qr) {
nd[p].lzy+=x;
nd[p].lzyp=mul(nd[p].lzyp,y);
push(p);
return;
}
int md=l+r>>1;
modify(p+p,l,md,ql,qr,x,y);
modify(p+p+1,md+1,r,ql,qr,x,y);
upd(p);
}
int init(int N,int* x,int* y) {
n=N;
ps[0]=0; pp[0]=1;
rep(i,1,n+1) ps[i]=ps[i-1]+log10l(x[i-1]);
rep(i,1,n+1) pp[i]=mul(pp[i-1],x[i-1]);
rep(i,1,n+1) a[i]=x[i-1],b[i]=y[i-1];
build(1,1,n);
return nd[1].f;
}
int updateX(int pos,int val) {
++pos;
modify(1,1,n,pos,n,log10l(val)-log10l(a[pos]),mul(val,powmod(a[pos],mod-2)));
a[pos]=val;
return nd[1].f;
}
int updateY(int pos,int val) {
++pos;
modify(1,1,n,pos,pos,log10l(val)-log10l(b[pos]),mul(val,powmod(b[pos],mod-2)));
b[pos]=val;
return nd[1].f;
}
Compilation message
horses.cpp: In function 'int rnd(int)':
horses.cpp:18:33: warning: conversion from 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
18 | int rnd(int x) { return mrand() % x;}
| ~~~~~~~~^~~
horses.cpp: In function 'void build(int, int, int)':
horses.cpp:62:24: warning: conversion from 'db' {aka 'long double'} to 'll' {aka 'long long int'} may change value [-Wfloat-conversion]
62 | nd[p].f=mul(pp[l],b[l]);
| ~~~^
horses.cpp:65:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
65 | int md=l+r>>1;
| ~^~
horses.cpp: In function 'void modify(int, int, int, int, int, db, ll)':
horses.cpp:80:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
80 | int md=l+r>>1;
| ~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:86:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
86 | int init(int N,int* x,int* y) {
| ~~~~^
horses.cpp:27:11: note: shadowed declaration is here
27 | const int N=501000;
| ^
horses.cpp:93:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
93 | return nd[1].f;
| ~~~~~~^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:98:68: warning: conversion from 'db' {aka 'long double'} to 'll' {aka 'long long int'} may change value [-Wfloat-conversion]
98 | modify(1,1,n,pos,n,log10l(val)-log10l(a[pos]),mul(val,powmod(a[pos],mod-2)));
| ~~~~~^
horses.cpp:100:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
100 | return nd[1].f;
| ~~~~~~^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:105:70: warning: conversion from 'db' {aka 'long double'} to 'll' {aka 'long long int'} may change value [-Wfloat-conversion]
105 | modify(1,1,n,pos,pos,log10l(val)-log10l(b[pos]),mul(val,powmod(b[pos],mod-2)));
| ~~~~~^
horses.cpp:107:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
107 | return nd[1].f;
| ~~~~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
588 KB |
Output is correct |
24 |
Correct |
2 ms |
588 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
2 ms |
588 KB |
Output is correct |
28 |
Correct |
2 ms |
580 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
588 KB |
Output is correct |
31 |
Correct |
2 ms |
588 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
280 ms |
81912 KB |
Output is correct |
2 |
Correct |
420 ms |
126528 KB |
Output is correct |
3 |
Correct |
405 ms |
130364 KB |
Output is correct |
4 |
Correct |
411 ms |
133372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
588 KB |
Output is correct |
24 |
Correct |
2 ms |
580 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
2 ms |
588 KB |
Output is correct |
28 |
Correct |
2 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
588 KB |
Output is correct |
31 |
Correct |
2 ms |
588 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
33 |
Correct |
201 ms |
105272 KB |
Output is correct |
34 |
Correct |
202 ms |
105216 KB |
Output is correct |
35 |
Correct |
192 ms |
91928 KB |
Output is correct |
36 |
Correct |
190 ms |
91716 KB |
Output is correct |
37 |
Correct |
189 ms |
103412 KB |
Output is correct |
38 |
Correct |
169 ms |
84420 KB |
Output is correct |
39 |
Correct |
166 ms |
82868 KB |
Output is correct |
40 |
Correct |
180 ms |
87364 KB |
Output is correct |
41 |
Correct |
166 ms |
83120 KB |
Output is correct |
42 |
Correct |
167 ms |
83012 KB |
Output is correct |
43 |
Correct |
164 ms |
87172 KB |
Output is correct |
44 |
Correct |
163 ms |
87236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
312 KB |
Output is correct |
23 |
Correct |
2 ms |
588 KB |
Output is correct |
24 |
Correct |
2 ms |
588 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
448 KB |
Output is correct |
27 |
Correct |
2 ms |
588 KB |
Output is correct |
28 |
Correct |
2 ms |
588 KB |
Output is correct |
29 |
Correct |
2 ms |
448 KB |
Output is correct |
30 |
Correct |
2 ms |
588 KB |
Output is correct |
31 |
Correct |
2 ms |
588 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
33 |
Correct |
276 ms |
85676 KB |
Output is correct |
34 |
Correct |
417 ms |
139196 KB |
Output is correct |
35 |
Correct |
395 ms |
130372 KB |
Output is correct |
36 |
Correct |
419 ms |
133572 KB |
Output is correct |
37 |
Correct |
199 ms |
105220 KB |
Output is correct |
38 |
Correct |
195 ms |
105108 KB |
Output is correct |
39 |
Correct |
188 ms |
91868 KB |
Output is correct |
40 |
Correct |
184 ms |
91700 KB |
Output is correct |
41 |
Correct |
186 ms |
103472 KB |
Output is correct |
42 |
Correct |
173 ms |
84600 KB |
Output is correct |
43 |
Correct |
166 ms |
82980 KB |
Output is correct |
44 |
Correct |
178 ms |
87368 KB |
Output is correct |
45 |
Correct |
171 ms |
83140 KB |
Output is correct |
46 |
Correct |
167 ms |
82948 KB |
Output is correct |
47 |
Correct |
161 ms |
87152 KB |
Output is correct |
48 |
Correct |
160 ms |
87176 KB |
Output is correct |
49 |
Correct |
413 ms |
131828 KB |
Output is correct |
50 |
Correct |
410 ms |
131580 KB |
Output is correct |
51 |
Correct |
306 ms |
93756 KB |
Output is correct |
52 |
Correct |
310 ms |
93148 KB |
Output is correct |
53 |
Correct |
405 ms |
129860 KB |
Output is correct |
54 |
Correct |
305 ms |
91204 KB |
Output is correct |
55 |
Correct |
283 ms |
84004 KB |
Output is correct |
56 |
Correct |
313 ms |
94152 KB |
Output is correct |
57 |
Correct |
287 ms |
84784 KB |
Output is correct |
58 |
Correct |
287 ms |
85156 KB |
Output is correct |
59 |
Correct |
161 ms |
87200 KB |
Output is correct |