#include "horses.h"
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define F first
#define S second
#define lc id*2+1
#define rc id*2+2
using namespace std;
const ll p=1e9+7;
ll pw(ll a,ll b){
ll ans=1;
while(b){
if(b&1)ans*=a,ans%=p;
b>>=1,a*=a,a%=p;
}
return ans;
}
ll x[500010],y[500010],n;
struct BIT{
ll ori[500010];
void init(){
for(int i=0;i<=n;i++)ori[i]=1;
return;
}
void modify(ll x,int pos){
while(pos<=n){
ori[pos]*=x;
ori[pos]%=p;
pos+=pos&(-pos);
}
return;
}
ll query(ll pos){
ll ans=1;
while(pos){
ans*=ori[pos];
ans%=p;
pos-=pos&(-pos);
}
return ans;
}
}bit;
struct node{
pair<ld,int> val;
ld tag;
node(){
}
};
struct SEG_TREE{
node ori[2000010];
void pull(int l,int r,int id){
if(l==r)return;
ori[id].val=max(ori[lc].val,ori[rc].val);
return;
}
void push(int l,int r,int id){
ori[id].val.F+=ori[id].tag;
if(l!=r){
int m=(l+r)>>1;
ori[lc].tag+=ori[id].tag;
ori[rc].tag+=ori[id].tag;
push(l,m,lc);
push(m+1,r,rc);
pull(l,r,id);
}
ori[id].tag=0;
return;
}
void build(int l,int r,int id){
ori[id].val={0,l};
ori[id].tag=0;
if(l==r){
return;
}
int m=(l+r)>>1;
build(l,m,lc);
build(m+1,r,rc);
return;
}
void modify(int l,int r,int ml,int mr,int id,ld x){
push(l,r,id);
if(l==ml&&r==mr){
ori[id].tag+=x;
push(l,r,id);
return;
}
int m=(l+r)>>1;
if(mr<=m){
modify(l,m,ml,mr,lc,x);
}else if(m<ml){
modify(m+1,r,ml,mr,rc,x);
}else{
modify(l,m,ml,m,lc,x);
modify(m+1,r,m+1,mr,rc,x);
}
return;
}
pair<ld,int> query(int l,int r,int ql,int qr,int id){
push(l,r,id);
if(l==ql&&r==qr){
return ori[id].val;
}
int m=(l+r)>>1;
if(qr<=m){
return query(l,m,ql,qr,lc);
}else if(m<ql){
return query(m+1,r,ql,qr,rc);
}else{
return max(query(l,m,ql,m,lc),query(m+1,r,m+1,qr,rc));
}
}
}seg;
ll q(){
pair<ld,int> ans=seg.query(1,n,1,n,0);
ll a=bit.query(ans.S);
a*=y[ans.S];
a%=p;
return a;
}
int init(int N, int X[], int Y[]) {
n=N;
for(int i=0;i<n;i++){
x[i+1]=X[i];
y[i+1]=Y[i];
}
bit.init();
seg.build(1,n,0);
for(int i=1;i<=n;i++){
seg.modify(1,n,i,n,0,log2l(x[i]));
seg.modify(1,n,i,i,0,log2l(y[i]));
bit.modify(x[i],i);
}
return q();
}
int updateX(int pos, int val) {
pos+=1;
seg.modify(1,n,pos,n,0,log2l(val)-log2l(x[pos]));
bit.modify(pw(x[pos],p-2),pos);
bit.modify(val,pos);
x[pos]=val;
return q();
}
int updateY(int pos, int val) {
pos+=1;
seg.modify(1,n,pos,pos,0,log2l(val)-log2l(y[pos]));
y[pos]=val;
return q();
}
Compilation message
horses.cpp: In member function 'void BIT::modify(long long int, int)':
horses.cpp:26:17: warning: declaration of 'x' shadows a global declaration [-Wshadow]
26 | void modify(ll x,int pos){
| ^
horses.cpp:19:4: note: shadowed declaration is here
19 | ll x[500010],y[500010],n;
| ^
horses.cpp: In member function 'void SEG_TREE::modify(int, int, int, int, int, long double)':
horses.cpp:81:50: warning: declaration of 'x' shadows a global declaration [-Wshadow]
81 | void modify(int l,int r,int ml,int mr,int id,ld x){
| ^
horses.cpp:19:4: note: shadowed declaration is here
19 | ll x[500010],y[500010],n;
| ^
horses.cpp: In function 'long long int q()':
horses.cpp:116:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
116 | pair<ld,int> ans=seg.query(1,n,1,n,0);
| ^
horses.cpp:116:35: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
116 | pair<ld,int> ans=seg.query(1,n,1,n,0);
| ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:132:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
132 | seg.build(1,n,0);
| ^
horses.cpp:134:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
134 | seg.modify(1,n,i,n,0,log2l(x[i]));
| ^
horses.cpp:134:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
134 | seg.modify(1,n,i,n,0,log2l(x[i]));
| ^
horses.cpp:135:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
135 | seg.modify(1,n,i,i,0,log2l(y[i]));
| ^
horses.cpp:138:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
138 | return q();
| ~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:143:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
143 | seg.modify(1,n,pos,n,0,log2l(val)-log2l(x[pos]));
| ^
horses.cpp:143:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
143 | seg.modify(1,n,pos,n,0,log2l(val)-log2l(x[pos]));
| ^
horses.cpp:147:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
147 | return q();
| ~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:152:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
152 | seg.modify(1,n,pos,pos,0,log2l(val)-log2l(y[pos]));
| ^
horses.cpp:154:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
154 | return q();
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
94292 KB |
Output is correct |
2 |
Correct |
49 ms |
94228 KB |
Output is correct |
3 |
Correct |
52 ms |
94148 KB |
Output is correct |
4 |
Correct |
50 ms |
94352 KB |
Output is correct |
5 |
Correct |
47 ms |
94288 KB |
Output is correct |
6 |
Correct |
48 ms |
94292 KB |
Output is correct |
7 |
Correct |
50 ms |
94264 KB |
Output is correct |
8 |
Correct |
49 ms |
94128 KB |
Output is correct |
9 |
Correct |
56 ms |
94268 KB |
Output is correct |
10 |
Correct |
56 ms |
94292 KB |
Output is correct |
11 |
Correct |
48 ms |
94288 KB |
Output is correct |
12 |
Correct |
52 ms |
94288 KB |
Output is correct |
13 |
Correct |
50 ms |
94288 KB |
Output is correct |
14 |
Correct |
47 ms |
94380 KB |
Output is correct |
15 |
Correct |
54 ms |
94292 KB |
Output is correct |
16 |
Correct |
55 ms |
94288 KB |
Output is correct |
17 |
Correct |
61 ms |
94292 KB |
Output is correct |
18 |
Correct |
48 ms |
94292 KB |
Output is correct |
19 |
Correct |
48 ms |
94288 KB |
Output is correct |
20 |
Correct |
56 ms |
94220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
94288 KB |
Output is correct |
2 |
Correct |
60 ms |
94256 KB |
Output is correct |
3 |
Correct |
58 ms |
94272 KB |
Output is correct |
4 |
Correct |
48 ms |
94292 KB |
Output is correct |
5 |
Correct |
49 ms |
94240 KB |
Output is correct |
6 |
Correct |
47 ms |
94288 KB |
Output is correct |
7 |
Correct |
50 ms |
94288 KB |
Output is correct |
8 |
Correct |
59 ms |
94288 KB |
Output is correct |
9 |
Correct |
46 ms |
94292 KB |
Output is correct |
10 |
Correct |
56 ms |
94288 KB |
Output is correct |
11 |
Correct |
51 ms |
94300 KB |
Output is correct |
12 |
Correct |
55 ms |
94288 KB |
Output is correct |
13 |
Correct |
64 ms |
94356 KB |
Output is correct |
14 |
Correct |
48 ms |
94260 KB |
Output is correct |
15 |
Correct |
50 ms |
94336 KB |
Output is correct |
16 |
Correct |
49 ms |
94288 KB |
Output is correct |
17 |
Correct |
53 ms |
94232 KB |
Output is correct |
18 |
Correct |
47 ms |
94292 KB |
Output is correct |
19 |
Correct |
52 ms |
94292 KB |
Output is correct |
20 |
Correct |
48 ms |
94160 KB |
Output is correct |
21 |
Correct |
46 ms |
94288 KB |
Output is correct |
22 |
Correct |
46 ms |
94288 KB |
Output is correct |
23 |
Correct |
294 ms |
94436 KB |
Output is correct |
24 |
Correct |
298 ms |
94288 KB |
Output is correct |
25 |
Correct |
275 ms |
94292 KB |
Output is correct |
26 |
Correct |
308 ms |
94288 KB |
Output is correct |
27 |
Correct |
310 ms |
94288 KB |
Output is correct |
28 |
Correct |
352 ms |
94368 KB |
Output is correct |
29 |
Correct |
328 ms |
94288 KB |
Output is correct |
30 |
Correct |
323 ms |
94288 KB |
Output is correct |
31 |
Correct |
316 ms |
94544 KB |
Output is correct |
32 |
Correct |
309 ms |
94420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1553 ms |
111768 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
94288 KB |
Output is correct |
2 |
Correct |
57 ms |
94348 KB |
Output is correct |
3 |
Correct |
42 ms |
94344 KB |
Output is correct |
4 |
Correct |
55 ms |
94292 KB |
Output is correct |
5 |
Correct |
50 ms |
94372 KB |
Output is correct |
6 |
Correct |
53 ms |
94288 KB |
Output is correct |
7 |
Correct |
54 ms |
94288 KB |
Output is correct |
8 |
Correct |
43 ms |
94292 KB |
Output is correct |
9 |
Correct |
54 ms |
94240 KB |
Output is correct |
10 |
Correct |
42 ms |
94372 KB |
Output is correct |
11 |
Correct |
46 ms |
94292 KB |
Output is correct |
12 |
Correct |
43 ms |
94292 KB |
Output is correct |
13 |
Correct |
46 ms |
94224 KB |
Output is correct |
14 |
Correct |
49 ms |
94292 KB |
Output is correct |
15 |
Correct |
44 ms |
94292 KB |
Output is correct |
16 |
Correct |
44 ms |
94288 KB |
Output is correct |
17 |
Correct |
51 ms |
94288 KB |
Output is correct |
18 |
Correct |
54 ms |
94292 KB |
Output is correct |
19 |
Correct |
43 ms |
94336 KB |
Output is correct |
20 |
Correct |
44 ms |
94292 KB |
Output is correct |
21 |
Correct |
43 ms |
94292 KB |
Output is correct |
22 |
Correct |
45 ms |
94332 KB |
Output is correct |
23 |
Correct |
338 ms |
94432 KB |
Output is correct |
24 |
Correct |
356 ms |
94416 KB |
Output is correct |
25 |
Correct |
312 ms |
94544 KB |
Output is correct |
26 |
Correct |
301 ms |
94428 KB |
Output is correct |
27 |
Correct |
350 ms |
94420 KB |
Output is correct |
28 |
Correct |
309 ms |
94288 KB |
Output is correct |
29 |
Correct |
340 ms |
94528 KB |
Output is correct |
30 |
Correct |
325 ms |
94436 KB |
Output is correct |
31 |
Correct |
329 ms |
94288 KB |
Output is correct |
32 |
Correct |
275 ms |
94412 KB |
Output is correct |
33 |
Execution timed out |
1594 ms |
113232 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
94288 KB |
Output is correct |
2 |
Correct |
47 ms |
94312 KB |
Output is correct |
3 |
Correct |
49 ms |
94288 KB |
Output is correct |
4 |
Correct |
48 ms |
94140 KB |
Output is correct |
5 |
Correct |
50 ms |
94292 KB |
Output is correct |
6 |
Correct |
44 ms |
94288 KB |
Output is correct |
7 |
Correct |
45 ms |
94292 KB |
Output is correct |
8 |
Correct |
47 ms |
94316 KB |
Output is correct |
9 |
Correct |
42 ms |
94288 KB |
Output is correct |
10 |
Correct |
46 ms |
94292 KB |
Output is correct |
11 |
Correct |
44 ms |
94536 KB |
Output is correct |
12 |
Correct |
44 ms |
94288 KB |
Output is correct |
13 |
Correct |
46 ms |
94296 KB |
Output is correct |
14 |
Correct |
45 ms |
94288 KB |
Output is correct |
15 |
Correct |
45 ms |
94368 KB |
Output is correct |
16 |
Correct |
46 ms |
94188 KB |
Output is correct |
17 |
Correct |
48 ms |
94296 KB |
Output is correct |
18 |
Correct |
48 ms |
94288 KB |
Output is correct |
19 |
Correct |
47 ms |
94244 KB |
Output is correct |
20 |
Correct |
46 ms |
94300 KB |
Output is correct |
21 |
Correct |
46 ms |
94224 KB |
Output is correct |
22 |
Correct |
44 ms |
94292 KB |
Output is correct |
23 |
Correct |
291 ms |
94292 KB |
Output is correct |
24 |
Correct |
280 ms |
94436 KB |
Output is correct |
25 |
Correct |
276 ms |
94444 KB |
Output is correct |
26 |
Correct |
290 ms |
94372 KB |
Output is correct |
27 |
Correct |
277 ms |
94292 KB |
Output is correct |
28 |
Correct |
303 ms |
94288 KB |
Output is correct |
29 |
Correct |
291 ms |
94300 KB |
Output is correct |
30 |
Correct |
305 ms |
94560 KB |
Output is correct |
31 |
Correct |
266 ms |
94544 KB |
Output is correct |
32 |
Correct |
275 ms |
94292 KB |
Output is correct |
33 |
Execution timed out |
1551 ms |
111840 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |