# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
62416 |
2018-07-28T11:58:10 Z |
Tenuun |
Horses (IOI15_horses) |
C++17 |
|
561 ms |
43144 KB |
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
int n, tr[2000000], id[500001];
ll bit[500001];
ll now=1;
vector<int>x, y;
set<int>a;
void update(int ind, int val){
if(ind==0) return;
while(ind<=500000){
bit[ind]*=val;
bit[ind]%=mod;
ind+=ind&-ind;
}
}
ll get(int ind){
if(ind<0 || ind>n) return 1;
ll ans=1;
while(ind>0){
ans*=bit[ind];
ans%=mod;
ind-=ind&-ind;
}
return ans;
}
void pre(){
fill(bit, bit+500001, 1);
a.insert(-1);
a.insert(0);
for(int i=0; i<n; i++){
if(x[i]>1){
a.insert(i);
update(i+1, x[i]);
}
}
}
void build(int ind, int l, int r){
if(l==r){
tr[ind]=y[l];
id[l]=ind;
return;
}
build(ind*2, l, (l+r)/2);
build(ind*2+1, (l+r)/2+1, r);
tr[ind]=max(tr[ind*2], tr[ind*2+1]);
}
void upd(int ind){
if(ind==0) return;
tr[ind]=max(tr[ind*2], tr[ind*2+1]);
upd(ind/2);
}
ll rmq(int ind, int l, int r, int L, int R){
if(l==L && r==R) return tr[ind];
int m=(l+r)/2;
if(R<=m) return rmq(ind*2, l, m, L, R);
else if(L>m) return rmq(ind*2+1, m+1, r, L, R);
else{
return max(rmq(ind*2, l, m, L, m), rmq(ind*2+1, m+1, r, m+1, R));
}
}
ll find(){
if(a.size()==1){
return rmq(1, 0, n-1, 0, n-1);
}
else if(a.size()==2){
// return (max(rmq(1, 0, n-1, *prev(a.end()), n-1)*x[*prev(a.end())], rmq(1, 0, n-1, 0, *prev(a.end())-1))%mod);
}
//cout << *prev(a.end()) << endl;
ll ans=1, t=rmq(1, 0, n-1, *prev(a.end()), n-1);
ll now=t;
set<int>::iterator it;
for(it=prev(a.end()); it!=a.begin() && now<mod; it--){
if(now*x[*it]>mod) {
break;
}
now*=x[*it];
}
ans=now%mod;
now/=t;
for(set<int>::iterator tmp=prev((prev(a.end()))); tmp!=prev(it) && tmp!=a.begin(); tmp--){
now/=x[*next(tmp)];
ans=max(ans, now*rmq(1, 0, n-1, *tmp, *next(tmp)-1));
}
ans%=mod;
if(it!=a.begin()) {
ans*=get(*it+1);
}
ans%=mod;
return ans;
}
int init(int N, int X[], int Y[]) {
n=N;
for(int i=0; i<n; i++) {x.push_back(X[i]); y.push_back(Y[i]);}
pre();
build(1, 0, n-1);
return find();
}
ll pw(ll o, ll p){
if(p==0) return 1;
ll ans=pw(o, p/2);
ans*=ans;
ans%=mod;
if(p%2) ans*=o;
ans%=mod;
return ans;
}
int updateX(int pos, int val){
//cout << pos << " " << val <<" " << a.size() <<endl;
if(x[pos]==1 && val==1) return find();
if(x[pos]>1 && val>1){
update(pos+1, (val*pw(x[pos], mod-2)%mod));
x[pos]=val;
return find();
}
if(x[pos]==1){
a.insert(pos);
update(pos+1, val);
x[pos]=val;
}
else{
a.erase(a.find(pos));
update(pos+1, pw(x[pos], mod-2));
x[pos]=1;
}
return find();
}
int updateY(int pos, int val){
tr[id[pos]]=val;
upd(id[pos]/2);
return find();
}
/*int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
int N; cin >> N;
int *X = (int*)malloc(sizeof(int)*(unsigned int)N);
int *Y = (int*)malloc(sizeof(int)*(unsigned int)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 M; cin >> M;
int type, pos, val;
for (int i = 0; i < M; i++) {
cin >> type >> pos >> val;
if (type == 1) {
cout << updateX(pos,val) << endl;
} else if (type == 2) {
cout << updateY(pos,val) << endl;
}
}
return 0;
}*/
Compilation message
horses.cpp: In function 'long long int find()':
horses.cpp:81:8: warning: declaration of 'now' shadows a global declaration [-Wshadow]
ll now=t;
^~~
horses.cpp:9:4: note: shadowed declaration is here
ll now=1;
^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:108:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return find();
~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:123:40: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
if(x[pos]==1 && val==1) return find();
~~~~^~
horses.cpp:125:45: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
update(pos+1, (val*pw(x[pos], mod-2)%mod));
~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:127:20: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return find();
~~~~^~
horses.cpp:136:25: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
update(pos+1, pw(x[pos], mod-2));
~~^~~~~~~~~~~~~~~
horses.cpp:139:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return find();
~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:145:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return find();
~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4216 KB |
Output is correct |
2 |
Correct |
6 ms |
4328 KB |
Output is correct |
3 |
Correct |
6 ms |
4532 KB |
Output is correct |
4 |
Correct |
6 ms |
4532 KB |
Output is correct |
5 |
Correct |
5 ms |
4532 KB |
Output is correct |
6 |
Correct |
5 ms |
4532 KB |
Output is correct |
7 |
Correct |
6 ms |
4532 KB |
Output is correct |
8 |
Correct |
6 ms |
4532 KB |
Output is correct |
9 |
Correct |
6 ms |
4532 KB |
Output is correct |
10 |
Correct |
7 ms |
4532 KB |
Output is correct |
11 |
Correct |
8 ms |
4532 KB |
Output is correct |
12 |
Correct |
5 ms |
4556 KB |
Output is correct |
13 |
Correct |
7 ms |
4556 KB |
Output is correct |
14 |
Correct |
9 ms |
4556 KB |
Output is correct |
15 |
Correct |
6 ms |
4556 KB |
Output is correct |
16 |
Correct |
7 ms |
4556 KB |
Output is correct |
17 |
Correct |
7 ms |
4556 KB |
Output is correct |
18 |
Correct |
6 ms |
4556 KB |
Output is correct |
19 |
Correct |
7 ms |
4556 KB |
Output is correct |
20 |
Correct |
8 ms |
4556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4556 KB |
Output is correct |
2 |
Correct |
6 ms |
4564 KB |
Output is correct |
3 |
Correct |
6 ms |
4564 KB |
Output is correct |
4 |
Correct |
7 ms |
4564 KB |
Output is correct |
5 |
Correct |
6 ms |
4564 KB |
Output is correct |
6 |
Correct |
7 ms |
4564 KB |
Output is correct |
7 |
Correct |
5 ms |
4564 KB |
Output is correct |
8 |
Correct |
6 ms |
4564 KB |
Output is correct |
9 |
Correct |
4 ms |
4564 KB |
Output is correct |
10 |
Correct |
7 ms |
4564 KB |
Output is correct |
11 |
Correct |
6 ms |
4564 KB |
Output is correct |
12 |
Correct |
5 ms |
4564 KB |
Output is correct |
13 |
Correct |
6 ms |
4564 KB |
Output is correct |
14 |
Correct |
6 ms |
4564 KB |
Output is correct |
15 |
Correct |
6 ms |
4564 KB |
Output is correct |
16 |
Correct |
7 ms |
4564 KB |
Output is correct |
17 |
Correct |
6 ms |
4564 KB |
Output is correct |
18 |
Correct |
6 ms |
4564 KB |
Output is correct |
19 |
Correct |
5 ms |
4564 KB |
Output is correct |
20 |
Correct |
6 ms |
4564 KB |
Output is correct |
21 |
Correct |
6 ms |
4588 KB |
Output is correct |
22 |
Correct |
5 ms |
4588 KB |
Output is correct |
23 |
Correct |
7 ms |
4588 KB |
Output is correct |
24 |
Correct |
7 ms |
4604 KB |
Output is correct |
25 |
Correct |
8 ms |
4620 KB |
Output is correct |
26 |
Correct |
8 ms |
4620 KB |
Output is correct |
27 |
Correct |
9 ms |
4636 KB |
Output is correct |
28 |
Correct |
9 ms |
4652 KB |
Output is correct |
29 |
Correct |
9 ms |
4652 KB |
Output is correct |
30 |
Correct |
9 ms |
4652 KB |
Output is correct |
31 |
Correct |
9 ms |
4652 KB |
Output is correct |
32 |
Correct |
11 ms |
4652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
544 ms |
43144 KB |
Output is correct |
2 |
Correct |
362 ms |
43144 KB |
Output is correct |
3 |
Correct |
414 ms |
43144 KB |
Output is correct |
4 |
Correct |
383 ms |
43144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
43144 KB |
Output is correct |
2 |
Correct |
8 ms |
43144 KB |
Output is correct |
3 |
Correct |
6 ms |
43144 KB |
Output is correct |
4 |
Correct |
7 ms |
43144 KB |
Output is correct |
5 |
Correct |
6 ms |
43144 KB |
Output is correct |
6 |
Correct |
8 ms |
43144 KB |
Output is correct |
7 |
Correct |
6 ms |
43144 KB |
Output is correct |
8 |
Correct |
7 ms |
43144 KB |
Output is correct |
9 |
Correct |
6 ms |
43144 KB |
Output is correct |
10 |
Correct |
6 ms |
43144 KB |
Output is correct |
11 |
Correct |
6 ms |
43144 KB |
Output is correct |
12 |
Correct |
6 ms |
43144 KB |
Output is correct |
13 |
Correct |
7 ms |
43144 KB |
Output is correct |
14 |
Correct |
7 ms |
43144 KB |
Output is correct |
15 |
Correct |
6 ms |
43144 KB |
Output is correct |
16 |
Correct |
6 ms |
43144 KB |
Output is correct |
17 |
Correct |
6 ms |
43144 KB |
Output is correct |
18 |
Correct |
6 ms |
43144 KB |
Output is correct |
19 |
Correct |
5 ms |
43144 KB |
Output is correct |
20 |
Correct |
5 ms |
43144 KB |
Output is correct |
21 |
Correct |
6 ms |
43144 KB |
Output is correct |
22 |
Correct |
7 ms |
43144 KB |
Output is correct |
23 |
Correct |
8 ms |
43144 KB |
Output is correct |
24 |
Correct |
8 ms |
43144 KB |
Output is correct |
25 |
Correct |
7 ms |
43144 KB |
Output is correct |
26 |
Correct |
8 ms |
43144 KB |
Output is correct |
27 |
Correct |
12 ms |
43144 KB |
Output is correct |
28 |
Correct |
8 ms |
43144 KB |
Output is correct |
29 |
Correct |
9 ms |
43144 KB |
Output is correct |
30 |
Correct |
8 ms |
43144 KB |
Output is correct |
31 |
Correct |
9 ms |
43144 KB |
Output is correct |
32 |
Correct |
9 ms |
43144 KB |
Output is correct |
33 |
Correct |
52 ms |
43144 KB |
Output is correct |
34 |
Correct |
53 ms |
43144 KB |
Output is correct |
35 |
Correct |
319 ms |
43144 KB |
Output is correct |
36 |
Correct |
296 ms |
43144 KB |
Output is correct |
37 |
Correct |
89 ms |
43144 KB |
Output is correct |
38 |
Correct |
141 ms |
43144 KB |
Output is correct |
39 |
Correct |
44 ms |
43144 KB |
Output is correct |
40 |
Correct |
262 ms |
43144 KB |
Output is correct |
41 |
Correct |
58 ms |
43144 KB |
Output is correct |
42 |
Correct |
78 ms |
43144 KB |
Output is correct |
43 |
Correct |
291 ms |
43144 KB |
Output is correct |
44 |
Correct |
265 ms |
43144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
43144 KB |
Output is correct |
2 |
Correct |
7 ms |
43144 KB |
Output is correct |
3 |
Correct |
8 ms |
43144 KB |
Output is correct |
4 |
Correct |
6 ms |
43144 KB |
Output is correct |
5 |
Correct |
6 ms |
43144 KB |
Output is correct |
6 |
Correct |
6 ms |
43144 KB |
Output is correct |
7 |
Correct |
5 ms |
43144 KB |
Output is correct |
8 |
Correct |
6 ms |
43144 KB |
Output is correct |
9 |
Correct |
5 ms |
43144 KB |
Output is correct |
10 |
Correct |
6 ms |
43144 KB |
Output is correct |
11 |
Correct |
7 ms |
43144 KB |
Output is correct |
12 |
Correct |
6 ms |
43144 KB |
Output is correct |
13 |
Correct |
7 ms |
43144 KB |
Output is correct |
14 |
Correct |
6 ms |
43144 KB |
Output is correct |
15 |
Correct |
7 ms |
43144 KB |
Output is correct |
16 |
Correct |
7 ms |
43144 KB |
Output is correct |
17 |
Correct |
7 ms |
43144 KB |
Output is correct |
18 |
Correct |
6 ms |
43144 KB |
Output is correct |
19 |
Correct |
6 ms |
43144 KB |
Output is correct |
20 |
Correct |
6 ms |
43144 KB |
Output is correct |
21 |
Correct |
7 ms |
43144 KB |
Output is correct |
22 |
Correct |
7 ms |
43144 KB |
Output is correct |
23 |
Correct |
7 ms |
43144 KB |
Output is correct |
24 |
Correct |
7 ms |
43144 KB |
Output is correct |
25 |
Correct |
7 ms |
43144 KB |
Output is correct |
26 |
Correct |
7 ms |
43144 KB |
Output is correct |
27 |
Correct |
9 ms |
43144 KB |
Output is correct |
28 |
Correct |
8 ms |
43144 KB |
Output is correct |
29 |
Correct |
9 ms |
43144 KB |
Output is correct |
30 |
Correct |
10 ms |
43144 KB |
Output is correct |
31 |
Correct |
8 ms |
43144 KB |
Output is correct |
32 |
Correct |
8 ms |
43144 KB |
Output is correct |
33 |
Correct |
561 ms |
43144 KB |
Output is correct |
34 |
Correct |
392 ms |
43144 KB |
Output is correct |
35 |
Correct |
377 ms |
43144 KB |
Output is correct |
36 |
Correct |
421 ms |
43144 KB |
Output is correct |
37 |
Correct |
60 ms |
43144 KB |
Output is correct |
38 |
Correct |
47 ms |
43144 KB |
Output is correct |
39 |
Correct |
299 ms |
43144 KB |
Output is correct |
40 |
Correct |
282 ms |
43144 KB |
Output is correct |
41 |
Correct |
85 ms |
43144 KB |
Output is correct |
42 |
Correct |
176 ms |
43144 KB |
Output is correct |
43 |
Correct |
59 ms |
43144 KB |
Output is correct |
44 |
Correct |
275 ms |
43144 KB |
Output is correct |
45 |
Correct |
57 ms |
43144 KB |
Output is correct |
46 |
Correct |
70 ms |
43144 KB |
Output is correct |
47 |
Correct |
286 ms |
43144 KB |
Output is correct |
48 |
Correct |
277 ms |
43144 KB |
Output is correct |
49 |
Correct |
154 ms |
43144 KB |
Output is correct |
50 |
Correct |
121 ms |
43144 KB |
Output is correct |
51 |
Correct |
393 ms |
43144 KB |
Output is correct |
52 |
Correct |
320 ms |
43144 KB |
Output is correct |
53 |
Correct |
404 ms |
43144 KB |
Output is correct |
54 |
Correct |
225 ms |
43144 KB |
Output is correct |
55 |
Correct |
125 ms |
43144 KB |
Output is correct |
56 |
Correct |
382 ms |
43144 KB |
Output is correct |
57 |
Correct |
226 ms |
43144 KB |
Output is correct |
58 |
Correct |
310 ms |
43144 KB |
Output is correct |
59 |
Correct |
251 ms |
43144 KB |
Output is correct |