# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
731331 |
2023-04-27T10:19:33 Z |
lucri |
말 (IOI15_horses) |
C++17 |
|
1243 ms |
38600 KB |
#include "horses.h"
#include <bits/stdc++.h>
#define MOD 1000000007
long long aintx[2000010],x[500010];
long long ainty[2000010],y[500010];
long long aintprod[2000010],n;
void initializeaintx(int poz,int b,int e)
{
if(b==e)
{
aintx[poz]=(x[b]!=1);
return;
}
initializeaintx(poz*2,b,(b+e)/2);
initializeaintx(poz*2+1,(b+e)/2+1,e);
aintx[poz]=(aintx[poz*2]|aintx[poz*2+1]);
}
void updateaintx(int poz,int b,int e,int pozm,int val)
{
if(e<pozm||b>pozm)
return;
if(b==e)
{
aintx[poz]=(x[b]!=1);
return;
}
updateaintx(poz*2,b,(b+e)/2,pozm,val);
updateaintx(poz*2+1,(b+e)/2+1,e,pozm,val);
aintx[poz]=(aintx[poz*2]|aintx[poz*2+1]);
}
void initializeainty(int poz,int b,int e)
{
if(b==e)
{
ainty[poz]=y[b];
return;
}
initializeainty(poz*2,b,(b+e)/2);
initializeainty(poz*2+1,(b+e)/2+1,e);
ainty[poz]=std::max(ainty[poz*2],ainty[poz*2+1]);
}
void updateainty(int poz,int b,int e,int pozm,int val)
{
if(e<pozm||b>pozm)
return;
if(b==e)
{
ainty[poz]=y[b];
return;
}
updateainty(poz*2,b,(b+e)/2,pozm,val);
updateainty(poz*2+1,(b+e)/2+1,e,pozm,val);
ainty[poz]=std::max(ainty[poz*2],ainty[poz*2+1]);
}
void initializeaintprod(int poz,int b,int e)
{
if(b==e)
{
aintprod[poz]=x[b];
return;
}
initializeaintprod(poz*2,b,(b+e)/2);
initializeaintprod(poz*2+1,(b+e)/2+1,e);
aintprod[poz]=aintprod[poz*2]*aintprod[poz*2+1]%MOD;
}
void updateaintprod(int poz,int b,int e,int pozm,int val)
{
if(e<pozm||b>pozm)
return;
if(b==e)
{
aintprod[poz]=x[b];
return;
}
updateaintprod(poz*2,b,(b+e)/2,pozm,val);
updateaintprod(poz*2+1,(b+e)/2+1,e,pozm,val);
ainty[poz]=aintprod[poz*2]*aintprod[poz*2+1]%MOD;
}
long long difde0(int poz,int b,int e,int ei)
{
if(b>=ei)
return 0;
if(aintx[poz]==0)
return 0;
if(b==e)
return b;
int poza=difde0(poz*2+1,(b+e)/2+1,e,ei);
if(poza)
return poza;
return difde0(poz*2,b,(b+e)/2,ei);
}
long long maxim(int poz,int b,int e,int bi,int ei)
{
if(b>ei||e<bi)
return 0;
if(bi<=b&&e<=ei)
return ainty[poz];
return std::max(maxim(poz*2,b,(b+e)/2,bi,ei),maxim(poz*2+1,(b+e)/2+1,e,bi,ei));
}
long long produs(int poz,int b,int e,int bi,int ei)
{
if(b>ei||e<bi)
return 1;
if(bi<=b&&e<=ei)
return aintprod[poz];
return produs(poz*2,b,(b+e)/2,bi,ei)*produs(poz*2+1,(b+e)/2+1,e,bi,ei)%MOD;
}
long long calculeaza()
{
long long prod=x[n]*y[n],pozant=n;
while(prod<1000000000&&pozant)
{
int pozac=pozant-1;
pozant=difde0(1,1,n,pozant);
long long vmax=maxim(1,1,n,pozant,pozac-1);
if(vmax>prod)
prod=vmax;
prod*=x[pozant];
}
prod%=MOD;
return prod*produs(1,1,n,1,pozant-1);
}
int init(int N, int X[], int Y[])
{
n=N;
for(int i=1;i<=N;++i)
{
x[i]=X[i-1];
y[i]=Y[i-1];
}
initializeaintx(1,1,N);
initializeainty(1,1,N);
initializeaintprod(1,1,N);
return calculeaza();
}
int updateX(int pos, int val)
{
++pos;
x[pos]=val;
updateaintx(1,1,n,pos,val);
updateaintprod(1,1,n,pos,val);
calculeaza();
return calculeaza();
}
int updateY(int pos, int val)
{
++pos;
y[pos]=val;
updateainty(1,1,n,pos,val);
calculeaza();
return calculeaza();
}
Compilation message
horses.cpp: In function 'long long int difde0(int, int, int, int)':
horses.cpp:91:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
91 | int poza=difde0(poz*2+1,(b+e)/2+1,e,ei);
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'long long int calculeaza()':
horses.cpp:119:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
119 | int pozac=pozant-1;
| ~~~~~~^~
horses.cpp:120:27: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
120 | pozant=difde0(1,1,n,pozant);
| ^
horses.cpp:120:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
120 | pozant=difde0(1,1,n,pozant);
| ^~~~~~
horses.cpp:121:34: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
121 | long long vmax=maxim(1,1,n,pozant,pozac-1);
| ^
horses.cpp:121:36: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
121 | long long vmax=maxim(1,1,n,pozant,pozac-1);
| ^~~~~~
horses.cpp:127:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
127 | return prod*produs(1,1,n,1,pozant-1);
| ^
horses.cpp:127:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
127 | return prod*produs(1,1,n,1,pozant-1);
| ~~~~~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:141:22: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
141 | return calculeaza();
| ~~~~~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:148:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
148 | updateaintx(1,1,n,pos,val);
| ^
horses.cpp:149:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
149 | updateaintprod(1,1,n,pos,val);
| ^
horses.cpp:151:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
151 | return calculeaza();
| ~~~~~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:158:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
158 | updateainty(1,1,n,pos,val);
| ^
horses.cpp:160:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
160 | return calculeaza();
| ~~~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1243 ms |
38600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |