# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1107629 |
2024-11-01T18:36:43 Z |
Aviansh |
Horses (IOI15_horses) |
C++17 |
|
85 ms |
25928 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
int n;
int *x;
int *y;
int mod = 1e9+7;
template <class T> class segTree{
private:
int n;
T *st;
public:
void realMakeST(int *arr, int l, int r, int ind){
if(l==r){
st[ind]=arr[l];
}
else{
int mid = (l+r)/2;
realMakeST(arr,l,mid,ind*2+1);
realMakeST(arr,mid+1,r,ind*2+2);
st[ind]=st[ind*2+1]*st[ind*2+2];
st[ind]%=mod;
}
}
segTree(){
//aise hi
}
segTree(int *arr, int siz){
int x = (int)pow(2,ceil(log2(siz)));
n=siz-1;
x*=2;
st=new T[x];
realMakeST(arr,0,n,0);
}
void realUpdate(int l, int r, int ind, int pos, int val){
if(pos<l||pos>r){
return;
}
if(l==r){
st[ind]=val;
return;
}
int mid = (l+r)/2;
realUpdate(l,mid,2*ind+1,pos,val);
realUpdate(mid+1,r,2*ind+2,pos,val);
st[ind]=st[ind*2+1]*st[ind*2+2];
st[ind]%=mod;
}
void update(int ind, int val){
realUpdate(0,n,0,ind,val);
}
T realQuery(int l, int r, int s, int e, int ind){
if(e<l||s>r){
return 1;
}
if(s<=l&&r<=e){
return st[ind];
}
int mid = (l+r)/2;
return (realQuery(l,mid,s,e,2*ind+1)*realQuery(mid+1,r,s,e,2*ind+2))%mod;
}
T query(int s,int e){
return realQuery(0,n,s,e,0);
}
};
int t = 1;
int *temp = &t;
segTree<long long> st(temp,1);
int finans(){
if(n<=1000){
int mx = 0;
long long curr = 1;
for(int i = 0;i<n;i++){
curr*=x[i];
if(curr>y[mx]){
mx=i;
curr=1;
continue;
}
else if(curr*y[i]>y[mx]){
mx=i;
curr=1;
continue;
}
}
long long ans = 1;
for(int i = 0;i<=mx;i++){
ans*=x[i];
ans%=mod;
}
ans*=y[mx];
ans%=mod;
return ans;
}
int mx = max(n-50,0);
long long curr = 1;
for(int i = max(n-50,0);i<n;i++){
curr*=x[i];
if(curr>y[mx]){
curr=1;
mx=i;
}
else if(curr*y[i]>y[mx]){
mx=i;
curr=1;
}
}
return (st.query(0,mx)*y[mx])%mod;
}
int init(int N, int X[], int Y[]) {
x=X;
y=Y;
n=N;
st = segTree<long long>(x,n);
return finans();
}
int updateX(int pos, int val) {
x[pos]=val;
st.update(pos,val);
return finans();
}
int updateY(int pos, int val) {
y[pos]=val;
return finans();
}
Compilation message
horses.cpp: In constructor 'segTree<T>::segTree(int*, int)':
horses.cpp:31:17: warning: declaration of 'x' shadows a global declaration [-Wshadow]
31 | int x = (int)pow(2,ceil(log2(siz)));
| ^
horses.cpp:6:6: note: shadowed declaration is here
6 | int *x;
| ^
horses.cpp: In function 'int finans()':
horses.cpp:99:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
99 | return ans;
| ^~~
horses.cpp:114:34: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
114 | return (st.query(0,mx)*y[mx])%mod;
| ~~~~~~~~~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
508 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
504 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
0 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
8 ms |
336 KB |
Output is correct |
24 |
Correct |
8 ms |
336 KB |
Output is correct |
25 |
Correct |
9 ms |
468 KB |
Output is correct |
26 |
Correct |
9 ms |
336 KB |
Output is correct |
27 |
Correct |
8 ms |
336 KB |
Output is correct |
28 |
Correct |
8 ms |
336 KB |
Output is correct |
29 |
Correct |
7 ms |
476 KB |
Output is correct |
30 |
Correct |
7 ms |
336 KB |
Output is correct |
31 |
Correct |
5 ms |
336 KB |
Output is correct |
32 |
Correct |
6 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
13384 KB |
Output is correct |
2 |
Correct |
84 ms |
13384 KB |
Output is correct |
3 |
Correct |
66 ms |
13316 KB |
Output is correct |
4 |
Correct |
77 ms |
13384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
0 ms |
336 KB |
Output is correct |
23 |
Correct |
8 ms |
336 KB |
Output is correct |
24 |
Correct |
8 ms |
336 KB |
Output is correct |
25 |
Correct |
9 ms |
336 KB |
Output is correct |
26 |
Correct |
9 ms |
336 KB |
Output is correct |
27 |
Correct |
7 ms |
336 KB |
Output is correct |
28 |
Correct |
8 ms |
336 KB |
Output is correct |
29 |
Correct |
6 ms |
336 KB |
Output is correct |
30 |
Correct |
7 ms |
336 KB |
Output is correct |
31 |
Correct |
5 ms |
336 KB |
Output is correct |
32 |
Correct |
6 ms |
336 KB |
Output is correct |
33 |
Incorrect |
29 ms |
14924 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
424 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
8 ms |
336 KB |
Output is correct |
24 |
Correct |
8 ms |
336 KB |
Output is correct |
25 |
Correct |
9 ms |
336 KB |
Output is correct |
26 |
Correct |
9 ms |
500 KB |
Output is correct |
27 |
Correct |
7 ms |
336 KB |
Output is correct |
28 |
Correct |
8 ms |
336 KB |
Output is correct |
29 |
Correct |
6 ms |
472 KB |
Output is correct |
30 |
Correct |
7 ms |
336 KB |
Output is correct |
31 |
Correct |
5 ms |
336 KB |
Output is correct |
32 |
Correct |
6 ms |
336 KB |
Output is correct |
33 |
Correct |
52 ms |
15116 KB |
Output is correct |
34 |
Correct |
84 ms |
25928 KB |
Output is correct |
35 |
Correct |
47 ms |
17224 KB |
Output is correct |
36 |
Correct |
85 ms |
21064 KB |
Output is correct |
37 |
Incorrect |
30 ms |
16504 KB |
Output isn't correct |
38 |
Halted |
0 ms |
0 KB |
- |