# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
785658 |
2023-07-17T11:31:47 Z |
TimDee |
Horses (IOI15_horses) |
C++17 |
|
440 ms |
40620 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int,int>
#define f first
#define s second
const int mod = 1e9+7;
#define int long long
int pw(int a, int b) {
int r=1;
while (b) {
if (b&1) r=(r*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return r;
}
int inv(int x) {
return pw(x,mod-2);
}
struct BIT {
vector<int> t; int n;
BIT(int n) {
this->n=n;
t.assign(n,1);
}
void add(int i, int x) {
for(;i<n;i=i|(i+1)) t[i]=(t[i]*x)%mod;
}
int sum(int r) {
int q=1;
for(;r>=0;r=(r&(r+1))-1) q=(q*t[r])%mod;
return q;
}
};
#undef int
int a[(int)5e5+5];
int c[(int)5e5+5];
BIT ft(5e5+5);
set<int> s;
int n;
struct sgt {
vector<int> t; int sz=1;
sgt(int n) {
while (sz<n) sz<<=1;
t.assign(2*sz,0);
}
int query(int v, int l, int r, int lx, int rx) {
if (rx<=l || r<=lx) return 0;
if (lx<=l && r<=rx) return t[v];
int m=(l+r)>>1;
int lq=query(2*v+1,l,m,lx,rx);
int rq=query(2*v+2,m,r,lx,rx);
return max(lq,rq);
}
int query(int l, int r) {
return query(0,0,sz,l,r);
}
void upd(int v, int l, int r, int i) {
if (r-l==1) return;
int m=(l+r)>>1;
if (i<m) upd(2*v+1,l,m,i);
else upd(2*v+2,m,r,i);
t[v]=max(t[2*v+1],t[2*v+2]);
}
void set(int i, int x) {
t[sz-1+i]=x;
upd(0,0,sz,i);
}
};
sgt st(5e5+5);
int query() {
#define int long long
int z=1;
int b=0;
pi mx={0,1};
int last=n;
s.insert(0);
for (auto v:s) {
int i=-v;
if (z>1e9) break;
int y=st.query(i,n);
if (y*mx.s>mx.f*z) {
b=i;
mx={y,z};
}
z*=a[i];
last=i;
}
int p=ft.sum(b);
int y=st.query(b,n);
return (p*y)%mod;
#undef int
}
int init(int _n, int x[], int y[]) {
n=_n;
forn(i,n) a[i]=x[i], c[i]=y[i];
forn(i,n) ft.add(i,a[i]);
forn(i,n) if (a[i]>1) s.insert(-i);
forn(i,n) st.set(i,c[i]);
return query();
}
int updateX(int i, int x) {
if (a[i]>1) s.erase(s.find(-i));
ft.add(i,inv(a[i]));
a[i]=x;
if (a[i]>1) s.insert(-i);
ft.add(i,a[i]);
return query();
}
int updateY(int i, int x) {
c[i]=x;
st.set(i,c[i]);
return query();
}
Compilation message
horses.cpp: In constructor 'BIT::BIT(long long int)':
horses.cpp:28:11: warning: declaration of 'n' shadows a member of 'BIT' [-Wshadow]
28 | BIT(int n) {
| ^
horses.cpp:27:22: note: shadowed declaration is here
27 | vector<int> t; int n;
| ^
horses.cpp: In constructor 'BIT::BIT(long long int)':
horses.cpp:28:11: warning: declaration of 'n' shadows a member of 'BIT' [-Wshadow]
28 | BIT(int n) {
| ^
horses.cpp:27:22: note: shadowed declaration is here
27 | vector<int> t; int n;
| ^
horses.cpp: In constructor 'BIT::BIT(long long int)':
horses.cpp:28:11: warning: declaration of 'n' shadows a member of 'BIT' [-Wshadow]
28 | BIT(int n) {
| ^
horses.cpp:27:22: note: shadowed declaration is here
27 | vector<int> t; int n;
| ^
horses.cpp: In constructor 'sgt::sgt(int)':
horses.cpp:51:11: warning: declaration of 'n' shadows a global declaration [-Wshadow]
51 | sgt(int n) {
| ~~~~^
horses.cpp:47:5: note: shadowed declaration is here
47 | int n;
| ^
horses.cpp: In constructor 'sgt::sgt(int)':
horses.cpp:51:11: warning: declaration of 'n' shadows a global declaration [-Wshadow]
51 | sgt(int n) {
| ~~~~^
horses.cpp:47:5: note: shadowed declaration is here
47 | int n;
| ^
horses.cpp: In constructor 'sgt::sgt(int)':
horses.cpp:51:11: warning: declaration of 'n' shadows a global declaration [-Wshadow]
51 | sgt(int n) {
| ~~~~^
horses.cpp:47:5: note: shadowed declaration is here
47 | int n;
| ^
horses.cpp: In function 'int query()':
horses.cpp:90:9: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
90 | if (z>1e9) break;
| ^
horses.cpp:91:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
91 | int y=st.query(i,n);
| ^
horses.cpp:100:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
100 | int y=st.query(b,n);
| ^
horses.cpp:101:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
101 | return (p*y)%mod;
| ~~~~~^~~~
horses.cpp:86:7: warning: variable 'last' set but not used [-Wunused-but-set-variable]
86 | int last=n;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8276 KB |
Output is correct |
2 |
Correct |
4 ms |
8276 KB |
Output is correct |
3 |
Correct |
3 ms |
8276 KB |
Output is correct |
4 |
Correct |
4 ms |
8320 KB |
Output is correct |
5 |
Correct |
3 ms |
8276 KB |
Output is correct |
6 |
Correct |
3 ms |
8276 KB |
Output is correct |
7 |
Correct |
4 ms |
8276 KB |
Output is correct |
8 |
Correct |
3 ms |
8276 KB |
Output is correct |
9 |
Correct |
4 ms |
8276 KB |
Output is correct |
10 |
Correct |
4 ms |
8276 KB |
Output is correct |
11 |
Correct |
3 ms |
8276 KB |
Output is correct |
12 |
Correct |
4 ms |
8276 KB |
Output is correct |
13 |
Correct |
3 ms |
8276 KB |
Output is correct |
14 |
Correct |
3 ms |
8276 KB |
Output is correct |
15 |
Correct |
4 ms |
8276 KB |
Output is correct |
16 |
Correct |
3 ms |
8276 KB |
Output is correct |
17 |
Correct |
3 ms |
8276 KB |
Output is correct |
18 |
Correct |
3 ms |
8276 KB |
Output is correct |
19 |
Correct |
4 ms |
8276 KB |
Output is correct |
20 |
Correct |
4 ms |
8276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8276 KB |
Output is correct |
2 |
Correct |
3 ms |
8276 KB |
Output is correct |
3 |
Correct |
3 ms |
8276 KB |
Output is correct |
4 |
Correct |
3 ms |
8276 KB |
Output is correct |
5 |
Correct |
3 ms |
8276 KB |
Output is correct |
6 |
Correct |
3 ms |
8276 KB |
Output is correct |
7 |
Correct |
4 ms |
8276 KB |
Output is correct |
8 |
Correct |
3 ms |
8276 KB |
Output is correct |
9 |
Correct |
3 ms |
8276 KB |
Output is correct |
10 |
Correct |
3 ms |
8276 KB |
Output is correct |
11 |
Correct |
4 ms |
8340 KB |
Output is correct |
12 |
Correct |
3 ms |
8276 KB |
Output is correct |
13 |
Correct |
3 ms |
8276 KB |
Output is correct |
14 |
Correct |
3 ms |
8276 KB |
Output is correct |
15 |
Correct |
3 ms |
8276 KB |
Output is correct |
16 |
Correct |
3 ms |
8276 KB |
Output is correct |
17 |
Correct |
3 ms |
8276 KB |
Output is correct |
18 |
Correct |
3 ms |
8244 KB |
Output is correct |
19 |
Correct |
5 ms |
8284 KB |
Output is correct |
20 |
Correct |
4 ms |
8276 KB |
Output is correct |
21 |
Correct |
3 ms |
8276 KB |
Output is correct |
22 |
Correct |
3 ms |
8276 KB |
Output is correct |
23 |
Correct |
4 ms |
8380 KB |
Output is correct |
24 |
Correct |
4 ms |
8276 KB |
Output is correct |
25 |
Correct |
4 ms |
8424 KB |
Output is correct |
26 |
Correct |
6 ms |
8404 KB |
Output is correct |
27 |
Correct |
8 ms |
8368 KB |
Output is correct |
28 |
Correct |
6 ms |
8404 KB |
Output is correct |
29 |
Correct |
4 ms |
8276 KB |
Output is correct |
30 |
Correct |
5 ms |
8404 KB |
Output is correct |
31 |
Correct |
7 ms |
8372 KB |
Output is correct |
32 |
Correct |
6 ms |
8276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
407 ms |
40560 KB |
Output is correct |
2 |
Correct |
298 ms |
40596 KB |
Output is correct |
3 |
Correct |
289 ms |
40548 KB |
Output is correct |
4 |
Correct |
333 ms |
40572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8276 KB |
Output is correct |
2 |
Correct |
3 ms |
8276 KB |
Output is correct |
3 |
Correct |
4 ms |
8276 KB |
Output is correct |
4 |
Correct |
3 ms |
8276 KB |
Output is correct |
5 |
Correct |
4 ms |
8296 KB |
Output is correct |
6 |
Correct |
3 ms |
8276 KB |
Output is correct |
7 |
Correct |
3 ms |
8276 KB |
Output is correct |
8 |
Correct |
4 ms |
8276 KB |
Output is correct |
9 |
Correct |
5 ms |
8276 KB |
Output is correct |
10 |
Correct |
4 ms |
8276 KB |
Output is correct |
11 |
Correct |
4 ms |
8276 KB |
Output is correct |
12 |
Correct |
4 ms |
8276 KB |
Output is correct |
13 |
Correct |
5 ms |
8276 KB |
Output is correct |
14 |
Correct |
5 ms |
8276 KB |
Output is correct |
15 |
Correct |
4 ms |
8276 KB |
Output is correct |
16 |
Correct |
3 ms |
8276 KB |
Output is correct |
17 |
Correct |
3 ms |
8276 KB |
Output is correct |
18 |
Correct |
5 ms |
8276 KB |
Output is correct |
19 |
Correct |
3 ms |
8276 KB |
Output is correct |
20 |
Correct |
3 ms |
8276 KB |
Output is correct |
21 |
Correct |
4 ms |
8276 KB |
Output is correct |
22 |
Correct |
4 ms |
8276 KB |
Output is correct |
23 |
Correct |
4 ms |
8376 KB |
Output is correct |
24 |
Correct |
5 ms |
8276 KB |
Output is correct |
25 |
Correct |
5 ms |
8420 KB |
Output is correct |
26 |
Correct |
5 ms |
8404 KB |
Output is correct |
27 |
Correct |
9 ms |
8368 KB |
Output is correct |
28 |
Correct |
6 ms |
8404 KB |
Output is correct |
29 |
Correct |
5 ms |
8364 KB |
Output is correct |
30 |
Correct |
6 ms |
8448 KB |
Output is correct |
31 |
Correct |
5 ms |
8276 KB |
Output is correct |
32 |
Correct |
6 ms |
8384 KB |
Output is correct |
33 |
Correct |
73 ms |
16260 KB |
Output is correct |
34 |
Correct |
69 ms |
16288 KB |
Output is correct |
35 |
Correct |
195 ms |
39648 KB |
Output is correct |
36 |
Correct |
193 ms |
39688 KB |
Output is correct |
37 |
Correct |
94 ms |
16264 KB |
Output is correct |
38 |
Correct |
115 ms |
28180 KB |
Output is correct |
39 |
Correct |
65 ms |
16156 KB |
Output is correct |
40 |
Correct |
180 ms |
39696 KB |
Output is correct |
41 |
Correct |
77 ms |
16204 KB |
Output is correct |
42 |
Correct |
80 ms |
16204 KB |
Output is correct |
43 |
Correct |
156 ms |
39572 KB |
Output is correct |
44 |
Correct |
172 ms |
39632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8276 KB |
Output is correct |
2 |
Correct |
3 ms |
8276 KB |
Output is correct |
3 |
Correct |
3 ms |
8276 KB |
Output is correct |
4 |
Correct |
3 ms |
8276 KB |
Output is correct |
5 |
Correct |
3 ms |
8228 KB |
Output is correct |
6 |
Correct |
4 ms |
8276 KB |
Output is correct |
7 |
Correct |
3 ms |
8276 KB |
Output is correct |
8 |
Correct |
3 ms |
8276 KB |
Output is correct |
9 |
Correct |
5 ms |
8276 KB |
Output is correct |
10 |
Correct |
4 ms |
8276 KB |
Output is correct |
11 |
Correct |
4 ms |
8276 KB |
Output is correct |
12 |
Correct |
3 ms |
8276 KB |
Output is correct |
13 |
Correct |
4 ms |
8276 KB |
Output is correct |
14 |
Correct |
3 ms |
8276 KB |
Output is correct |
15 |
Correct |
4 ms |
8276 KB |
Output is correct |
16 |
Correct |
4 ms |
8276 KB |
Output is correct |
17 |
Correct |
4 ms |
8276 KB |
Output is correct |
18 |
Correct |
5 ms |
8300 KB |
Output is correct |
19 |
Correct |
3 ms |
8276 KB |
Output is correct |
20 |
Correct |
3 ms |
8276 KB |
Output is correct |
21 |
Correct |
3 ms |
8320 KB |
Output is correct |
22 |
Correct |
4 ms |
8312 KB |
Output is correct |
23 |
Correct |
4 ms |
8276 KB |
Output is correct |
24 |
Correct |
4 ms |
8276 KB |
Output is correct |
25 |
Correct |
5 ms |
8404 KB |
Output is correct |
26 |
Correct |
5 ms |
8404 KB |
Output is correct |
27 |
Correct |
7 ms |
8276 KB |
Output is correct |
28 |
Correct |
5 ms |
8404 KB |
Output is correct |
29 |
Correct |
4 ms |
8276 KB |
Output is correct |
30 |
Correct |
4 ms |
8404 KB |
Output is correct |
31 |
Correct |
5 ms |
8276 KB |
Output is correct |
32 |
Correct |
6 ms |
8376 KB |
Output is correct |
33 |
Correct |
369 ms |
40572 KB |
Output is correct |
34 |
Correct |
306 ms |
40604 KB |
Output is correct |
35 |
Correct |
306 ms |
40548 KB |
Output is correct |
36 |
Correct |
350 ms |
40544 KB |
Output is correct |
37 |
Correct |
77 ms |
16288 KB |
Output is correct |
38 |
Correct |
80 ms |
16332 KB |
Output is correct |
39 |
Correct |
180 ms |
39732 KB |
Output is correct |
40 |
Correct |
195 ms |
39612 KB |
Output is correct |
41 |
Correct |
95 ms |
16272 KB |
Output is correct |
42 |
Correct |
112 ms |
28192 KB |
Output is correct |
43 |
Correct |
62 ms |
16160 KB |
Output is correct |
44 |
Correct |
172 ms |
39692 KB |
Output is correct |
45 |
Correct |
79 ms |
16276 KB |
Output is correct |
46 |
Correct |
82 ms |
16156 KB |
Output is correct |
47 |
Correct |
159 ms |
39628 KB |
Output is correct |
48 |
Correct |
154 ms |
39524 KB |
Output is correct |
49 |
Correct |
163 ms |
18220 KB |
Output is correct |
50 |
Correct |
154 ms |
18196 KB |
Output is correct |
51 |
Correct |
259 ms |
40544 KB |
Output is correct |
52 |
Correct |
228 ms |
40620 KB |
Output is correct |
53 |
Correct |
440 ms |
18168 KB |
Output is correct |
54 |
Correct |
242 ms |
31032 KB |
Output is correct |
55 |
Correct |
148 ms |
16348 KB |
Output is correct |
56 |
Correct |
245 ms |
40520 KB |
Output is correct |
57 |
Correct |
226 ms |
17040 KB |
Output is correct |
58 |
Correct |
294 ms |
17120 KB |
Output is correct |
59 |
Correct |
154 ms |
39560 KB |
Output is correct |