Submission #587504

# Submission time Handle Problem Language Result Execution time Memory
587504 2022-07-02T03:04:55 Z benson1029 Horses (IOI15_horses) C++14
100 / 100
525 ms 74792 KB
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;

long long mod = 1e9+7;
long double seglog[2000005];
long long segmul[2000005];
long double lzylog[2000005];
long long lzymul[2000005];
int n;
long long x[500005], y[500005];

long long fpw(long long n, long long p) {
	if(p==0) return 1LL;
	long long t = fpw(n, p/2);
	t = (t*t) % mod;
	if(p%2) t = (t*n) % mod;
	return t;
}

long long inv(long long n) {
	return fpw(n, mod-2);
}

void push(int x) {
	seglog[x*2] += lzylog[x];
	seglog[x*2+1] += lzylog[x];
	lzylog[x*2] += lzylog[x];
	lzylog[x*2+1] += lzylog[x];
	lzylog[x] = 0;
	segmul[x*2] = (segmul[x*2] * lzymul[x]) % mod;
	segmul[x*2+1] = (segmul[x*2+1] * lzymul[x]) % mod;
	lzymul[x*2] = (lzymul[x*2] * lzymul[x]) % mod;
	lzymul[x*2+1] = (lzymul[x*2+1] * lzymul[x]) % mod;
	lzymul[x] = 1;
}

void seg_set(int x, int l, int r, int pos, int val, long double LOG) {
	if(l==r) {
		segmul[x] = val;
		seglog[x] = LOG;
	} else {
		if(pos <= (l+r)/2) seg_set(x*2, l, (l+r)/2, pos, val, LOG);
		else seg_set(x*2+1, (l+r)/2+1, r, pos, val, LOG);
		if(seglog[x*2] > seglog[x*2+1]) {
			seglog[x] = seglog[x*2];
			segmul[x] = segmul[x*2];
		} else {
			seglog[x] = seglog[x*2+1];
			segmul[x] = segmul[x*2+1];
		}
	}
}

void seg_upd(int x, int l, int r, int ll, int rr, long long val, long double LOG) {
	if(l!=r) push(x);
	if(ll <= l && r <= rr) {
		seglog[x] += LOG;
		segmul[x] = (segmul[x] * val) % mod;
		lzylog[x] += LOG;
		lzymul[x] = (lzymul[x] * val) % mod;
	} else if(l > rr || r < ll) {

	} else {
		seg_upd(x*2, l, (l+r)/2, ll, rr, val, LOG);
		seg_upd(x*2+1, (l+r)/2+1, r, ll, rr, val, LOG);
		if(seglog[x*2] > seglog[x*2+1]) {
			seglog[x] = seglog[x*2];
			segmul[x] = segmul[x*2];
		} else {
			seglog[x] = seglog[x*2+1];
			segmul[x] = segmul[x*2+1];
		}
	}
}

int init(int N, int X[], int Y[]) {
	n = N;
	for(int i=0; i<4*n; i++) lzymul[i] = 1;
	long double logc = 0; long long mulc = 1;
	for(int i=0; i<N; i++) {
		x[i] = X[i]; y[i] = Y[i];
		mulc = (mulc * X[i]) % mod;
		logc += log(X[i]);
		seg_set(1, 0, n-1, i, (mulc * Y[i]) % mod, logc + log(Y[i]));
	}
	return segmul[1];
}

int updateX(int pos, int val) {	
	long long v = (inv(x[pos]) * val) % mod;
	long double t = log(val) - log(x[pos]);
	seg_upd(1, 0, n-1, pos, n-1, v, t);
	x[pos] = val;
	return segmul[1];
}

int updateY(int pos, int val) {
	long long v = (inv(y[pos]) * val) % mod;
	long double t = log(val) - log(y[pos]);
	seg_upd(1, 0, n-1, pos, pos, v, t);
	y[pos] = val;
	return segmul[1];
}

Compilation message

