# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
167385 |
2019-12-07T20:13:37 Z |
kostia244 |
Horses (IOI15_horses) |
C++17 |
|
477 ms |
50336 KB |
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
const int mod = 1e9 + 7;
const int maxn = 1<<21;
int n, t[maxn], ans = 0;
set<int> chk;
ll mulal = 1;
vi x, ix, y;
void upd(int p, int v) {
for(t[p += n] = v; p>>=1;)
t[p] = max(t[p<<1], t[p<<1|1]);
}
int get(int l, int r) {
// cout << l << " " << r << " " << n << "q\n";
int ans = 0;
for(l+=n, r+=n+1; l < r; l>>=1, r>>=1) {
if(l&1) ans = max(ans, t[l++]);
if(r&1) ans = max(ans, t[--r]);
}
// cout << ans << "q\n";
return ans;
}
int bp(int a, int p) {
int r = 1;
while(p) {
if(p&1) r = (r*1ll*a)%mod;
a = (a*1ll*a)%mod;
p>>=1;
}
return r;
}
int calc() {
auto it = chk.end();
int p = n-1;
ll mul = 1, pref = mulal;
ans = 0;
// for(auto i : chk) cout << i << " ";
// cout << "b\n";
while(mul <= 1000000000 && it-- != chk.begin()) {
int tmp = get((*it == -1) ? 0 : *it, p);
if(!ans || tmp > mul) {
ans = (tmp*1ll*pref)%mod;
mul = tmp;
}
// cout << *it << " " << p << "\n";
// cout << tmp << " " << pref;
// cout << " " << mul << "\n";
if(*it == -1) break;
pref = (pref*1ll*ix[*it])%mod;
mul *= x[*it];
p = *it - 1;
}
// cout << ans;
// cout << "======\n";
return ans;
}
int init(int N, int X[], int Y[]) {
n = N;
ix.resize(n);
x.resize(n);
y.resize(n);
chk.insert(-1);
for(int i = 0; i < n; i++) {
x[i] = X[i];
ix[i] = bp(x[i], mod-2);
mulal = (mulal*1ll*x[i])%mod;
if(x[i] > 1)
chk.insert(i);
}
for(int i = 0; i < n; i++) {
y[i] = Y[i];
upd(i, y[i]);
}
return calc();
}
int updateX(int pos, int val) {
if(x[pos] == val) return calc();
if(val==1) chk.erase(pos);
else if(x[pos]==1) chk.insert(pos);
x[pos] = val;
mulal = (mulal*1ll*ix[pos])%mod;
mulal = (mulal*1ll*x[pos])%mod;
ix[pos] = bp(x[pos], mod-2);
return calc();
}
int updateY(int pos, int val) {
y[pos] = val;
upd(pos, y[pos]);
return calc();
}
Compilation message
horses.cpp: In function 'int get(int, int)':
horses.cpp:18:6: warning: declaration of 'ans' shadows a global declaration [-Wshadow]
int ans = 0;
^~~
horses.cpp:8:17: note: shadowed declaration is here
int n, t[maxn], ans = 0;
^~~
horses.cpp: In function 'int bp(int, int)':
horses.cpp:29:24: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
if(p&1) r = (r*1ll*a)%mod;
~~~~~~~~~^~~~
horses.cpp:30:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
a = (a*1ll*a)%mod;
~~~~~~~~~^~~~
horses.cpp: In function 'int calc()':
horses.cpp:45:24: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
ans = (tmp*1ll*pref)%mod;
~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
252 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
256 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
380 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
504 KB |
Output is correct |
31 |
Correct |
3 ms |
376 KB |
Output is correct |
32 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
373 ms |
40624 KB |
Output is correct |
2 |
Correct |
390 ms |
39244 KB |
Output is correct |
3 |
Correct |
364 ms |
40440 KB |
Output is correct |
4 |
Correct |
477 ms |
39836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
408 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
380 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
256 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
380 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
29 |
Correct |
3 ms |
380 KB |
Output is correct |
30 |
Correct |
6 ms |
508 KB |
Output is correct |
31 |
Correct |
3 ms |
376 KB |
Output is correct |
32 |
Correct |
3 ms |
376 KB |
Output is correct |
33 |
Correct |
150 ms |
15580 KB |
Output is correct |
34 |
Correct |
148 ms |
15932 KB |
Output is correct |
35 |
Correct |
350 ms |
38468 KB |
Output is correct |
36 |
Correct |
358 ms |
38396 KB |
Output is correct |
37 |
Correct |
146 ms |
16248 KB |
Output is correct |
38 |
Correct |
227 ms |
29156 KB |
Output is correct |
39 |
Correct |
140 ms |
16120 KB |
Output is correct |
40 |
Correct |
338 ms |
43644 KB |
Output is correct |
41 |
Correct |
140 ms |
16248 KB |
Output is correct |
42 |
Correct |
142 ms |
16348 KB |
Output is correct |
43 |
Correct |
331 ms |
43896 KB |
Output is correct |
44 |
Correct |
339 ms |
44156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
380 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
1 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
29 |
Correct |
3 ms |
380 KB |
Output is correct |
30 |
Correct |
3 ms |
504 KB |
Output is correct |
31 |
Correct |
3 ms |
376 KB |
Output is correct |
32 |
Correct |
3 ms |
376 KB |
Output is correct |
33 |
Correct |
366 ms |
40312 KB |
Output is correct |
34 |
Correct |
396 ms |
39372 KB |
Output is correct |
35 |
Correct |
363 ms |
39928 KB |
Output is correct |
36 |
Correct |
376 ms |
39672 KB |
Output is correct |
37 |
Correct |
148 ms |
15736 KB |
Output is correct |
38 |
Correct |
148 ms |
15656 KB |
Output is correct |
39 |
Correct |
356 ms |
38272 KB |
Output is correct |
40 |
Correct |
398 ms |
38264 KB |
Output is correct |
41 |
Correct |
147 ms |
15736 KB |
Output is correct |
42 |
Correct |
228 ms |
29236 KB |
Output is correct |
43 |
Correct |
140 ms |
16120 KB |
Output is correct |
44 |
Correct |
340 ms |
43520 KB |
Output is correct |
45 |
Correct |
139 ms |
16124 KB |
Output is correct |
46 |
Correct |
142 ms |
16348 KB |
Output is correct |
47 |
Correct |
330 ms |
43896 KB |
Output is correct |
48 |
Correct |
342 ms |
44008 KB |
Output is correct |
49 |
Correct |
197 ms |
21240 KB |
Output is correct |
50 |
Correct |
194 ms |
21240 KB |
Output is correct |
51 |
Correct |
397 ms |
50336 KB |
Output is correct |
52 |
Correct |
387 ms |
49912 KB |
Output is correct |
53 |
Correct |
234 ms |
19448 KB |
Output is correct |
54 |
Correct |
282 ms |
33192 KB |
Output is correct |
55 |
Correct |
177 ms |
17144 KB |
Output is correct |
56 |
Correct |
405 ms |
45448 KB |
Output is correct |
57 |
Correct |
180 ms |
17912 KB |
Output is correct |
58 |
Correct |
205 ms |
18296 KB |
Output is correct |
59 |
Correct |
340 ms |
44024 KB |
Output is correct |