# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
649505 |
2022-10-10T10:25:27 Z |
ToroTN |
Horses (IOI15_horses) |
C++14 |
|
409 ms |
29472 KB |
#include<bits/stdc++.h>
using namespace std;
#include "horses.h"
#define ll long long
#define X first
#define Y second
ll n,x[500005],y[500005],md=1e9+7,nw,fight;
ll seg[2000005],val,str,ans,last,mul[2000005],big;
void build(ll tree,ll st,ll ed)
{
ll md=(st+ed)/2;
if(st==ed)
{
seg[tree]=y[ed];
mul[tree]=x[ed];
return;
}
build(2*tree,st,md);
build(2*tree+1,md+1,ed);
seg[tree]=max(seg[2*tree],seg[2*tree+1]);
mul[tree]=1;
if(mul[2*tree]!=0)
{
mul[tree]=(mul[tree]*mul[2*tree]);
mul[tree]%=1000000007;
}
if(mul[2*tree+1]!=0)
{
mul[tree]=(mul[tree]*mul[2*tree+1]);
mul[tree]%=1000000007;
}
}
void update(ll tree,ll st,ll ed,ll idx,ll val)
{
ll md=(st+ed)/2;
if(st==ed)
{
seg[tree]=y[idx];
mul[tree]=x[idx];
return;
}
if(idx<=md)
{
update(2*tree,st,md,idx,val);
}else
{
update(2*tree+1,md+1,ed,idx,val);
}
seg[tree]=max(seg[2*tree],seg[2*tree+1]);
mul[tree]=(mul[2*tree]*mul[2*tree+1])%1000000007;
}
ll query(ll tree,ll st,ll ed,ll l,ll r)
{
ll md=(st+ed)/2;
if(st>r||ed<l)return -1e9;
if(st>=l&&ed<=r)return seg[tree];
return max(query(2*tree,st,md,l,r),query(2*tree+1,md+1,ed,l,r));
}
ll query2(ll tree,ll st,ll ed,ll l,ll r)
{
ll md=(st+ed)/2;
if(st>r||ed<l)return 1;
if(st>=l&&ed<=r)return mul[tree];
return (query2(2*tree,st,md,l,r)*query2(2*tree+1,md+1,ed,l,r))%1000000007;
}
set<ll> s;
stack<pair<ll,ll> > stk;
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];
}
build(1,1,n);
/*printf("%lld\n",mul[1]);
for(int i=1;i<=7;i++)
{
printf("%d %lld\n",i,mul[i]);
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
printf("%d %d %lld\n",i,j,query2(1,1,n,(ll)i,(ll)j));
}
}*/
for(int i=1;i<n;i++)
{
if(x[i]>1)s.insert(i);
if(s.size()>20)s.erase(s.find(*s.begin()));
}
for(auto it=s.begin();it!=s.end();it++)
{
stk.push({*it,query(1,1,n,(*it)+1,n)});
}
nw=n;
str=y[n];
ans=str;
while(!stk.empty())
{
fight=stk.top().X;
val=stk.top().Y;
//printf("%lld %lld\n",fight,val);
stk.pop();
if(str>1e9)
{
str=1e18;
ans*=x[nw];
ans%=md;
}else
{
if(val>str*x[nw])
{
str=val;
ans=val;
}else
{
str*=x[nw];
ans*=x[nw];
ans%=md;
}
}
if(y[fight]>str)
{
str=y[fight];
ans=y[fight];
}
nw=fight;
}
big=query2(1,1,n,1,nw);
//printf("%lld\n",big);
if(str>1e9)
{
str=1e18;
ans*=big;
ans%=md;
return ans;
}else
{
last=seg[1];
if(last>str*big)
{
return last;
}else
{
ans*=big;
ans%=md;
return ans;
}
}
}
int updateX(int pos, int val) {
++pos;
x[pos]=val;
update(1,1,n,pos,val);
if(x[pos]>1)
{
s.insert(pos);
}else
{
s.erase(s.find(pos));
}
if(s.size()>20)s.erase(s.find(*s.begin()));
for(auto it=s.begin();it!=s.end();it++)
{
stk.push({*it,query(1,1,n,(*it)+1,n)});
}
nw=n;
str=y[n];
ans=str;
while(!stk.empty())
{
fight=stk.top().X;
val=stk.top().Y;
//printf("%lld %lld\n",fight,val);
stk.pop();
if(str>1e9)
{
str=1e18;
ans*=x[nw];
ans%=md;
}else
{
if(val>str*x[nw])
{
str=val;
ans=val;
}else
{
str*=x[nw];
ans*=x[nw];
ans%=md;
}
}
if(y[fight]>str)
{
str=y[fight];
ans=y[fight];
}
nw=fight;
}
big=query2(1,1,n,1,nw);
//printf("%lld\n",big);
if(str>1e9)
{
str=1e18;
ans*=big;
ans%=md;
return ans;
}else
{
last=seg[1];
if(last>str*big)
{
return last;
}else
{
ans*=big;
ans%=md;
return ans;
}
}
}
int updateY(int pos, int val) {
++pos;
y[pos]=val;
update(1,1,n,pos,val);
for(auto it=s.begin();it!=s.end();it++)
{
stk.push({*it,query(1,1,n,(*it)+1,n)});
}
nw=n;
str=y[n];
ans=str;
while(!stk.empty())
{
fight=stk.top().X;
val=stk.top().Y;
//printf("%lld %lld\n",fight,val);
stk.pop();
if(str>1e9)
{
str=1e18;
ans*=x[nw];
ans%=md;
}else
{
if(val>str*x[nw])
{
str=val;
ans=val;
}else
{
str*=x[nw];
ans*=x[nw];
ans%=md;
}
}
if(y[fight]>str)
{
str=y[fight];
ans=y[fight];
}
nw=fight;
}
big=query2(1,1,n,1,nw);
//printf("%lld\n",big);
if(str>1e9)
{
str=1e18;
ans*=big;
ans%=md;
return ans;
}else
{
last=seg[1];
if(last>str*big)
{
return last;
}else
{
ans*=big;
ans%=md;
return ans;
}
}
}
Compilation message
horses.cpp: In function 'void build(long long int, long long int, long long int)':
horses.cpp:11:5: warning: declaration of 'md' shadows a global declaration [-Wshadow]
11 | ll md=(st+ed)/2;
| ^~
horses.cpp:7:26: note: shadowed declaration is here
7 | ll n,x[500005],y[500005],md=1e9+7,nw,fight;
| ^~
horses.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:33:43: warning: declaration of 'val' shadows a global declaration [-Wshadow]
33 | void update(ll tree,ll st,ll ed,ll idx,ll val)
| ^
horses.cpp:8:17: note: shadowed declaration is here
8 | ll seg[2000005],val,str,ans,last,mul[2000005],big;
| ^~~
horses.cpp:35:5: warning: declaration of 'md' shadows a global declaration [-Wshadow]
35 | ll md=(st+ed)/2;
| ^~
horses.cpp:7:26: note: shadowed declaration is here
7 | ll n,x[500005],y[500005],md=1e9+7,nw,fight;
| ^~
horses.cpp: In function 'long long int query(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:54:5: warning: declaration of 'md' shadows a global declaration [-Wshadow]
54 | ll md=(st+ed)/2;
| ^~
horses.cpp:7:26: note: shadowed declaration is here
7 | ll n,x[500005],y[500005],md=1e9+7,nw,fight;
| ^~
horses.cpp: In function 'long long int query2(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:61:5: warning: declaration of 'md' shadows a global declaration [-Wshadow]
61 | ll md=(st+ed)/2;
| ^~
horses.cpp:7:26: note: shadowed declaration is here
7 | ll n,x[500005],y[500005],md=1e9+7,nw,fight;
| ^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:106:6: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
106 | if(str>1e9)
| ^~~
horses.cpp:133:5: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
133 | if(str>1e9)
| ^~~
horses.cpp:138:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
138 | return ans;
| ^~~
horses.cpp:144:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
144 | return last;
| ^~~~
horses.cpp:149:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
149 | return ans;
| ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:154:26: warning: declaration of 'val' shadows a global declaration [-Wshadow]
154 | int updateX(int pos, int val) {
| ~~~~^~~
horses.cpp:8:17: note: shadowed declaration is here
8 | ll seg[2000005],val,str,ans,last,mul[2000005],big;
| ^~~
horses.cpp:6:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
6 | #define Y second
| ^
horses.cpp:176:17: note: in expansion of macro 'Y'
176 | val=stk.top().Y;
| ^
horses.cpp:179:6: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
179 | if(str>1e9)
| ^~~
horses.cpp:206:5: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
206 | if(str>1e9)
| ^~~
horses.cpp:211:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
211 | return ans;
| ^~~
horses.cpp:217:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
217 | return last;
| ^~~~
horses.cpp:222:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
222 | return ans;
| ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:227:26: warning: declaration of 'val' shadows a global declaration [-Wshadow]
227 | int updateY(int pos, int val) {
| ~~~~^~~
horses.cpp:8:17: note: shadowed declaration is here
8 | ll seg[2000005],val,str,ans,last,mul[2000005],big;
| ^~~
horses.cpp:6:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
6 | #define Y second
| ^
horses.cpp:241:17: note: in expansion of macro 'Y'
241 | val=stk.top().Y;
| ^
horses.cpp:244:6: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
244 | if(str>1e9)
| ^~~
horses.cpp:271:5: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
271 | if(str>1e9)
| ^~~
horses.cpp:276:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
276 | return ans;
| ^~~
horses.cpp:282:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
282 | return last;
| ^~~~
horses.cpp:287:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
287 | return ans;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 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 |
0 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 |
0 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
21 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
409 ms |
29472 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 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 |
0 ms |
212 KB |
Output is correct |
21 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
21 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
22 |
Halted |
0 ms |
0 KB |
- |