#include <bits/stdc++.h>
#include "horses.h"
#define inf 1000000007
#define mod 1000000007
#define lson (p<<1)
#define rson (p<<1|1)
#define lowbit(x) (x&(-x))
// #define int long long
// #pragma GCC optimize("Ofast","inline","-ffast-math")
// #pragma GCC target("avx,sse2,sse3,sse4,mmx")
using namespace std;
template <typename T> void read(T &x){
x=0;char ch=getchar();int fh=1;
while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
x*=fh;
}
template <typename T> void write(T x) {
if (x<0) x=-x,putchar('-');
if (x>9) write(x/10);
putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
write(x);
puts("");
}
int n,m;
int x[500005],y[500005];
long long bit[500005];
pair<double,int> mx[2000005];
double tag[2000005];
long long qpow(long long a,long long b)
{
long long res=1;
while(b)
{
if(b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
void bitmodify(int x,long long y)
{
while(x<=n)
{
bit[x]*=y;
bit[x]%=mod;
x+=lowbit(x);
}
}
long long bitquery(int x)
{
long long res=1;
while(x)
{
res*=bit[x];
res%=mod;
x-=lowbit(x);
}
return res;
}
void build(int p,int l,int r)
{
if(l==r)
{
mx[p]={0,l};
return;
}
int mid=l+r>>1;
build(lson,l,mid);
build(rson,mid+1,r);
mx[p]=max(mx[lson],mx[rson]);
}
void pushdown(int p)
{
mx[lson].first+=tag[p],tag[lson]+=tag[p];
mx[rson].first+=tag[p],tag[rson]+=tag[p];
tag[p]=0;
}
void modify(int p,int l,int r,int x,int y,double k)
{
if(x<=l&&r<=y)
{
mx[p].first+=k,tag[p]+=k;
return;
}
int mid=l+r>>1;
pushdown(p);
if(x<=mid) modify(lson,l,mid,x,y,k);
if(mid+1<=y) modify(rson,mid+1,r,x,y,k);
mx[p]=max(mx[lson],mx[rson]);
}
int init(int N,int X[],int Y[])
{
n=N;
for(int i=1;i<=n;++i)
{
x[i]=X[i-1];bit[i]=1;
}
for(int i=1;i<=n;++i)
y[i]=Y[i-1];
build(1,1,n);
for(int i=1;i<=n;++i)
{
bitmodify(i,x[i]);
modify(1,1,n,i,n,log(x[i])/log(2));
modify(1,1,n,i,i,log(y[i])/log(2));
}
return (bitquery(mx[1].second)*y[mx[1].second]%mod);
}
int updateX(int pos,int val)
{
++pos;
bitmodify(pos,qpow(x[pos],mod-2));
bitmodify(pos,val);
modify(1,1,n,pos,n,-log(x[pos])/log(2));
modify(1,1,n,pos,n,log(val)/log(2));
x[pos]=val;
return (bitquery(mx[1].second)*y[mx[1].second]%mod);
}
int updateY(int pos,int val)
{
++pos;
modify(1,1,n,pos,pos,-log(y[pos])/log(2));
modify(1,1,n,pos,pos,log(val)/log(2));
y[pos]=val;
return (bitquery(mx[1].second)*y[mx[1].second]%mod);
}
Compilation message
horses.cpp: In function 'void bitmodify(int, long long int)':
horses.cpp:43:32: warning: declaration of 'y' shadows a global declaration [-Wshadow]
43 | void bitmodify(int x,long long y)
| ~~~~~~~~~~^
horses.cpp:28:15: note: shadowed declaration is here
28 | int x[500005],y[500005];
| ^
horses.cpp:43:20: warning: declaration of 'x' shadows a global declaration [-Wshadow]
43 | void bitmodify(int x,long long y)
| ~~~~^
horses.cpp:28:5: note: shadowed declaration is here
28 | int x[500005],y[500005];
| ^
horses.cpp: In function 'long long int bitquery(int)':
horses.cpp:52:24: warning: declaration of 'x' shadows a global declaration [-Wshadow]
52 | long long bitquery(int x)
| ~~~~^
horses.cpp:28:5: note: shadowed declaration is here
28 | int x[500005],y[500005];
| ^
horses.cpp: In function 'void build(int, int, int)':
horses.cpp:70:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
70 | int mid=l+r>>1;
| ~^~
horses.cpp: In function 'void modify(int, int, int, int, int, double)':
horses.cpp:81:41: warning: declaration of 'y' shadows a global declaration [-Wshadow]
81 | void modify(int p,int l,int r,int x,int y,double k)
| ~~~~^
horses.cpp:28:15: note: shadowed declaration is here
28 | int x[500005],y[500005];
| ^
horses.cpp:81:35: warning: declaration of 'x' shadows a global declaration [-Wshadow]
81 | void modify(int p,int l,int r,int x,int y,double k)
| ~~~~^
horses.cpp:28:5: note: shadowed declaration is here
28 | int x[500005],y[500005];
| ^
horses.cpp:88:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
88 | int mid=l+r>>1;
| ~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:110:48: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
110 | return (bitquery(mx[1].second)*y[mx[1].second]%mod);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:120:48: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
120 | return (bitquery(mx[1].second)*y[mx[1].second]%mod);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:128:48: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
128 | return (bitquery(mx[1].second)*y[mx[1].second]%mod);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
308 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
320 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
312 KB |
Output is correct |
30 |
Correct |
2 ms |
316 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
330 ms |
41476 KB |
Output is correct |
2 |
Correct |
439 ms |
50232 KB |
Output is correct |
3 |
Correct |
388 ms |
41568 KB |
Output is correct |
4 |
Correct |
423 ms |
45316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
320 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
3 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
316 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
307 ms |
40676 KB |
Output is correct |
34 |
Correct |
303 ms |
40696 KB |
Output is correct |
35 |
Correct |
318 ms |
47692 KB |
Output is correct |
36 |
Correct |
317 ms |
47476 KB |
Output is correct |
37 |
Correct |
271 ms |
38864 KB |
Output is correct |
38 |
Correct |
308 ms |
39664 KB |
Output is correct |
39 |
Correct |
279 ms |
38656 KB |
Output is correct |
40 |
Correct |
301 ms |
42576 KB |
Output is correct |
41 |
Correct |
284 ms |
38812 KB |
Output is correct |
42 |
Correct |
281 ms |
38864 KB |
Output is correct |
43 |
Correct |
286 ms |
42952 KB |
Output is correct |
44 |
Correct |
294 ms |
43028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
1 ms |
304 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
304 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
324 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
360 ms |
41512 KB |
Output is correct |
34 |
Correct |
449 ms |
50204 KB |
Output is correct |
35 |
Correct |
382 ms |
41376 KB |
Output is correct |
36 |
Correct |
437 ms |
45176 KB |
Output is correct |
37 |
Correct |
303 ms |
40652 KB |
Output is correct |
38 |
Correct |
313 ms |
40708 KB |
Output is correct |
39 |
Correct |
370 ms |
47588 KB |
Output is correct |
40 |
Correct |
317 ms |
47540 KB |
Output is correct |
41 |
Correct |
269 ms |
38816 KB |
Output is correct |
42 |
Correct |
288 ms |
39832 KB |
Output is correct |
43 |
Correct |
283 ms |
38648 KB |
Output is correct |
44 |
Correct |
292 ms |
42692 KB |
Output is correct |
45 |
Correct |
266 ms |
38752 KB |
Output is correct |
46 |
Correct |
273 ms |
38760 KB |
Output is correct |
47 |
Correct |
281 ms |
43088 KB |
Output is correct |
48 |
Correct |
282 ms |
42936 KB |
Output is correct |
49 |
Correct |
406 ms |
42628 KB |
Output is correct |
50 |
Correct |
400 ms |
42728 KB |
Output is correct |
51 |
Correct |
392 ms |
49404 KB |
Output is correct |
52 |
Correct |
399 ms |
48972 KB |
Output is correct |
53 |
Correct |
381 ms |
40952 KB |
Output is correct |
54 |
Correct |
370 ms |
41520 KB |
Output is correct |
55 |
Correct |
346 ms |
39940 KB |
Output is correct |
56 |
Correct |
368 ms |
44576 KB |
Output is correct |
57 |
Correct |
327 ms |
40396 KB |
Output is correct |
58 |
Correct |
342 ms |
40880 KB |
Output is correct |
59 |
Correct |
277 ms |
42944 KB |
Output is correct |