# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
572140 |
2022-06-03T18:41:57 Z |
beaconmc |
Horses (IOI15_horses) |
C++14 |
|
388 ms |
81208 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/yy[i]){
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 |
1 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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
392 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 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 |
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 |
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 |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
4 ms |
468 KB |
Output is correct |
24 |
Correct |
3 ms |
448 KB |
Output is correct |
25 |
Correct |
2 ms |
580 KB |
Output is correct |
26 |
Correct |
2 ms |
576 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
3 ms |
580 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
388 ms |
75592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 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 |
1 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 |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 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 |
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 |
596 KB |
Output is correct |
26 |
Correct |
2 ms |
600 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
4 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
3 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
448 KB |
Output is correct |
32 |
Correct |
2 ms |
476 KB |
Output is correct |
33 |
Correct |
128 ms |
28932 KB |
Output is correct |
34 |
Correct |
124 ms |
28980 KB |
Output is correct |
35 |
Correct |
292 ms |
75616 KB |
Output is correct |
36 |
Correct |
295 ms |
75652 KB |
Output is correct |
37 |
Correct |
121 ms |
28876 KB |
Output is correct |
38 |
Correct |
186 ms |
52628 KB |
Output is correct |
39 |
Correct |
107 ms |
28836 KB |
Output is correct |
40 |
Correct |
278 ms |
75740 KB |
Output is correct |
41 |
Correct |
112 ms |
28988 KB |
Output is correct |
42 |
Correct |
118 ms |
30064 KB |
Output is correct |
43 |
Correct |
270 ms |
81208 KB |
Output is correct |
44 |
Correct |
260 ms |
81024 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 |
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 |
1 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 |
1 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 |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
444 KB |
Output is correct |
24 |
Correct |
3 ms |
468 KB |
Output is correct |
25 |
Correct |
4 ms |
596 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
2 ms |
448 KB |
Output is correct |
28 |
Correct |
3 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
3 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Incorrect |
379 ms |
76492 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |