# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
621251 |
2022-08-03T15:39:34 Z |
A_D |
Horses (IOI15_horses) |
C++14 |
|
1500 ms |
46460 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+100;
const long long MOD=1e9+7;
const long long L=32;
long long x[N];
long long y[N];
set<int> st;
long long sum=1;
int n;
vector<int> vec;
long long seg[4*N];
long long po(long long b,long long p)
{
if(p==0)return 1;
if(p==1)return b;
if(p%2){
return (b*po(b,p-1))%MOD;
}
long long r=po(b,p/2);
return (r*r)%MOD;
}
long long modinv(int v)
{
return po(v,MOD-2);
}
void build(int p,int s,int e)
{
if(s==e){
seg[p]=y[s];
return;
}
int mid=(s+e)/2;
build(p*2,s,mid);
build(p*2+1,mid+1,e);
seg[p]=max(seg[p*2],seg[p*2+1]);
}
void update(int p,int s,int e,int i,int val)
{
if(s==e){
seg[p]=val;
return;
}
int mid=(s+e)/2;
if(i<=mid){
update(p*2,s,mid,i,val);
}
else{
update(p*2+1,mid+1,e,i,val);
}
seg[p]=max(seg[p*2],seg[p*2+1]);
}
long long get(int p,int s,int e,int a,int b)
{
if(a<=s&&e<=b){
return seg[p];
}
if(s>b||e<a)return 0;
int mid=(s+e)/2;
return max(get(p*2,s,mid,a,b),get(p*2+1,mid+1,e,a,b));
}
void filvec()
{
vec.clear();
int cnt=0;
for(auto x:st){
vec.push_back(-x);
cnt++;
if(cnt==L)continue;
}
reverse(vec.begin(),vec.end());
}
long long getansst()
{
filvec();
long long ret=seg[1];
long long sum=1,sum2=1,val=seg[1];
for(auto i:vec){
sum*=x[i];
sum%=MOD;
sum2*=x[i];
long long u=sum2*get(1,0,n-1,i,n-1);
if(u>val){
sum2=1;
ret=sum*get(1,0,n-1,i,n-1);
val=y[i];
}
}
ret%=MOD;
return ret;
}
int init(int N, int X[], int Y[]){
st.clear();
n=N;
for(int i=0;i<N;i++){
x[i]=X[i];
y[i]=Y[i];
if(x[i]!=1){
st.insert(-i);
}
}
build(1,0,n-1);
filvec();
if(vec.empty()){
sum=1;
return seg[1];
}
else{
int h=vec[0];
for(int i=0;i<h;i++){
sum*=x[i];
sum%=MOD;
}
long long u=getansst();
u*=sum;
u%=MOD;
return (int)u;
}
}
int updateX(int pos, int val) {
filvec();
int sz=vec.size();
if(x[pos]!=1){
st.erase(-pos);
}
if(val!=1){
st.insert(-pos);
}
if(st.size()<=L){
filvec();
x[pos]=val;
sum=1;
long long u=getansst();
return (int)u;
}
else{
int h=vec[0];
if(pos<h){
sum*=modinv(x[pos]);
sum%=MOD;
x[pos]=val;
sum*=x[pos];
sum%=MOD;
}
else{
if(val!=1){
st.erase(-pos);
}
if(x[pos]!=1){
st.insert(-pos);
}
if(x[pos]!=1){
if(val!=1){
x[pos]=val;
}
else{
int cnt=0;
int u;
for(auto x:st){
cnt++;
u=x;
if(cnt==L+1)break;
}
u*=-1;
st.erase(-pos);
sum*=modinv(x[u]);
sum%=MOD;
x[pos]=val;
}
}
else{
filvec();
if(val!=1){
x[pos]=val;
st.insert(-pos);
sum*=x[vec[0]];
sum%=MOD;
}
else{
x[pos]=val;
}
}
}
}
filvec();
long long u=getansst();
u*=sum;
u%=MOD;
return (int)u;
}
int updateY(int pos, int val) {
update(1,0,n-1,pos,val);
filvec();
long long u=getansst();
u*=sum;
u%=MOD;
return (int)u;
}
Compilation message
horses.cpp: In function 'void filvec()':
horses.cpp:79:14: warning: declaration of 'x' shadows a global declaration [-Wshadow]
79 | for(auto x:st){
| ^
horses.cpp:10:11: note: shadowed declaration is here
10 | long long x[N];
| ^
horses.cpp: In function 'long long int getansst()':
horses.cpp:90:15: warning: declaration of 'sum' shadows a global declaration [-Wshadow]
90 | long long sum=1,sum2=1,val=seg[1];
| ^~~
horses.cpp:13:11: note: shadowed declaration is here
13 | long long sum=1;
| ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:106:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
106 | int init(int N, int X[], int Y[]){
| ~~~~^
horses.cpp:7:11: note: shadowed declaration is here
7 | const int N=1e6+100;
| ^
horses.cpp:123:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
123 | return seg[1];
| ~~~~~^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:144:20: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
144 | int sz=vec.size();
| ~~~~~~~~^~
horses.cpp:161:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
161 | sum*=modinv(x[pos]);
| ~~~~~^
horses.cpp:187:30: warning: declaration of 'x' shadows a global declaration [-Wshadow]
187 | for(auto x:st){
| ^
horses.cpp:10:11: note: shadowed declaration is here
10 | long long x[N];
| ^
horses.cpp:194:36: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
194 | sum*=modinv(x[u]);
| ~~~^
horses.cpp:144:9: warning: unused variable 'sz' [-Wunused-variable]
144 | int sz=vec.size();
| ^~
horses.cpp:192:22: warning: 'u' may be used uninitialized in this function [-Wmaybe-uninitialized]
192 | u*=-1;
| ~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1592 ms |
46460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
312 KB |
Output is correct |
19 |
Correct |
0 ms |
316 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |