Submission #924837

# Submission time Handle Problem Language Result Execution time Memory
924837 2024-02-09T21:58:15 Z Macker Horses (IOI15_horses) C++17
100 / 100
284 ms 91220 KB
#include "horses.h"
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
typedef long double ld;
#define fi first
#define se second

ll mod = 1e9 + 7;
vector<pair<ll, ld>> st;
vector<pair<ll, ld>> lz;
vector<ll> x;
vector<ll> y;
int n;
int len = 1;

ll pow(ll n, ll k){
	n %= mod;
	ll res = 1;
	while(k > 0){
		if(k % 2) res = res * n % mod;
		k /= 2;
		n = n * n % mod;
	}
	return res;
}

ll modInv(ll x){
	return pow(x, mod - 2);
}

void prop(int i){
	st[i * 2].fi = st[i * 2].fi * lz[i].fi % mod;
	st[i * 2].se += lz[i].se;
	lz[i * 2].fi = lz[i * 2].fi * lz[i].fi % mod;
	lz[i * 2].se += lz[i].se;
	st[i * 2 + 1].fi = st[i * 2 + 1].fi * lz[i].fi % mod;
	st[i * 2 + 1].se += lz[i].se;
	lz[i * 2 + 1].fi = lz[i * 2 + 1].fi * lz[i].fi % mod;
	lz[i * 2 + 1].se += lz[i].se;
	lz[i] = {1, 0};
}

void upd(int l, int r, ll mval, ld lval, int i = 1, int s = 0, int e = len){
	if(l >= e || s >= r) return;
	if(l <= s && e <= r){
		st[i].fi = st[i].fi * mval % mod;
		st[i].se += lval;
		lz[i].fi = lz[i].fi * mval % mod;
		lz[i].se += lval;
		return;
	}
	prop(i);
	upd(l, r, mval, lval, i * 2, s, (s + e) / 2);
	upd(l, r, mval, lval, i * 2 + 1, (s + e) / 2, e);
	if(st[i * 2].second > st[i * 2 + 1].second){
		st[i] = st[i * 2];
	}
	else st[i] = st[i * 2 + 1];
}

int init(int N, int X[], int Y[]) {
	x.assign(X, X + N);
	y.assign(Y, Y + N);
	n = N;

	while(len < N) len *= 2;
	st.resize(2 * len, {1, 0});
	lz.resize(2 * len, {1, 0});

	for (int i = 0; i < N; i++) {
		st[len + i].fi = st[len + i - 1].fi * x[i] % mod;
		st[len + i].second = st[len + i - 1].se + logl(x[i]);
	}
	for (int i = 0; i < N; i++) {
		st[len + i].fi = st[len + i].fi * y[i] % mod;
		st[len + i].se += logl(y[i]);
	}
	
	for (int i = len - 1; i > 0; i--) {
		if(st[i * 2].second > st[i * 2 + 1].second){
			st[i] = st[i * 2];
		}
		else st[i] = st[i * 2 + 1];
	}
	
	
	return st[1].first;
}

int updateX(int pos, int val) {
	upd(pos, len + 1, val * modInv(x[pos]) % mod, logl(val) - logl(x[pos]));
	x[pos] = val;

	return st[1].first;
}

int updateY(int pos, int val) {
	upd(pos, pos + 1, val * modInv(y[pos]) % mod, logl(val) - logl(y[pos]));
	y[pos] = val;

	return st[1].first;
}

Compilation message

horses.cpp: In function 'll pow(ll, ll)':
horses.cpp:19:11: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   19 | ll pow(ll n, ll k){
      |        ~~~^
horses.cpp:16:5: note: shadowed declaration is here
   16 | int n;
      |     ^
horses.cpp: In function 'll modInv(ll)':
horses.cpp:30:14: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   30 | ll modInv(ll x){
      |           ~~~^
horses.cpp:14:12: note: shadowed declaration is here
   14 | vector<ll> x;
      |            ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:90:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   90 |  return st[1].first;
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:97:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   97 |  return st[1].first;
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:104:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  104 |  return st[1].first;
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 2 ms 444 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 192 ms 78608 KB Output is correct
2 Correct 275 ms 78852 KB Output is correct
3 Correct 250 ms 82516 KB Output is correct
4 Correct 266 ms 86452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 360 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 612 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 1 ms 632 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 848 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 97 ms 81772 KB Output is correct
34 Correct 108 ms 81744 KB Output is correct
35 Correct 97 ms 88788 KB Output is correct
36 Correct 95 ms 88664 KB Output is correct
37 Correct 92 ms 79904 KB Output is correct
38 Correct 80 ms 80860 KB Output is correct
39 Correct 82 ms 79700 KB Output is correct
40 Correct 93 ms 83844 KB Output is correct
41 Correct 84 ms 79744 KB Output is correct
42 Correct 86 ms 79956 KB Output is correct
43 Correct 79 ms 84216 KB Output is correct
44 Correct 79 ms 84032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2 ms 760 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 181 ms 82452 KB Output is correct
34 Correct 278 ms 91220 KB Output is correct
35 Correct 278 ms 82392 KB Output is correct
36 Correct 284 ms 86404 KB Output is correct
37 Correct 112 ms 81780 KB Output is correct
38 Correct 94 ms 81764 KB Output is correct
39 Correct 104 ms 88732 KB Output is correct
40 Correct 94 ms 88660 KB Output is correct
41 Correct 107 ms 79952 KB Output is correct
42 Correct 80 ms 80788 KB Output is correct
43 Correct 87 ms 79900 KB Output is correct
44 Correct 94 ms 83796 KB Output is correct
45 Correct 102 ms 79884 KB Output is correct
46 Correct 97 ms 79952 KB Output is correct
47 Correct 81 ms 84304 KB Output is correct
48 Correct 99 ms 84304 KB Output is correct
49 Correct 275 ms 83792 KB Output is correct
50 Correct 280 ms 83796 KB Output is correct
51 Correct 194 ms 90624 KB Output is correct
52 Correct 206 ms 89936 KB Output is correct
53 Correct 258 ms 82220 KB Output is correct
54 Correct 170 ms 82512 KB Output is correct
55 Correct 156 ms 80772 KB Output is correct
56 Correct 222 ms 85584 KB Output is correct
57 Correct 182 ms 81488 KB Output is correct
58 Correct 187 ms 82004 KB Output is correct
59 Correct 81 ms 84212 KB Output is correct