# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
421167 |
2021-06-08T19:48:05 Z |
Pbezz |
Horses (IOI15_horses) |
C++14 |
|
1500 ms |
29888 KB |
#include "horses.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
typedef pair<ll,ll> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const ll MAXN=5e5+5;
const ll MOD=1e9+7;
int x[MAXN],y[MAXN],mini,n;
ll seg[4*MAXN];
//seg[node].second = 1 se ja ultrapassou 1e9+7
void recalculate(ll node){
ll res = seg[2*node+1]*seg[2*node+2];
res%=MOD;
seg[node] = res;
}
void build(ll node, ll left, ll right){
if(left==right){
seg[node] = (ll)x[left];
}else{
ll middle=(left+right)/2;
build(2*node+1,left,middle);
build(2*node+2,middle+1,right);
recalculate(node);
}
}
void update(ll node, ll left, ll right, ll pos, ll val){
if(left==right){
seg[node]=val;
}else{
ll middle = (left+right)/2;
if(pos<=middle)update(2*node+1,left,middle,pos,val);
if(pos>=middle+1)update(2*node+2,middle+1,right,pos,val);
recalculate(node);
}
}
ll querie(ll node, ll left, ll right, ll a, ll b){
if(a<=left&&b>=right){
return seg[node];
}else{
ll middle=(left+right)/2,res=1;
if(a<=middle)res*=querie(2*node+1,left,middle,a,b);
res%=MOD;
if(b>=middle+1)res*=querie(2*node+2,middle+1,right,a,b);
res%=MOD;
if(res<0)res+=MOD;
return res;
}
}
int init(int N, int X[], int Y[]){
ll i,j=N;
mini=MOD+10; n=N;
for(i=0;i<N;i++){
x[i+1] = X[i];
y[i+1] = Y[i];
mini = min(mini,X[i]);
}
build(0,1,N);
ll cur=(ll)x[n];
for(i=N-1;i>=1;i--){
if(cur>=MOD)break;
if(y[i]>cur*y[j]){
j=i; cur = x[j];
}else{
cur*=x[i];
}
}
ll ans = querie(0,1,N,1,j);
ans*=y[j];
ans%=MOD;
if(ans<0)ans+=MOD;
return ans;
}
int updateX(int pos, int val){
mini=min(mini,val);
//if(mini>=2){
//e otimal ir ate um dos ultimos 30 dias
//}
update(0,1,n,pos+1,val);
x[pos+1]=val;
ll i,j=n,cur=(ll)x[n];
for(i=n-1;i>=1;i--){
if(cur>=MOD)break;
if(y[i]>cur*y[j]){
j=i; cur = x[j];
}else{
cur*=x[i];
}
}
ll ans = querie(0,1,n,1,j);
ans*=y[j];
ans%=MOD;
if(ans<0)ans+=MOD;
return ans;
}
int updateY(int pos, int val) {
y[pos+1]=val;
ll i,j=n,cur=(ll)x[n];
for(i=n-1;i>=1;i--){
if(cur>=MOD)break;
if(y[i]>cur*y[j]){
j=i; cur = x[j];
}else{
cur*=x[i];
}
}
ll ans = querie(0,1,n,1,j);
ans*=y[j];
ans%=MOD;
if(ans<0)ans+=MOD;
return ans;
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:110:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
110 | return ans;
| ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:144:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
144 | return ans;
| ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:170:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
170 | return ans;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
0 ms |
296 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
296 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
296 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
316 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
3 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
18756 KB |
Output is correct |
2 |
Correct |
113 ms |
29888 KB |
Output is correct |
3 |
Correct |
74 ms |
20988 KB |
Output is correct |
4 |
Correct |
110 ms |
24940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
300 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
308 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
3 ms |
332 KB |
Output is correct |
33 |
Correct |
96 ms |
20348 KB |
Output is correct |
34 |
Correct |
37 ms |
20300 KB |
Output is correct |
35 |
Correct |
71 ms |
27232 KB |
Output is correct |
36 |
Correct |
64 ms |
27204 KB |
Output is correct |
37 |
Correct |
346 ms |
18560 KB |
Output is correct |
38 |
Correct |
36 ms |
19328 KB |
Output is correct |
39 |
Execution timed out |
1567 ms |
18392 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
308 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
80 ms |
21060 KB |
Output is correct |
34 |
Correct |
115 ms |
29772 KB |
Output is correct |
35 |
Correct |
84 ms |
20984 KB |
Output is correct |
36 |
Correct |
119 ms |
24840 KB |
Output is correct |
37 |
Correct |
86 ms |
20264 KB |
Output is correct |
38 |
Correct |
38 ms |
20308 KB |
Output is correct |
39 |
Correct |
66 ms |
27232 KB |
Output is correct |
40 |
Correct |
64 ms |
27240 KB |
Output is correct |
41 |
Correct |
345 ms |
18516 KB |
Output is correct |
42 |
Correct |
34 ms |
19344 KB |
Output is correct |
43 |
Execution timed out |
1581 ms |
18380 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |