# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
705346 |
2023-03-04T04:41:17 Z |
bin9638 |
Horses (IOI15_horses) |
C++17 |
|
800 ms |
45944 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fs first
#define sc second
#define N 500010
#define pb push_back
#define ii pair<ll,ll>
const ll mod=1e9+7;
struct IT
{
ll ST[N*4]={};
void update(int id,int l,int r,int i,int val)
{
if(l>i||r<i)
return;
if(l==r)
{
ST[id]=val;
return;
}
int mid=(l+r)/2;
update(id*2,l,mid,i,val);
update(id*2+1,mid+1,r,i,val);
ST[id]=max(ST[id*2],ST[id*2+1]);
}
ll get(int id,int l,int r,int u,int v)
{
if(l>v||r<u)
return 0;
if(l>=u&&r<=v)
return ST[id];
int mid=(l+r)/2;
return max(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v));
}
}IT_X,IT_Y;
ll bit[N];
int n;
ll x[N],y[N];
ll mu(ll x,ll y)
{
x%=mod;
ll res=1;
for(;y>0;y>>=1,x=x*x%mod)
if(y&1)
res=res*x%mod;
return res;
}
void updatebit(int u,ll val)
{
for(;u<=n;u+=u&(-u))
bit[u]=bit[u]*val%mod;
}
ll getbit(int u)
{
ll res=1;
for(;u>0;u-=u&(-u))
res=res*bit[u]%mod;
return res;
}
ll solve()
{
ll res=getbit(n)*y[n]%mod,S=x[n];
ii ps={y[n],1};
int vt=n;
while(vt>1)
{
int cc=max(1ll,IT_X.get(1,1,n,1,vt-1));
//cc->vt-1
ii p={IT_Y.get(1,1,n,max(cc,1),vt-1),S};
// cout<<cc<<" "<<vt<<" "<<p.fs<<endl;
if(p.fs*ps.sc>ps.fs*p.sc)
{
// cout<<"cc\n";
ps=p;
res=p.fs*getbit(vt-1)%mod;
}
S*=x[cc];
if(S>=2e9)
break;
vt=cc;
}
return res%mod;
}
ll updateX(int pos, int val)
{
pos++;
updatebit(pos,mu(x[pos],mod-2));
x[pos]=val;
updatebit(pos,val);
IT_X.update(1,1,n,pos,pos*(val!=1));
return solve();
}
ll updateY(int pos, int val)
{
pos++;
y[pos]=val;
IT_Y.update(1,1,n,pos,val);
return solve();
}
ll init(int cc,int X[],int Y[])
{
n=cc;
//cout<<n<<endl;
for(int i=1;i<=n;i++)
{
x[i]=X[i-1];
y[i]=Y[i-1];
bit[i]=1;
// cout<<x[i]<<" "<<y[i]<<endl;
}
for(int i=1;i<=n;i++)
{
if(x[i]!=1)
IT_X.update(1,1,n,i,i);
IT_Y.update(1,1,n,i,y[i]);
updatebit(i,x[i]);
}
return solve();
}
#ifdef SKY
int main()
{
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
int n;
cin>>n;
int x[n],y[n];
for(int i=0;i<n;i++)
cin>>x[i];
for(int i=0;i<n;i++)
cin>>y[i];
cout<<init(n,x,y)<<endl;
int q;
cin>>q;
while(q--)
{
int type,pos,val;
cin>>type>>pos>>val;
if(type==1)
cout<<updateX(pos,val)<<endl;
else cout<<updateY(pos,val)<<endl;
}
return 0;
}
#endif // SKY
Compilation message
horses.cpp: In function 'long long int mu(long long int, long long int)':
horses.cpp:48:15: warning: declaration of 'y' shadows a global declaration [-Wshadow]
48 | ll mu(ll x,ll y)
| ^
horses.cpp:46:9: note: shadowed declaration is here
46 | ll x[N],y[N];
| ^
horses.cpp:48:10: warning: declaration of 'x' shadows a global declaration [-Wshadow]
48 | ll mu(ll x,ll y)
| ^
horses.cpp:46:4: note: shadowed declaration is here
46 | ll x[N],y[N];
| ^
horses.cpp: In function 'long long int solve()':
horses.cpp:79:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
79 | int cc=max(1ll,IT_X.get(1,1,n,1,vt-1));
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:90:12: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
90 | if(S>=2e9)
| ^
horses.cpp: In function 'long long int init(int, int*, int*)':
horses.cpp:130:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
130 | IT_Y.update(1,1,n,i,y[i]);
| ~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
328 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
324 KB |
Output is correct |
27 |
Correct |
4 ms |
320 KB |
Output is correct |
28 |
Correct |
3 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
324 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
800 ms |
33540 KB |
Output is correct |
2 |
Correct |
256 ms |
45900 KB |
Output is correct |
3 |
Correct |
290 ms |
37208 KB |
Output is correct |
4 |
Correct |
339 ms |
40896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
424 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
452 KB |
Output is correct |
26 |
Correct |
2 ms |
344 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
324 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
104 ms |
36400 KB |
Output is correct |
34 |
Correct |
102 ms |
36368 KB |
Output is correct |
35 |
Correct |
184 ms |
43444 KB |
Output is correct |
36 |
Correct |
184 ms |
43176 KB |
Output is correct |
37 |
Correct |
144 ms |
30440 KB |
Output is correct |
38 |
Correct |
141 ms |
35456 KB |
Output is correct |
39 |
Correct |
106 ms |
26388 KB |
Output is correct |
40 |
Correct |
176 ms |
38344 KB |
Output is correct |
41 |
Correct |
122 ms |
26944 KB |
Output is correct |
42 |
Correct |
156 ms |
26384 KB |
Output is correct |
43 |
Correct |
154 ms |
38656 KB |
Output is correct |
44 |
Correct |
161 ms |
38656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
316 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
2 ms |
428 KB |
Output is correct |
31 |
Correct |
4 ms |
328 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
717 ms |
37136 KB |
Output is correct |
34 |
Correct |
279 ms |
45944 KB |
Output is correct |
35 |
Correct |
271 ms |
37244 KB |
Output is correct |
36 |
Correct |
341 ms |
41008 KB |
Output is correct |
37 |
Correct |
106 ms |
36396 KB |
Output is correct |
38 |
Correct |
102 ms |
36280 KB |
Output is correct |
39 |
Correct |
206 ms |
43272 KB |
Output is correct |
40 |
Correct |
177 ms |
43332 KB |
Output is correct |
41 |
Correct |
146 ms |
30480 KB |
Output is correct |
42 |
Correct |
152 ms |
35444 KB |
Output is correct |
43 |
Correct |
105 ms |
26372 KB |
Output is correct |
44 |
Correct |
158 ms |
38376 KB |
Output is correct |
45 |
Correct |
121 ms |
26916 KB |
Output is correct |
46 |
Correct |
147 ms |
26440 KB |
Output is correct |
47 |
Correct |
172 ms |
38724 KB |
Output is correct |
48 |
Correct |
152 ms |
38712 KB |
Output is correct |
49 |
Correct |
230 ms |
38420 KB |
Output is correct |
50 |
Correct |
182 ms |
38396 KB |
Output is correct |
51 |
Correct |
362 ms |
45156 KB |
Output is correct |
52 |
Correct |
228 ms |
44716 KB |
Output is correct |
53 |
Correct |
719 ms |
32632 KB |
Output is correct |
54 |
Correct |
357 ms |
37304 KB |
Output is correct |
55 |
Correct |
191 ms |
27532 KB |
Output is correct |
56 |
Correct |
274 ms |
40148 KB |
Output is correct |
57 |
Correct |
457 ms |
28592 KB |
Output is correct |
58 |
Correct |
686 ms |
28448 KB |
Output is correct |
59 |
Correct |
154 ms |
38768 KB |
Output is correct |