horses.cpp: In function 'long long int fpw(long long int, long long int)':
horses.cpp:13:25: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   13 | long long fpw(long long n, long long p) {
      |               ~~~~~~~~~~^
horses.cpp:10:5: note: shadowed declaration is here
   10 | int n;
      |     ^
horses.cpp: In function 'long long int inv(long long int)':
horses.cpp:21:25: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   21 | long long inv(long long n) {
      |               ~~~~~~~~~~^
horses.cpp:10:5: note: shadowed declaration is here
   10 | int n;
      |     ^
horses.cpp: In function 'void push(int)':
horses.cpp:25:15: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   25 | void push(int x) {
      |           ~~~~^
horses.cpp:11:11: note: shadowed declaration is here
   11 | long long x[500005], y[500005];
      |           ^
horses.cpp: In function 'void seg_set(int, int, int, int, int, long double)':
horses.cpp:38:18: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   38 | void seg_set(int x, int l, int r, int pos, int val, long double LOG) {
      |              ~~~~^
horses.cpp:11:11: note: shadowed declaration is here
   11 | long long x[500005], y[500005];
      |           ^
horses.cpp: In function 'void seg_upd(int, int, int, int, int, long long int, long double)':
horses.cpp:55:18: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   55 | void seg_upd(int x, int l, int r, int ll, int rr, long long val, long double LOG) {
      |              ~~~~^
horses.cpp:11:11: note: shadowed declaration is here
   11 | long long x[500005], y[500005];
      |           ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:85:39: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   85 |   seg_set(1, 0, n-1, i, (mulc * Y[i]) % mod, logc + log(Y[i]));
      |                         ~~~~~~~~~~~~~~^~~~~
horses.cpp:87:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   87 |  return segmul[1];
      |         ~~~~~~~~^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:95:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   95 |  return segmul[1];
      |         ~~~~~~~~^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:103:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  103 |  return segmul[1];
      |         ~~~~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 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 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
# 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 1 ms 308 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 304 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 308 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 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 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 53568 KB Output is correct
2 Correct 488 ms 69868 KB Output is correct
3 Correct 414 ms 69836 KB Output is correct
4 Correct 458 ms 69872 KB Output is correct
# 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 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 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 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 312 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 516 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 448 KB Output is correct
28 Correct 2 ms 448 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 189 ms 68932 KB Output is correct
34 Correct 202 ms 68784 KB Output is correct
35 Correct 181 ms 52528 KB Output is correct
36 Correct 189 ms 52556 KB Output is correct
37 Correct 174 ms 68788 KB Output is correct
38 Correct 161 ms 52924 KB Output is correct
39 Correct 149 ms 52684 KB Output is correct
40 Correct 170 ms 52852 KB Output is correct
41 Correct 143 ms 53624 KB Output is correct
42 Correct 144 ms 52624 KB Output is correct
43 Correct 151 ms 52476 KB Output is correct
44 Correct 148 ms 52464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 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 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 308 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 0 ms 304 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 308 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 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 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 298 ms 53416 KB Output is correct
34 Correct 525 ms 69884 KB Output is correct
35 Correct 426 ms 69844 KB Output is correct
36 Correct 458 ms 69844 KB Output is correct
37 Correct 185 ms 68872 KB Output is correct
38 Correct 197 ms 68812 KB Output is correct
39 Correct 188 ms 52552 KB Output is correct
40 Correct 176 ms 52624 KB Output is correct
41 Correct 172 ms 68812 KB Output is correct
42 Correct 165 ms 52848 KB Output is correct
43 Correct 138 ms 52600 KB Output is correct
44 Correct 172 ms 52884 KB Output is correct
45 Correct 147 ms 53636 KB Output is correct
46 Correct 150 ms 52632 KB Output is correct
47 Correct 151 ms 52432 KB Output is correct
48 Correct 159 ms 52420 KB Output is correct
49 Correct 430 ms 74792 KB Output is correct
50 Correct 434 ms 74792 KB Output is correct
51 Correct 375 ms 65228 KB Output is correct
52 Correct 350 ms 64744 KB Output is correct
53 Correct 469 ms 73048 KB Output is correct
54 Correct 307 ms 60588 KB Output is correct
55 Correct 263 ms 55608 KB Output is correct
56 Correct 377 ms 63456 KB Output is correct
57 Correct 282 ms 57200 KB Output is correct
58 Correct 335 ms 56680 KB Output is correct
59 Correct 152 ms 58872 KB Output is correct