# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
986370 |
2024-05-20T11:22:48 Z |
Pyqe |
Horses (IOI15_horses) |
C++17 |
|
617 ms |
72576 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
int n,ma=1e9,a[500069],wg[500069],fw[2][500069],fi,pwk,dv=1e9+7,inf=1e9;
struct segtree
{
int l,r,mx;
segtree *p[2];
void bd(int lh,int rh)
{
l=lh;
r=rh;
if(l==r)
{
mx=wg[l];
}
else
{
int ii,md=(l+r)/2;
for(ii=0;ii<2;ii++)
{
p[ii]=new segtree;
p[ii]->bd(!ii?l:md+1,!ii?md:r);
}
mx=max(p[0]->mx,p[1]->mx);
}
}
void ud(int x,int w)
{
if(l>x||r<x);
else if(l>=x&&r<=x)
{
mx=w;
}
else
{
int ii;
for(ii=0;ii<2;ii++)
{
p[ii]->ud(x,w);
}
mx=max(p[0]->mx,p[1]->mx);
}
}
int qr(int lh,int rh)
{
if(l>rh||r<lh)
{
return -inf;
}
else if(l>=lh&&r<=rh)
{
return mx;
}
else
{
return max(p[0]->qr(lh,rh),p[1]->qr(lh,rh));
}
}
}
sg;
int pw(int x,int y)
{
if(!y)
{
return 1;
}
pwk=pw(x,y/2);
pwk=(long long)pwk*pwk%dv;
if(y%2)
{
pwk=(long long)pwk*x%dv;
}
return pwk;
}
void ud(int xx,int x,int w)
{
for(fi=x;fi<=n;fi+=fi&-fi)
{
if(!xx)
{
fw[xx][fi]=(long long)fw[xx][fi]*w%dv;
}
else
{
fw[xx][fi]+=w;
}
}
}
int qr(int xx,int x)
{
int z=!xx;
for(fi=x;fi;fi-=fi&-fi)
{
if(!xx)
{
z=(long long)z*fw[xx][fi]%dv;
}
else
{
z+=fw[xx][fi];
}
}
return z;
}
int bl(int xx,int x)
{
int i,p=0,sm=0;
for(i=18;i+1;i--)
{
if((p|1<<i)<=n&&sm+fw[xx][p|1<<i]<x)
{
p|=1<<i;
sm+=fw[xx][p];
}
}
return p;
}
int slv()
{
int k,l;
long long ml=1,mx=0;
for(k=n+1;k&&ml<=ma;)
{
l=k;
k=bl(1,qr(1,k-1))+1;
if(k==l)
{
break;
}
mx=max(mx*a[l],(long long)sg.qr(k,l-1));
ml*=a[k];
}
return mx%dv*qr(0,k)%dv;
}
int init(int on,int aa[],int wgg[])
{
int i;
n=on;
for(i=1;i<=n;i++)
{
fw[0][i]=1;
}
for(i=1;i<=n;i++)
{
a[i]=aa[i-1];
wg[i]=wgg[i-1];
ud(0,i,a[i]);
ud(1,i,!!(a[i]-1));
}
sg.bd(1,n);
return slv();
}
int updateX(int x,int w)
{
x++;
ud(0,x,(long long)pw(a[x],dv-2)*w%dv);
ud(1,x,!!(w-1)-!!(a[x]-1));
a[x]=w;
return slv();
}
int updateY(int x,int w)
{
x++;
sg.ud(x,w);
return slv();
}
Compilation message
horses.cpp: In function 'int pw(int, int)':
horses.cpp:76:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
76 | pwk=(long long)pwk*pwk%dv;
| ~~~~~~~~~~~~~~~~~~^~~
horses.cpp:79:23: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
79 | pwk=(long long)pwk*x%dv;
| ~~~~~~~~~~~~~~~~^~~
horses.cpp: In function 'void ud(int, int, int)':
horses.cpp:90:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
90 | fw[xx][fi]=(long long)fw[xx][fi]*w%dv;
| ~~~~~~~~~~~~~~~~~~~~~~~^~~
horses.cpp: In function 'int qr(int, int)':
horses.cpp:107:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
107 | z=(long long)z*fw[xx][fi]%dv;
| ~~~~~~~~~~~~~~~~~~~~~~~^~~
horses.cpp: In function 'int slv()':
horses.cpp:148:22: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
148 | return mx%dv*qr(0,k)%dv;
| ~~~~~~~~~~~~~^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:174:35: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
174 | ud(0,x,(long long)pw(a[x],dv-2)*w%dv);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6588 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6592 KB |
Output is correct |
10 |
Correct |
1 ms |
6500 KB |
Output is correct |
11 |
Correct |
1 ms |
6596 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6592 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6592 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6488 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6488 KB |
Output is correct |
21 |
Correct |
1 ms |
6744 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6488 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
3 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
3 ms |
6492 KB |
Output is correct |
30 |
Correct |
2 ms |
6492 KB |
Output is correct |
31 |
Correct |
3 ms |
6492 KB |
Output is correct |
32 |
Correct |
5 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
463 ms |
63872 KB |
Output is correct |
2 |
Correct |
231 ms |
72576 KB |
Output is correct |
3 |
Correct |
211 ms |
63828 KB |
Output is correct |
4 |
Correct |
220 ms |
67664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6596 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6764 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6592 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6744 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6488 KB |
Output is correct |
23 |
Correct |
2 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6492 KB |
Output is correct |
25 |
Correct |
2 ms |
6620 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
5 ms |
6604 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
6492 KB |
Output is correct |
30 |
Correct |
2 ms |
6492 KB |
Output is correct |
31 |
Correct |
4 ms |
6492 KB |
Output is correct |
32 |
Correct |
4 ms |
6732 KB |
Output is correct |
33 |
Correct |
93 ms |
62988 KB |
Output is correct |
34 |
Correct |
93 ms |
63208 KB |
Output is correct |
35 |
Correct |
129 ms |
69968 KB |
Output is correct |
36 |
Correct |
125 ms |
69884 KB |
Output is correct |
37 |
Correct |
135 ms |
61308 KB |
Output is correct |
38 |
Correct |
90 ms |
62092 KB |
Output is correct |
39 |
Correct |
80 ms |
61192 KB |
Output is correct |
40 |
Correct |
116 ms |
64968 KB |
Output is correct |
41 |
Correct |
104 ms |
61124 KB |
Output is correct |
42 |
Correct |
109 ms |
61296 KB |
Output is correct |
43 |
Correct |
116 ms |
65364 KB |
Output is correct |
44 |
Correct |
100 ms |
65368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6588 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6492 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6736 KB |
Output is correct |
27 |
Correct |
4 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
6492 KB |
Output is correct |
30 |
Correct |
2 ms |
6492 KB |
Output is correct |
31 |
Correct |
4 ms |
6728 KB |
Output is correct |
32 |
Correct |
4 ms |
6492 KB |
Output is correct |
33 |
Correct |
441 ms |
63936 KB |
Output is correct |
34 |
Correct |
233 ms |
72512 KB |
Output is correct |
35 |
Correct |
202 ms |
63824 KB |
Output is correct |
36 |
Correct |
227 ms |
67712 KB |
Output is correct |
37 |
Correct |
86 ms |
62996 KB |
Output is correct |
38 |
Correct |
82 ms |
63056 KB |
Output is correct |
39 |
Correct |
125 ms |
69972 KB |
Output is correct |
40 |
Correct |
126 ms |
69968 KB |
Output is correct |
41 |
Correct |
131 ms |
61320 KB |
Output is correct |
42 |
Correct |
84 ms |
62032 KB |
Output is correct |
43 |
Correct |
95 ms |
60996 KB |
Output is correct |
44 |
Correct |
105 ms |
64972 KB |
Output is correct |
45 |
Correct |
94 ms |
61668 KB |
Output is correct |
46 |
Correct |
121 ms |
61124 KB |
Output is correct |
47 |
Correct |
97 ms |
65292 KB |
Output is correct |
48 |
Correct |
102 ms |
65412 KB |
Output is correct |
49 |
Correct |
196 ms |
65000 KB |
Output is correct |
50 |
Correct |
170 ms |
65008 KB |
Output is correct |
51 |
Correct |
228 ms |
71956 KB |
Output is correct |
52 |
Correct |
184 ms |
71380 KB |
Output is correct |
53 |
Correct |
617 ms |
63500 KB |
Output is correct |
54 |
Correct |
234 ms |
63956 KB |
Output is correct |
55 |
Correct |
185 ms |
62444 KB |
Output is correct |
56 |
Correct |
208 ms |
66828 KB |
Output is correct |
57 |
Correct |
356 ms |
62804 KB |
Output is correct |
58 |
Correct |
480 ms |
63396 KB |
Output is correct |
59 |
Correct |
99 ms |
65432 KB |
Output is correct |