# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
670096 |
2022-12-08T06:17:38 Z |
Astrayt |
Horses (IOI15_horses) |
C++17 |
|
505 ms |
113732 KB |
#include <bits/stdc++.h>
using namespace std;
#define starburst ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define int long long
#define double long double
#define pii pair<int,int>
#define pb push_back
#define maxn 500005
#define mod 1000000007ll
#define ff first
#define ss second
int N;
vector<int> X, Y;
vector<double> lgX, lgY, PlgX;
int fastpow(int a, int b){
int ret = 1;
for(; b; b >>= 1){
if(b & 1) ret = 1ll * ret * a % mod;
a = 1ll * a * a % mod;
}
return ret;
}
struct FenwickTree{
int val[maxn];
void init(int n){
for(int i = 1; i <= n; ++i) val[i] = 1;
}
void modify(int p, int x){
for(; p < maxn; p += (p & -p)) val[p] = 1ll * x * val[p] % mod;
}
int query(int p){
int ret = 1;
for(; p; p -= (p & -p)){
ret = 1ll * ret * val[p] % mod;
}
return ret;
}
}bit;
struct SegmentTree{
pair<double, int> node[4 * maxn];
double tag[4 * maxn];
void push(int i){
double t = tag[i];
node[2 * i].ff += t, tag[2 * i] += t;
node[2 * i + 1].ff += t, tag[2 * i + 1] += t;
tag[i] = 0;
node[i] = max(node[2 * i], node[2 * i + 1]);
}
void modify(int i, int l, int r, int ql, int qr, double x){
if(l == r){
node[i].ff += x;
node[i].ss = l;
return;
}
push(i);
if(ql <= l && r <= qr){
node[i].ff += x;
tag[i] += x;
return;
}
int mid = (l + r) / 2;
if(ql <= mid) modify(2 * i, l, mid, ql, qr, x);
if(mid < qr) modify(2 * i + 1, mid + 1, r, ql, qr, x);
node[i] = max(node[2 * i], node[2 * i + 1]);
}
}seg;
int init(int n, int *x, int *y){
N = n;
bit.init(n);
X.assign(N + 1, 0), Y.assign(N + 1, 0);
lgX.assign(N + 1, 0.0), lgY.assign(N + 1, 0.0), PlgX.assign(N + 1, 0.0);
for(int i = 1; i <= n; ++i){
X[i] = x[i - 1], Y[i] = y[i - 1];
lgX[i] = log(X[i]), lgY[i] = log(Y[i]);
PlgX[i] = PlgX[i - 1] + lgX[i];
bit.modify(i, X[i]);
seg.modify(1, 1, N, i, i, PlgX[i] + lgY[i]);
}
int id = seg.node[1].ss;
int BX = bit.query(id);
return 1ll * BX * Y[id] % mod;
}
int updateX(int pos, int val){
bit.modify(pos, fastpow(X[pos], mod - 2));
bit.modify(pos, val);
seg.modify(1, 1, N, pos, N, -lgX[pos]);
X[pos] = val;
lgX[pos] = log(val);
seg.modify(1, 1, N, pos, N, lgX[pos]);
int id = seg.node[1].ss;
int BX = bit.query(id);
return 1ll * BX * Y[id] % mod;
}
int updateY(int pos, int val){
seg.modify(1, 1, N, pos, pos, -lgY[pos]);
Y[pos] = val;
lgY[pos] = log(val);
seg.modify(1, 1, N, pos, N, lgY[pos]);
int id = seg.node[1].ss;
int BX = bit.query(id);
return 1ll * BX * Y[id] % mod;
}
Compilation message
horses.cpp: In function 'int fastpow(int, int)':
horses.cpp:20:39: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
20 | if(b & 1) ret = 1ll * ret * a % mod;
| ^
horses.cpp:21:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
21 | a = 1ll * a * a % mod;
| ^
horses.cpp: In member function 'void FenwickTree::modify(int, int)':
horses.cpp:32:66: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
32 | for(; p < maxn; p += (p & -p)) val[p] = 1ll * x * val[p] % mod;
| ^
horses.cpp: In member function 'int FenwickTree::query(int)':
horses.cpp:37:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
37 | ret = 1ll * ret * val[p] % mod;
| ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:86:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
86 | return 1ll * BX * Y[id] % mod;
| ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:98:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
98 | return 1ll * BX * Y[id] % mod;
| ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:108:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
108 | return 1ll * BX * Y[id] % mod;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
62924 KB |
Output is correct |
2 |
Correct |
25 ms |
62884 KB |
Output is correct |
3 |
Correct |
25 ms |
62936 KB |
Output is correct |
4 |
Correct |
26 ms |
62908 KB |
Output is correct |
5 |
Correct |
25 ms |
62932 KB |
Output is correct |
6 |
Correct |
26 ms |
62984 KB |
Output is correct |
7 |
Correct |
30 ms |
62972 KB |
Output is correct |
8 |
Correct |
25 ms |
62868 KB |
Output is correct |
9 |
Correct |
26 ms |
62912 KB |
Output is correct |
10 |
Correct |
25 ms |
62928 KB |
Output is correct |
11 |
Correct |
31 ms |
62840 KB |
Output is correct |
12 |
Correct |
26 ms |
62932 KB |
Output is correct |
13 |
Correct |
26 ms |
62932 KB |
Output is correct |
14 |
Correct |
28 ms |
62932 KB |
Output is correct |
15 |
Correct |
35 ms |
62944 KB |
Output is correct |
16 |
Correct |
26 ms |
62924 KB |
Output is correct |
17 |
Correct |
29 ms |
62840 KB |
Output is correct |
18 |
Correct |
26 ms |
62988 KB |
Output is correct |
19 |
Correct |
29 ms |
62956 KB |
Output is correct |
20 |
Correct |
26 ms |
62880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
62932 KB |
Output is correct |
2 |
Correct |
31 ms |
62896 KB |
Output is correct |
3 |
Correct |
27 ms |
62932 KB |
Output is correct |
4 |
Correct |
27 ms |
62860 KB |
Output is correct |
5 |
Correct |
25 ms |
62976 KB |
Output is correct |
6 |
Correct |
26 ms |
62876 KB |
Output is correct |
7 |
Correct |
27 ms |
62836 KB |
Output is correct |
8 |
Correct |
25 ms |
62940 KB |
Output is correct |
9 |
Correct |
29 ms |
62952 KB |
Output is correct |
10 |
Correct |
26 ms |
62932 KB |
Output is correct |
11 |
Correct |
25 ms |
62844 KB |
Output is correct |
12 |
Correct |
25 ms |
62856 KB |
Output is correct |
13 |
Correct |
25 ms |
62880 KB |
Output is correct |
14 |
Correct |
26 ms |
62944 KB |
Output is correct |
15 |
Correct |
24 ms |
62932 KB |
Output is correct |
16 |
Correct |
25 ms |
62944 KB |
Output is correct |
17 |
Correct |
25 ms |
62932 KB |
Output is correct |
18 |
Correct |
25 ms |
62888 KB |
Output is correct |
19 |
Correct |
26 ms |
62956 KB |
Output is correct |
20 |
Correct |
25 ms |
62948 KB |
Output is correct |
21 |
Incorrect |
25 ms |
62896 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
505 ms |
113732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
62924 KB |
Output is correct |
2 |
Correct |
25 ms |
62912 KB |
Output is correct |
3 |
Correct |
24 ms |
62920 KB |
Output is correct |
4 |
Correct |
28 ms |
62956 KB |
Output is correct |
5 |
Correct |
25 ms |
62984 KB |
Output is correct |
6 |
Correct |
25 ms |
62968 KB |
Output is correct |
7 |
Correct |
25 ms |
62944 KB |
Output is correct |
8 |
Correct |
26 ms |
62932 KB |
Output is correct |
9 |
Correct |
26 ms |
62932 KB |
Output is correct |
10 |
Correct |
26 ms |
62860 KB |
Output is correct |
11 |
Correct |
25 ms |
62860 KB |
Output is correct |
12 |
Correct |
25 ms |
62924 KB |
Output is correct |
13 |
Correct |
25 ms |
62944 KB |
Output is correct |
14 |
Correct |
26 ms |
62852 KB |
Output is correct |
15 |
Correct |
25 ms |
62936 KB |
Output is correct |
16 |
Correct |
25 ms |
62932 KB |
Output is correct |
17 |
Correct |
24 ms |
62968 KB |
Output is correct |
18 |
Correct |
24 ms |
62924 KB |
Output is correct |
19 |
Correct |
25 ms |
62932 KB |
Output is correct |
20 |
Correct |
25 ms |
62868 KB |
Output is correct |
21 |
Incorrect |
26 ms |
62856 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
62892 KB |
Output is correct |
2 |
Correct |
24 ms |
62876 KB |
Output is correct |
3 |
Correct |
24 ms |
62932 KB |
Output is correct |
4 |
Correct |
26 ms |
62924 KB |
Output is correct |
5 |
Correct |
25 ms |
62932 KB |
Output is correct |
6 |
Correct |
25 ms |
62908 KB |
Output is correct |
7 |
Correct |
25 ms |
62932 KB |
Output is correct |
8 |
Correct |
24 ms |
62888 KB |
Output is correct |
9 |
Correct |
25 ms |
62860 KB |
Output is correct |
10 |
Correct |
25 ms |
62924 KB |
Output is correct |
11 |
Correct |
25 ms |
62920 KB |
Output is correct |
12 |
Correct |
25 ms |
62912 KB |
Output is correct |
13 |
Correct |
27 ms |
62972 KB |
Output is correct |
14 |
Correct |
29 ms |
62920 KB |
Output is correct |
15 |
Correct |
25 ms |
62884 KB |
Output is correct |
16 |
Correct |
27 ms |
62968 KB |
Output is correct |
17 |
Correct |
25 ms |
62968 KB |
Output is correct |
18 |
Correct |
25 ms |
62888 KB |
Output is correct |
19 |
Correct |
25 ms |
62952 KB |
Output is correct |
20 |
Correct |
26 ms |
62920 KB |
Output is correct |
21 |
Incorrect |
26 ms |
62852 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |