답안 #587503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587503 2022-07-02T03:01:55 Z benson1029 말 (IOI15_horses) C++14
54 / 100
333 ms 66016 KB
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;

long long mod = 1e9+7;
double seglog[2000005];
long long segmul[2000005];
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, 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, 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;
	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;
	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;
	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, 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, 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, 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, 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];
      |         ~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 312 KB Output is correct
11 Correct 0 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 312 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 316 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 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 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 476 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 1 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 1 ms 468 KB Output is correct
32 Correct 2 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 48956 KB Output is correct
2 Correct 333 ms 65944 KB Output is correct
3 Correct 279 ms 57024 KB Output is correct
4 Correct 311 ms 60972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 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 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 224 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 312 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 1 ms 436 KB Output is correct
22 Correct 0 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 1 ms 468 KB Output is correct
26 Correct 2 ms 448 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 452 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 448 KB Output is correct
33 Correct 137 ms 56332 KB Output is correct
34 Correct 130 ms 56432 KB Output is correct
35 Correct 131 ms 55124 KB Output is correct
36 Correct 134 ms 54980 KB Output is correct
37 Correct 101 ms 54464 KB Output is correct
38 Correct 110 ms 47444 KB Output is correct
39 Correct 91 ms 46272 KB Output is correct
40 Correct 118 ms 50252 KB Output is correct
41 Correct 93 ms 47132 KB Output is correct
42 Correct 105 ms 46532 KB Output is correct
43 Correct 110 ms 50524 KB Output is correct
44 Incorrect 106 ms 50464 KB Output isn't correct
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 0 ms 316 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 2 ms 600 KB Output is correct
27 Correct 1 ms 448 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 1 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 222 ms 48928 KB Output is correct
34 Correct 332 ms 66016 KB Output is correct
35 Correct 280 ms 57052 KB Output is correct
36 Correct 316 ms 60980 KB Output is correct
37 Correct 128 ms 56376 KB Output is correct
38 Correct 126 ms 56320 KB Output is correct
39 Correct 137 ms 55072 KB Output is correct
40 Correct 134 ms 54976 KB Output is correct
41 Correct 100 ms 54532 KB Output is correct
42 Correct 110 ms 47368 KB Output is correct
43 Correct 96 ms 46372 KB Output is correct
44 Correct 124 ms 50284 KB Output is correct
45 Correct 92 ms 47180 KB Output is correct
46 Correct 95 ms 46272 KB Output is correct
47 Correct 110 ms 50532 KB Output is correct
48 Incorrect 111 ms 50552 KB Output isn't correct
49 Halted 0 ms 0 KB -