//#include "horses.h"
#include <vector>
#define ll long long
#define MOD 1000000007
using namespace std;
struct num
{
ll a; ll b;
num(ll x, ll y): a(x), b(y) {};
void operator*=(ll x)
{
a *= x;
b *= x;
if(b >= MOD)
{
b %= MOD;
++a;
}
}
bool operator<(const num &n) const
{
if(a != n.a) return a < n.a;
else return b < n.b;
}
};
vector<num> mult;
vector<ll> x, y;
int ans()
{
num maxVal(0, 0);
for(int i = 0; i < mult.size(); i++)
{
num tmp = mult[i];
tmp *= y[i];
maxVal = max(maxVal, tmp);
}
return maxVal.b;
}
int init(int N, int X[], int Y[])
{
mult.assign(N, num(0, 0));
mult[0].b = X[0];
x.assign(N, 0);
x[0] = X[0];
y.assign(N, 0);
y[0] = Y[0];
for(int i = 1; i < N; i++)
{
y[i] = (ll)Y[i];
x[i] = (ll)X[i];
num tmp = mult[i - 1];
tmp *= x[i];
mult[i] = tmp;
}
return ans();
}
int updateX(int pos, int val)
{
x[pos] = (ll)val;
if(!pos)
{
mult[0].b = x[0];
pos++;
}
for(int i = pos; i < mult.size(); i++)
{
num tmp = mult[i - 1];
tmp *= x[i];
mult[i] = tmp;
}
return ans();
}
int updateY(int pos, int val)
{
y[pos] = (ll)val;
return ans();
}
Compilation message
horses.cpp: In function 'int ans()':
horses.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<num>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i = 0; i < mult.size(); i++)
| ~~^~~~~~~~~~~~~
horses.cpp:44:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
44 | return maxVal.b;
| ~~~~~~~^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:79:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<num>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i = pos; i < mult.size(); i++)
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
288 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
288 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
292 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
288 KB |
Output is correct |
14 |
Correct |
0 ms |
292 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
292 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
288 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
288 KB |
Output is correct |
22 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1557 ms |
19872 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
288 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
284 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
292 KB |
Output is correct |
17 |
Correct |
1 ms |
284 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
288 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Incorrect |
0 ms |
292 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |