/// ... :(
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
const int NMAX = 5e5 + 5;
const int mod = 1e9 + 7;
int N, X[NMAX], Y[NMAX];
namespace SegmentTree
{
int N;
vector<double> lg, lgadd;
vector<int> aint, aintadd;
int sti, dri;
double lgval;
int val;
void B(int nod, int st, int dr)
{
lg[nod] = lgadd[nod] = 0;
aint[nod] = aintadd[nod] = 1;
if(st == dr) return;
int mij = st + (dr - st) / 2;
B(nod * 2, st, mij);
B(nod * 2 + 1, mij + 1, dr);
}
void init(int _N)
{
N = _N;
lg.resize(4 * N);
lgadd.reserve(4 * N);
aint.resize(4 * N);
aintadd.resize(4 * N);
B(1, 1, N);
}
void lazy(int nod)
{
double lgval = lgadd[nod];
int val = aintadd[nod];
lgadd[nod] = 0, aintadd[nod] = 1;
for(int i = 0; i <= 1; i++)
{
lg[nod * 2 + i] += lgval;
lgadd[nod * 2 + i] += lgval;
aint[nod * 2 + i] = (1LL * aint[nod * 2 + i] * val) % mod;
aintadd[nod * 2 + i] = (1LL * aintadd[nod * 2 + i] * val) % mod;
}
}
void U(int nod, int st, int dr)
{
if(sti <= st && dr <= dri)
{
lg[nod] += lgval;
lgadd[nod] += lgval;
aint[nod] = (1LL * aint[nod] * val) % mod;
aintadd[nod] = (1LL * aintadd[nod] * val) % mod;
return;
}
int mij = st + (dr - st) / 2;
lazy(nod);
if(sti <= mij) U(nod * 2, st, mij);
if(mij < dri) U(nod * 2 + 1, mij + 1, dr);
if(lg[nod * 2] > lg[nod * 2 + 1])
{
lg[nod] = lg[nod * 2];
aint[nod] = aint[nod * 2];
}
else
{
lg[nod] = lg[nod * 2 + 1];
aint[nod] = aint[nod * 2 + 1];
}
}
void update(int st, int dr, double mylg, int myval)
{
sti = st, dri = dr;
lgval = mylg;
val = myval;
U(1, 1, N);
}
}
int power(int x, int y)
{
if(x == 0) return 0;
if(y <= 0) return 1;
int ans = power( (1LL * x * x) % mod, y >> 1 );
if(y & 1) ans = (1LL * ans * x) % mod;
return ans;
}
int init(int _N, int _X[], int _Y[])
{
N = _N;
for(int i = 0; i < N; i++) X[i] = _X[i], Y[i] = _Y[i];
SegmentTree::init(N);
for(int i = 0; i < N; i++)
{
SegmentTree::update(i + 1, N, log2(X[i]), X[i]);
SegmentTree::update(i + 1, i + 1, log2(Y[i]), Y[i]);
}
return SegmentTree::aint[1];
}
int updateX(int pos, int val)
{
SegmentTree::update(pos + 1, N, -log2(X[pos]), power(X[pos], mod - 2));
X[pos] = val;
SegmentTree::update(pos + 1, N, log2(X[pos]), X[pos]);
return SegmentTree::aint[1];
}
int updateY(int pos, int val) {
SegmentTree::update(pos + 1, pos + 1, -log2(Y[pos]), power(Y[pos], mod - 2));
Y[pos] = val;
SegmentTree::update(pos + 1, pos + 1, log2(Y[pos]), Y[pos]);
return SegmentTree::aint[1];
}
Compilation message
horses.cpp: In function 'void SegmentTree::lazy(int)':
horses.cpp:46:16: warning: declaration of 'lgval' shadows a global declaration [-Wshadow]
double lgval = lgadd[nod];
^~~~~
horses.cpp:19:12: note: shadowed declaration is here
double lgval;
^~~~~
horses.cpp:47:14: warning: declaration of 'val' shadows a global declaration [-Wshadow]
int val = aintadd[nod];
^~~
horses.cpp:20:9: note: shadowed declaration is here
int val;
^~~
horses.cpp:54:65: warning: conversion to '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' from 'long long int' may alter its value [-Wconversion]
aint[nod * 2 + i] = (1LL * aint[nod * 2 + i] * val) % mod;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:55:71: warning: conversion to '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' from 'long long int' may alter its value [-Wconversion]
aintadd[nod * 2 + i] = (1LL * aintadd[nod * 2 + i] * val) % mod;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void SegmentTree::U(int, int, int)':
horses.cpp:65:49: warning: conversion to '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' from 'long long int' may alter its value [-Wconversion]
aint[nod] = (1LL * aint[nod] * val) % mod;
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:66:55: warning: conversion to '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' from 'long long int' may alter its value [-Wconversion]
aintadd[nod] = (1LL * aintadd[nod] * val) % mod;
~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int power(int, int)':
horses.cpp:101:36: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
int ans = power( (1LL * x * x) % mod, y >> 1 );
~~~~~~~~~~~~~~^~~~~
horses.cpp:102:39: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
if(y & 1) ans = (1LL * ans * x) % mod;
~~~~~~~~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
4 ms |
380 KB |
Output is correct |
24 |
Correct |
4 ms |
376 KB |
Output is correct |
25 |
Correct |
4 ms |
504 KB |
Output is correct |
26 |
Correct |
4 ms |
504 KB |
Output is correct |
27 |
Correct |
4 ms |
508 KB |
Output is correct |
28 |
Correct |
4 ms |
504 KB |
Output is correct |
29 |
Correct |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
4 ms |
504 KB |
Output is correct |
31 |
Correct |
4 ms |
504 KB |
Output is correct |
32 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
811 ms |
49284 KB |
Output is correct |
2 |
Correct |
899 ms |
49260 KB |
Output is correct |
3 |
Correct |
848 ms |
49272 KB |
Output is correct |
4 |
Correct |
871 ms |
49272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
380 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
380 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
4 ms |
504 KB |
Output is correct |
24 |
Correct |
4 ms |
504 KB |
Output is correct |
25 |
Correct |
4 ms |
508 KB |
Output is correct |
26 |
Correct |
4 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
504 KB |
Output is correct |
28 |
Correct |
4 ms |
504 KB |
Output is correct |
29 |
Correct |
4 ms |
376 KB |
Output is correct |
30 |
Correct |
4 ms |
504 KB |
Output is correct |
31 |
Correct |
4 ms |
376 KB |
Output is correct |
32 |
Correct |
4 ms |
504 KB |
Output is correct |
33 |
Correct |
671 ms |
48280 KB |
Output is correct |
34 |
Correct |
671 ms |
48376 KB |
Output is correct |
35 |
Correct |
692 ms |
48292 KB |
Output is correct |
36 |
Correct |
697 ms |
48304 KB |
Output is correct |
37 |
Correct |
657 ms |
48512 KB |
Output is correct |
38 |
Correct |
653 ms |
48376 KB |
Output is correct |
39 |
Correct |
629 ms |
48420 KB |
Output is correct |
40 |
Correct |
659 ms |
48376 KB |
Output is correct |
41 |
Correct |
645 ms |
48392 KB |
Output is correct |
42 |
Correct |
637 ms |
48376 KB |
Output is correct |
43 |
Correct |
666 ms |
48284 KB |
Output is correct |
44 |
Correct |
649 ms |
48376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
404 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
4 ms |
508 KB |
Output is correct |
24 |
Correct |
4 ms |
504 KB |
Output is correct |
25 |
Correct |
4 ms |
504 KB |
Output is correct |
26 |
Correct |
4 ms |
504 KB |
Output is correct |
27 |
Correct |
4 ms |
424 KB |
Output is correct |
28 |
Correct |
4 ms |
504 KB |
Output is correct |
29 |
Correct |
4 ms |
504 KB |
Output is correct |
30 |
Correct |
4 ms |
504 KB |
Output is correct |
31 |
Correct |
4 ms |
376 KB |
Output is correct |
32 |
Correct |
4 ms |
504 KB |
Output is correct |
33 |
Correct |
845 ms |
49372 KB |
Output is correct |
34 |
Correct |
915 ms |
49256 KB |
Output is correct |
35 |
Correct |
851 ms |
49392 KB |
Output is correct |
36 |
Correct |
881 ms |
49272 KB |
Output is correct |
37 |
Correct |
670 ms |
48376 KB |
Output is correct |
38 |
Correct |
679 ms |
48288 KB |
Output is correct |
39 |
Correct |
690 ms |
48288 KB |
Output is correct |
40 |
Correct |
689 ms |
48392 KB |
Output is correct |
41 |
Correct |
643 ms |
48416 KB |
Output is correct |
42 |
Correct |
670 ms |
48376 KB |
Output is correct |
43 |
Correct |
663 ms |
48496 KB |
Output is correct |
44 |
Correct |
663 ms |
48376 KB |
Output is correct |
45 |
Correct |
635 ms |
48376 KB |
Output is correct |
46 |
Correct |
643 ms |
48308 KB |
Output is correct |
47 |
Correct |
654 ms |
48280 KB |
Output is correct |
48 |
Correct |
646 ms |
48380 KB |
Output is correct |
49 |
Correct |
893 ms |
49784 KB |
Output is correct |
50 |
Correct |
888 ms |
49784 KB |
Output is correct |
51 |
Correct |
898 ms |
49944 KB |
Output is correct |
52 |
Correct |
914 ms |
49828 KB |
Output is correct |
53 |
Correct |
851 ms |
49656 KB |
Output is correct |
54 |
Correct |
808 ms |
49912 KB |
Output is correct |
55 |
Correct |
770 ms |
49036 KB |
Output is correct |
56 |
Correct |
815 ms |
49656 KB |
Output is correct |
57 |
Correct |
825 ms |
49796 KB |
Output is correct |
58 |
Correct |
823 ms |
49912 KB |
Output is correct |
59 |
Correct |
646 ms |
48696 KB |
Output is correct |