# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
219607 |
2020-04-05T17:24:16 Z |
summitwei |
Horses (IOI15_horses) |
C++17 |
|
1010 ms |
65692 KB |
#include <bits/stdc++.h>
#include <horses.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (ll i=(a); i >= b; i--)
#define MN 500005
int n;
ll a[MN];
ll b[MN];
ll tree[2][4*MN];
void upd(int node, int a, int b, int i, ll val, int tp){
if(a > i || b < i) return;
if(a == b){
tree[tp][node] = val;
return;
}
int mid = (a+b)/2;
upd(node*2, a, mid, i, val, tp);
upd(node*2+1, 1+mid, b, i, val, tp);
if(tp == 0) tree[tp][node] = max(tree[tp][node*2], tree[tp][node*2+1]);
else tree[tp][node] = (tree[tp][node*2]*tree[tp][node*2+1])%MOD;
}
ll que(int node, int a, int b, int i, int j, int tp){
if(a > j || b < i || j < i) return 1;
if(i <= a && b <= j) return tree[tp][node];
int mid = (a+b)/2;
ll q1 = que(node*2, a, mid, i, j, tp);
ll q2 = que(node*2+1, 1+mid, b, i, j, tp);
if(tp == 0) return max(q1, q2);
else return (q1*q2)%MOD;
}
set<int, greater<int> > hmm;
ll calc(){
hmm.insert(1); //1 as 1 might be relevant
ll res = 0;
int pv = n+1;
for(auto cur : hmm){
//cout << "checking " << cur << " " << pv-1 << " range\n";
res = max(res, que(1, 1, n, cur, pv-1, 0));
res = res*a[cur];
//cout << "res now " << res << "\n";
if(res > MOD){
res %= MOD;
ll ot = que(1, 1, n, 1, cur-1, 1);
return (res*ot)%MOD;
}
pv = cur;
}
return res;
}
int init(int N, int x[], int y[]){
n = N;
F0R(i, n){
upd(1, 1, n, i+1, x[i], 1);
upd(1, 1, n, i+1, y[i], 0);
if(x[i] != 1) hmm.insert(i+1);
a[i+1] = x[i]; b[i+1] = y[i];
}
return (int)calc();
}
int updateX(int pos, int val){
++pos;
if(a[pos] == 1 && val != 1) hmm.insert(pos);
else if(a[pos] != 1 && val == 1) hmm.erase(pos);
a[pos] = val;
upd(1, 1, n, pos, val, 1);
return (int)calc();
}
int updateY(int pos, int val){
++pos;
b[pos] = val;
upd(1, 1, n, pos, val, 0);
return (int)calc();
}
/*int main(){
//ios_base::sync_with_stdio(false);
//cin.tie(0);
int n, m;
cin >> n;
int x[n], y[n];
F0R(i, n) cin >> x[i];
F0R(i, n) cin >> y[i];
cout << init(n, x, y) << "\n";
cin >> m;
F0R(i, m){
int c, pos, val;
cin >> c >> pos >> val;
if(c == 0){
cout << updateX(pos, val) << "\n";
} else{
cout << updateY(pos, val) << "\n";
}
}
return 0;
}*/
Compilation message
horses.cpp: In function 'void upd(int, int, int, int, ll, int)':
horses.cpp:29:55: warning: declaration of 'b' shadows a global declaration [-Wshadow]
void upd(int node, int a, int b, int i, ll val, int tp){
^
horses.cpp:26:4: note: shadowed declaration is here
ll b[MN];
^
horses.cpp:29:55: warning: declaration of 'a' shadows a global declaration [-Wshadow]
void upd(int node, int a, int b, int i, ll val, int tp){
^
horses.cpp:25:4: note: shadowed declaration is here
ll a[MN];
^
horses.cpp: In function 'll que(int, int, int, int, int, int)':
horses.cpp:41:52: warning: declaration of 'b' shadows a global declaration [-Wshadow]
ll que(int node, int a, int b, int i, int j, int tp){
^
horses.cpp:26:4: note: shadowed declaration is here
ll b[MN];
^
horses.cpp:41:52: warning: declaration of 'a' shadows a global declaration [-Wshadow]
ll que(int node, int a, int b, int i, int j, int tp){
^
horses.cpp:25:4: note: shadowed declaration is here
ll a[MN];
^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:76:23: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
upd(1, 1, n, i+1, x[i], 1);
~^~
horses.cpp:77:23: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
upd(1, 1, n, i+1, y[i], 0);
~^~
horses.cpp:78:35: warning: conversion to 'std::set<int, std::greater<int> >::value_type {aka int}' from 'll {aka long long int}' may alter its value [-Wconversion]
if(x[i] != 1) hmm.insert(i+1);
~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
6 ms |
640 KB |
Output is correct |
24 |
Correct |
6 ms |
512 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
9 ms |
512 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
7 ms |
512 KB |
Output is correct |
32 |
Correct |
9 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
950 ms |
53880 KB |
Output is correct |
2 |
Correct |
522 ms |
65656 KB |
Output is correct |
3 |
Correct |
531 ms |
56824 KB |
Output is correct |
4 |
Correct |
511 ms |
60792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
512 KB |
Output is correct |
24 |
Correct |
5 ms |
512 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
9 ms |
512 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
6 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
8 ms |
384 KB |
Output is correct |
32 |
Correct |
8 ms |
384 KB |
Output is correct |
33 |
Correct |
272 ms |
32940 KB |
Output is correct |
34 |
Correct |
271 ms |
32636 KB |
Output is correct |
35 |
Correct |
451 ms |
63100 KB |
Output is correct |
36 |
Correct |
425 ms |
62968 KB |
Output is correct |
37 |
Correct |
334 ms |
30968 KB |
Output is correct |
38 |
Correct |
330 ms |
43640 KB |
Output is correct |
39 |
Correct |
272 ms |
30728 KB |
Output is correct |
40 |
Correct |
394 ms |
57976 KB |
Output is correct |
41 |
Correct |
287 ms |
30584 KB |
Output is correct |
42 |
Correct |
311 ms |
30712 KB |
Output is correct |
43 |
Correct |
409 ms |
58360 KB |
Output is correct |
44 |
Correct |
416 ms |
58496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
7 ms |
512 KB |
Output is correct |
24 |
Correct |
6 ms |
512 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
9 ms |
512 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
9 ms |
384 KB |
Output is correct |
32 |
Correct |
9 ms |
512 KB |
Output is correct |
33 |
Correct |
888 ms |
56824 KB |
Output is correct |
34 |
Correct |
553 ms |
65692 KB |
Output is correct |
35 |
Correct |
556 ms |
56700 KB |
Output is correct |
36 |
Correct |
545 ms |
60844 KB |
Output is correct |
37 |
Correct |
267 ms |
32592 KB |
Output is correct |
38 |
Correct |
267 ms |
32632 KB |
Output is correct |
39 |
Correct |
441 ms |
62968 KB |
Output is correct |
40 |
Correct |
403 ms |
62968 KB |
Output is correct |
41 |
Correct |
344 ms |
30840 KB |
Output is correct |
42 |
Correct |
338 ms |
43768 KB |
Output is correct |
43 |
Correct |
247 ms |
30584 KB |
Output is correct |
44 |
Correct |
397 ms |
58232 KB |
Output is correct |
45 |
Correct |
283 ms |
30584 KB |
Output is correct |
46 |
Correct |
305 ms |
30840 KB |
Output is correct |
47 |
Correct |
406 ms |
58424 KB |
Output is correct |
48 |
Correct |
411 ms |
58488 KB |
Output is correct |
49 |
Correct |
398 ms |
35704 KB |
Output is correct |
50 |
Correct |
374 ms |
35832 KB |
Output is correct |
51 |
Correct |
577 ms |
64888 KB |
Output is correct |
52 |
Correct |
484 ms |
64376 KB |
Output is correct |
53 |
Correct |
1010 ms |
34040 KB |
Output is correct |
54 |
Correct |
529 ms |
47584 KB |
Output is correct |
55 |
Correct |
361 ms |
31608 KB |
Output is correct |
56 |
Correct |
514 ms |
59900 KB |
Output is correct |
57 |
Correct |
629 ms |
32248 KB |
Output is correct |
58 |
Correct |
836 ms |
32760 KB |
Output is correct |
59 |
Correct |
405 ms |
58360 KB |
Output is correct |