# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
443743 |
2021-07-12T01:12:29 Z |
jk410 |
말 (IOI15_horses) |
C++17 |
|
1263 ms |
44088 KB |
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
typedef long long ll;
const ll MX=1e9,MX_N=5e5,MOD=1e9+7;
const ll SZ=(1<<(int)ceil(log2(MX_N))+1);
int N;
ll X[MX_N+1],Y[MX_N+1],XTree[SZ],YTree[SZ];
priority_queue<int> Q;
vector<int> Idx;
ll mul_update(ll *tree,int s,int e,int idx,ll v,int n){
if (idx<s||e<idx)
return tree[n];
if (s==e)
return tree[n]=v;
int m=(s+e)>>1;
return tree[n]=mul_update(tree,s,m,idx,v,n<<1)*mul_update(tree,m+1,e,idx,v,n<<1|1)%MOD;
}
ll mul_query(ll *tree,int s,int e,int l,int r,int n){
if (r<s||e<l)
return 1;
if (l<=s&&e<=r)
return tree[n];
int m=(s+e)>>1;
return mul_query(tree,s,m,l,r,n<<1)*mul_query(tree,m+1,e,l,r,n<<1|1)%MOD;
}
ll max_update(ll *tree,int s,int e,int idx,ll v,int n){
if (idx<s||e<idx)
return tree[n];
if (s==e)
return tree[n]=v;
int m=(s+e)>>1;
return tree[n]=max(max_update(tree,s,m,idx,v,n<<1),max_update(tree,m+1,e,idx,v,n<<1|1));
}
ll max_query(ll *tree,int s,int e,int l,int r,int n){
if (r<s||e<l)
return 0;
if (l<=s&&e<=r)
return tree[n];
int m=(s+e)>>1;
return max(max_query(tree,s,m,l,r,n<<1),max_query(tree,m+1,e,l,r,n<<1|1));
}
int ans(){
Idx.clear();
Idx.push_back(N);
ll mul=1;
while (!Q.empty()){
int t=Q.top();
Q.pop();
Idx.push_back(t);
mul*=X[t];
if (mul>MX)
break;
}
if (mul<=MX)
Idx.push_back(0);
mul=1;
ll max_x=X[Idx.back()],max_y=0;
int idx;
for (int i=Idx.size()-1; i>0; i--){
mul*=X[Idx[i]];
ll t=max_query(YTree,0,N-1,Idx[i],Idx[i-1]-1,1);
if (max_y<mul/max_x*t){
max_x=mul;
max_y=t;
idx=Idx[i-1]-1;
}
}
for (int i:Idx){
if (X[i]>1)
Q.push(i);
}
return mul_query(XTree,0,N-1,0,idx,1)*max_y%MOD;
}
int init(int n, int x[], int y[]){
N=n;
for (int i=0; i<N; i++){
X[i]=x[i];
if (X[i]>1)
Q.push(i);
mul_update(XTree,0,N-1,i,X[i],1);
Y[i]=y[i];
max_update(YTree,0,N-1,i,Y[i],1);
}
return ans();
}
int updateX(int pos, int val) {
if (val>1&&X[pos]==1)
Q.push(pos);
X[pos]=val;
mul_update(XTree,0,N-1,pos,val,1);
return ans();
}
int updateY(int pos, int val) {
Y[pos]=val;
max_update(YTree,0,N-1,pos,val,1);
return ans();
}
Compilation message
horses.cpp:6:38: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
6 | const ll SZ=(1<<(int)ceil(log2(MX_N))+1);
| ~~~~~~~~~~~~~~~~~~~~~^~
horses.cpp: In function 'int ans()':
horses.cpp:60:26: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
60 | for (int i=Idx.size()-1; i>0; i--){
| ~~~~~~~~~~^~
horses.cpp:73:48: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
73 | return mul_query(XTree,0,N-1,0,idx,1)*max_y%MOD;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp:73:21: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
73 | return mul_query(XTree,0,N-1,0,idx,1)*max_y%MOD;
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
5 ms |
332 KB |
Output is correct |
28 |
Correct |
3 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
5 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1121 ms |
31532 KB |
Output is correct |
2 |
Correct |
520 ms |
44064 KB |
Output is correct |
3 |
Correct |
538 ms |
35476 KB |
Output is correct |
4 |
Correct |
582 ms |
39204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
6 ms |
332 KB |
Output is correct |
28 |
Correct |
3 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
5 ms |
332 KB |
Output is correct |
33 |
Correct |
328 ms |
28564 KB |
Output is correct |
34 |
Correct |
330 ms |
32544 KB |
Output is correct |
35 |
Correct |
388 ms |
41400 KB |
Output is correct |
36 |
Correct |
375 ms |
41504 KB |
Output is correct |
37 |
Correct |
413 ms |
30616 KB |
Output is correct |
38 |
Correct |
358 ms |
32620 KB |
Output is correct |
39 |
Correct |
324 ms |
30532 KB |
Output is correct |
40 |
Correct |
362 ms |
36624 KB |
Output is correct |
41 |
Correct |
361 ms |
30472 KB |
Output is correct |
42 |
Correct |
373 ms |
30596 KB |
Output is correct |
43 |
Correct |
374 ms |
36808 KB |
Output is correct |
44 |
Correct |
363 ms |
36912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
5 ms |
392 KB |
Output is correct |
28 |
Correct |
3 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
5 ms |
388 KB |
Output is correct |
33 |
Correct |
1116 ms |
31616 KB |
Output is correct |
34 |
Correct |
503 ms |
44088 KB |
Output is correct |
35 |
Correct |
528 ms |
35324 KB |
Output is correct |
36 |
Correct |
579 ms |
39092 KB |
Output is correct |
37 |
Correct |
338 ms |
32412 KB |
Output is correct |
38 |
Correct |
334 ms |
32388 KB |
Output is correct |
39 |
Correct |
390 ms |
41496 KB |
Output is correct |
40 |
Correct |
379 ms |
41396 KB |
Output is correct |
41 |
Correct |
417 ms |
30772 KB |
Output is correct |
42 |
Correct |
352 ms |
32568 KB |
Output is correct |
43 |
Correct |
323 ms |
30500 KB |
Output is correct |
44 |
Correct |
358 ms |
36432 KB |
Output is correct |
45 |
Correct |
361 ms |
30492 KB |
Output is correct |
46 |
Correct |
380 ms |
30524 KB |
Output is correct |
47 |
Correct |
351 ms |
36812 KB |
Output is correct |
48 |
Correct |
350 ms |
36916 KB |
Output is correct |
49 |
Correct |
490 ms |
34720 KB |
Output is correct |
50 |
Correct |
463 ms |
34756 KB |
Output is correct |
51 |
Correct |
622 ms |
43344 KB |
Output is correct |
52 |
Correct |
461 ms |
42932 KB |
Output is correct |
53 |
Correct |
1263 ms |
33004 KB |
Output is correct |
54 |
Correct |
632 ms |
34820 KB |
Output is correct |
55 |
Correct |
468 ms |
31556 KB |
Output is correct |
56 |
Correct |
489 ms |
38348 KB |
Output is correct |
57 |
Correct |
778 ms |
32280 KB |
Output is correct |
58 |
Correct |
1000 ms |
32676 KB |
Output is correct |
59 |
Correct |
351 ms |
36788 KB |
Output is correct |