# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
572141 |
2022-06-03T18:44:12 Z |
beaconmc |
Horses (IOI15_horses) |
C++14 |
|
455 ms |
87572 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
#define double long double
#define SIZE 1048576
#define HSIZE 524288
#define MOD 1000000007
// #include "horses.h"
using namespace std;
vector<ll> x, y, xx, yy;
ll n;
ll tree[SIZE];
ll tree2[SIZE];
set<vector<ll>> ranges;
void update(ll a,ll b){
a += HSIZE;
tree[a] = b;
while (a>1){
a/=2;
tree[a] = tree[a*2]*tree[a*2+1]%MOD;
}
}
void update2(ll a,ll b){
a += HSIZE;
tree2[a] = b;
while (a>1){
a/=2;
tree2[a] = max(tree2[a*2], tree2[a*2+1]);
}
}
ll query(ll a, ll b){
a += HSIZE;
b += HSIZE;
ll maxi = 1;
while (a<=b){
if (a%2==1){
maxi *= tree[a++];
maxi %= MOD;
}
if (b%2==0){
maxi *= tree[b--];
maxi %= MOD;
}
a/=2; b/=2;
}
return maxi;
}
ll query2(ll a, ll b){
a += HSIZE;
b += HSIZE;
ll maxi = 0;
while (a<=b){
if (a%2==1){
maxi = max(maxi, tree2[a++]);
}
if (b%2==0){
maxi = max(maxi, tree2[b--]);
}
a/=2; b/=2;
}
return maxi;
}
int solve(){
vector<ll> xx;
vector<ll> yy;
vector<ll> pos;
ll cur = 31;
auto it = ranges.end();
while (cur--){
it--;
xx.push_back(x[(*it)[0]]);
yy.push_back(query2((*it)[0], (*it)[1]));
pos.push_back((*it)[0]);
if (it==ranges.begin()){
break;
}
}
reverse(xx.begin(), xx.end());
reverse(yy.begin(), yy.end());
reverse(pos.begin(), pos.end());
cur = 1;
ll maxsum = 1;
ll maxpos = -1;
FOR(i,0, xx.size()){
cur *= xx[i];
if (cur >= (maxsum-1)/yy[i]+1){
cur = 1;
maxsum = yy[i];
maxpos = i;
}
}
int realsus = (query(0, pos[maxpos]) * maxsum) % 1000000007;
return realsus;
}
int init(int N, int X[], int Y[]) {
n = N;
FOR(i,0,N){
x.push_back(X[i]);
update(i, X[i]);
y.push_back(Y[i]);
update2(i, Y[i]);
}
ll prev = -1;
FORNEG(i, n-1, -1){
if (x[i] == 1 && prev==-1){
prev = i;
}
if (x[i] != 1){
if (prev != -1){
ranges.insert({i, prev});
prev = -1;
}else{
ranges.insert({i,i});
}
}
}
if (prev != -1){
ranges.insert({0, prev});
}
return solve();
}
int updateX(int pos, int val) {
if (x[pos] == val) return solve();
update(pos, val);
if (pos!=0){
if (x[pos] == 1 && val != 1){
auto it = ranges.upper_bound({pos, 9999999999});
it--;
vector<ll> first = *it;
ranges.insert({first[0], pos-1});
ranges.insert({pos, first[1]});
ranges.erase(it);
}
if (x[pos] != 1 && val == 1){
auto it = ranges.upper_bound({pos, 9999999999});
it--;
vector<ll> first = *it;
it --;
vector<ll> second = *it;
ranges.erase(first);ranges.erase(second);
ranges.insert({second[0], first[1]});
}
}
x[pos] = val;
return solve();
}
int updateY(int pos, int val) {
update2(pos, val);
y[pos] = val;
return solve();
}
Compilation message
horses.cpp: In function 'int solve()':
horses.cpp:78:13: warning: declaration of 'xx' shadows a global declaration [-Wshadow]
78 | vector<ll> xx;
| ^~
horses.cpp:14:18: note: shadowed declaration is here
14 | vector<ll> x, y, xx, yy;
| ^~
horses.cpp:79:13: warning: declaration of 'yy' shadows a global declaration [-Wshadow]
79 | vector<ll> yy;
| ^~
horses.cpp:14:22: note: shadowed declaration is here
14 | vector<ll> x, y, xx, yy;
| ^~
horses.cpp:5:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
102 | FOR(i,0, xx.size()){
| ~~~~~~~~~~~~~~
horses.cpp:102:2: note: in expansion of macro 'FOR'
102 | FOR(i,0, xx.size()){
| ^~~
horses.cpp:112:49: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
112 | int realsus = (query(0, pos[maxpos]) * maxsum) % 1000000007;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
568 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
363 ms |
75708 KB |
Output is correct |
2 |
Correct |
406 ms |
75712 KB |
Output is correct |
3 |
Correct |
376 ms |
75616 KB |
Output is correct |
4 |
Correct |
383 ms |
75792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
118 ms |
27984 KB |
Output is correct |
34 |
Correct |
114 ms |
28096 KB |
Output is correct |
35 |
Correct |
289 ms |
74768 KB |
Output is correct |
36 |
Correct |
277 ms |
74788 KB |
Output is correct |
37 |
Correct |
113 ms |
27988 KB |
Output is correct |
38 |
Correct |
183 ms |
51960 KB |
Output is correct |
39 |
Correct |
98 ms |
27904 KB |
Output is correct |
40 |
Correct |
265 ms |
74808 KB |
Output is correct |
41 |
Correct |
102 ms |
27940 KB |
Output is correct |
42 |
Correct |
109 ms |
28020 KB |
Output is correct |
43 |
Correct |
249 ms |
74732 KB |
Output is correct |
44 |
Correct |
246 ms |
74688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
358 ms |
75716 KB |
Output is correct |
34 |
Correct |
398 ms |
76532 KB |
Output is correct |
35 |
Correct |
377 ms |
76584 KB |
Output is correct |
36 |
Correct |
384 ms |
76572 KB |
Output is correct |
37 |
Correct |
128 ms |
29060 KB |
Output is correct |
38 |
Correct |
115 ms |
28896 KB |
Output is correct |
39 |
Correct |
274 ms |
75692 KB |
Output is correct |
40 |
Correct |
281 ms |
75628 KB |
Output is correct |
41 |
Correct |
113 ms |
28836 KB |
Output is correct |
42 |
Correct |
182 ms |
52576 KB |
Output is correct |
43 |
Correct |
102 ms |
28836 KB |
Output is correct |
44 |
Correct |
271 ms |
75648 KB |
Output is correct |
45 |
Correct |
104 ms |
28900 KB |
Output is correct |
46 |
Correct |
109 ms |
30116 KB |
Output is correct |
47 |
Correct |
254 ms |
81228 KB |
Output is correct |
48 |
Correct |
250 ms |
80964 KB |
Output is correct |
49 |
Correct |
300 ms |
36052 KB |
Output is correct |
50 |
Correct |
256 ms |
35988 KB |
Output is correct |
51 |
Correct |
412 ms |
87572 KB |
Output is correct |
52 |
Correct |
408 ms |
87044 KB |
Output is correct |
53 |
Correct |
284 ms |
34188 KB |
Output is correct |
54 |
Correct |
320 ms |
60836 KB |
Output is correct |
55 |
Correct |
170 ms |
31024 KB |
Output is correct |
56 |
Correct |
455 ms |
82456 KB |
Output is correct |
57 |
Correct |
204 ms |
31688 KB |
Output is correct |
58 |
Correct |
245 ms |
32164 KB |
Output is correct |
59 |
Correct |
263 ms |
81100 KB |
Output is correct |