# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
62940 |
2018-07-31T01:59:07 Z |
updown1 |
Horses (IOI15_horses) |
C++17 |
|
783 ms |
44908 KB |
/*
segtree. Each element i stores (X[0]*X[1]*...*X[i]*Y[i])%MOD
*/
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, a, b) for(int i=a; i<b; i++)
#define ffi For(i, 0, N1)
#define ffj For(j, 0, P)
#define ffa ffi ffj
//#define s <<" "<<
//#define c <<" : "<<
#define w cout
#define e endl
#define pb push_back
#define mp make_pair
#define a first
#define b second
//#define int ll
const ll MAXN = 500000, MOD = 1000000007;
int N1;
ll tree[4*MAXN+1], lazy[4*MAXN+1], xx[MAXN], yy[MAXN];
ll mI(ll x, ll y) { /// call mI(x, MOD-2)
/// x^y
if (y == 0) return 1;
if (y == 1) return x;
ll p = mI(x, y/2);
p = (p*p)%MOD;
if (y%2 == 1) p = (p*x)%MOD;
return p;
}
void push(int x, int L, int R) {
tree[x] *= lazy[x];
tree[x] %= MOD;
if (L != R) {
lazy[x*2] *= lazy[x];
lazy[x*2] %= MOD;
lazy[x*2+1] *= lazy[x];
lazy[x*2+1] %= MOD;
}
lazy[x] = 1;
}
void update(int x, int L, int R, int oL, int oR, ll v) {
push(x, L, R);
if (R < oL || oR < L) return;
if (oL <= L && R <= oR) {
lazy[x] *= v;
lazy[x] %= MOD;
push(x, L, R);
return;
}
update(x*2, L, (L+R)/2, oL, oR, v);
update(x*2+1,(L+R)/2+1,R,oL, oR, v);
tree[x] = max(tree[x*2], tree[x*2+1]);
}
int answer() {
push(1, 0, N1-1);
assert(tree[1] > 0);
return tree[1];
}
int init(int N, int X[], int Y[]) {
N1 = N;
For (i, 0, 4*MAXN+1) tree[i] = lazy[i] = 1;
ffi xx[i] = X[i], yy[i] = Y[i];
ffi update(1, 0, N-1, i, N-1, X[i]), update(1, 0, N-1, i, i, Y[i]);
return answer();
}
int updateX(int pos, int val) {
//w<< pos << " " << val << " " << (mI(xx[pos], MOD-2)*xx[pos])%MOD<<e;
update(1, 0, N1-1, pos, N1-1, mI(xx[pos], MOD-2));
update(1, 0, N1-1, pos, N1-1, val);
xx[pos] = val;
return answer();
}
int updateY(int pos, int val) {
update(1, 0, N1-1, pos, pos, mI(yy[pos], MOD-2));
update(1, 0, N1-1, pos, pos, val);
yy[pos] = val;
return answer();
}
Compilation message
horses.cpp: In function 'int answer()':
horses.cpp:62:18: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return tree[1];
~~~~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
31608 KB |
Output is correct |
2 |
Correct |
29 ms |
31716 KB |
Output is correct |
3 |
Correct |
26 ms |
31716 KB |
Output is correct |
4 |
Correct |
25 ms |
31716 KB |
Output is correct |
5 |
Correct |
32 ms |
31716 KB |
Output is correct |
6 |
Correct |
28 ms |
31840 KB |
Output is correct |
7 |
Correct |
32 ms |
31840 KB |
Output is correct |
8 |
Correct |
31 ms |
32036 KB |
Output is correct |
9 |
Correct |
26 ms |
32036 KB |
Output is correct |
10 |
Correct |
30 ms |
32036 KB |
Output is correct |
11 |
Correct |
35 ms |
32036 KB |
Output is correct |
12 |
Correct |
35 ms |
32036 KB |
Output is correct |
13 |
Correct |
31 ms |
32036 KB |
Output is correct |
14 |
Correct |
28 ms |
32036 KB |
Output is correct |
15 |
Correct |
28 ms |
32036 KB |
Output is correct |
16 |
Correct |
28 ms |
32036 KB |
Output is correct |
17 |
Correct |
29 ms |
32036 KB |
Output is correct |
18 |
Correct |
36 ms |
32036 KB |
Output is correct |
19 |
Correct |
28 ms |
32036 KB |
Output is correct |
20 |
Correct |
30 ms |
32036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
32036 KB |
Output is correct |
2 |
Correct |
26 ms |
32036 KB |
Output is correct |
3 |
Correct |
26 ms |
32036 KB |
Output is correct |
4 |
Correct |
31 ms |
32036 KB |
Output is correct |
5 |
Correct |
28 ms |
32036 KB |
Output is correct |
6 |
Correct |
30 ms |
32036 KB |
Output is correct |
7 |
Correct |
33 ms |
32036 KB |
Output is correct |
8 |
Correct |
33 ms |
32036 KB |
Output is correct |
9 |
Correct |
29 ms |
32036 KB |
Output is correct |
10 |
Correct |
28 ms |
32036 KB |
Output is correct |
11 |
Correct |
30 ms |
32036 KB |
Output is correct |
12 |
Correct |
30 ms |
32036 KB |
Output is correct |
13 |
Correct |
28 ms |
32036 KB |
Output is correct |
14 |
Correct |
27 ms |
32036 KB |
Output is correct |
15 |
Correct |
29 ms |
32036 KB |
Output is correct |
16 |
Correct |
30 ms |
32036 KB |
Output is correct |
17 |
Correct |
26 ms |
32036 KB |
Output is correct |
18 |
Correct |
25 ms |
32036 KB |
Output is correct |
19 |
Correct |
29 ms |
32036 KB |
Output is correct |
20 |
Correct |
31 ms |
32036 KB |
Output is correct |
21 |
Incorrect |
29 ms |
32036 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
783 ms |
44908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
44908 KB |
Output is correct |
2 |
Correct |
25 ms |
44908 KB |
Output is correct |
3 |
Correct |
26 ms |
44908 KB |
Output is correct |
4 |
Correct |
29 ms |
44908 KB |
Output is correct |
5 |
Correct |
28 ms |
44908 KB |
Output is correct |
6 |
Correct |
28 ms |
44908 KB |
Output is correct |
7 |
Correct |
29 ms |
44908 KB |
Output is correct |
8 |
Correct |
25 ms |
44908 KB |
Output is correct |
9 |
Correct |
32 ms |
44908 KB |
Output is correct |
10 |
Correct |
30 ms |
44908 KB |
Output is correct |
11 |
Correct |
29 ms |
44908 KB |
Output is correct |
12 |
Correct |
26 ms |
44908 KB |
Output is correct |
13 |
Correct |
26 ms |
44908 KB |
Output is correct |
14 |
Correct |
27 ms |
44908 KB |
Output is correct |
15 |
Correct |
26 ms |
44908 KB |
Output is correct |
16 |
Correct |
32 ms |
44908 KB |
Output is correct |
17 |
Correct |
31 ms |
44908 KB |
Output is correct |
18 |
Correct |
26 ms |
44908 KB |
Output is correct |
19 |
Correct |
26 ms |
44908 KB |
Output is correct |
20 |
Correct |
33 ms |
44908 KB |
Output is correct |
21 |
Incorrect |
29 ms |
44908 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
44908 KB |
Output is correct |
2 |
Correct |
30 ms |
44908 KB |
Output is correct |
3 |
Correct |
30 ms |
44908 KB |
Output is correct |
4 |
Correct |
28 ms |
44908 KB |
Output is correct |
5 |
Correct |
27 ms |
44908 KB |
Output is correct |
6 |
Correct |
29 ms |
44908 KB |
Output is correct |
7 |
Correct |
28 ms |
44908 KB |
Output is correct |
8 |
Correct |
28 ms |
44908 KB |
Output is correct |
9 |
Correct |
31 ms |
44908 KB |
Output is correct |
10 |
Correct |
36 ms |
44908 KB |
Output is correct |
11 |
Correct |
26 ms |
44908 KB |
Output is correct |
12 |
Correct |
26 ms |
44908 KB |
Output is correct |
13 |
Correct |
26 ms |
44908 KB |
Output is correct |
14 |
Correct |
26 ms |
44908 KB |
Output is correct |
15 |
Correct |
26 ms |
44908 KB |
Output is correct |
16 |
Correct |
25 ms |
44908 KB |
Output is correct |
17 |
Correct |
40 ms |
44908 KB |
Output is correct |
18 |
Correct |
28 ms |
44908 KB |
Output is correct |
19 |
Correct |
30 ms |
44908 KB |
Output is correct |
20 |
Correct |
26 ms |
44908 KB |
Output is correct |
21 |
Incorrect |
31 ms |
44908 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |