답안 #104996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104996 2019-04-10T05:12:03 Z arman_ferdous 말 (IOI15_horses) C++17
100 / 100
643 ms 125816 KB
#include "horses.h"
#include <bits/stdc++.h>
#define double long double
using namespace std;

using ll = long long;
const int N = 5e5+10;
const int MOD = 1e9+7;
const double eps = 1e-9;

int n; ll mulz[N];
double X[N], Y[N];
double lgx[N], lgy[N];
double tmp[N];

struct SGT1{
	struct nude{
		int idx;
		double mx, lazy;
	}t[N<<2];
	void build(int node, int L, int R) {
		t[node].lazy = 0;
		if(L == R) {
			t[node].mx = tmp[L];
			t[node].idx = L;
			return;
		} int mid = (L+R)>>1, lc = node<<1, rc = lc|1;
		build(lc, L, mid); build(rc, mid+1, R);

		if(t[lc].mx - t[rc].mx > eps) {
			t[node].mx = t[lc].mx;
			t[node].idx = t[lc].idx;
		} else {
			t[node].mx = t[rc].mx;
			t[node].idx = t[rc].idx;
		}
	}
	void shift(int node) {
		int lc = node<<1, rc = lc|1;
		t[lc].mx += t[node].lazy;
		t[rc].mx += t[node].lazy;
		t[lc].lazy += t[node].lazy;
		t[rc].lazy += t[node].lazy;
		t[node].lazy = 0;

		if(t[lc].mx - t[rc].mx > eps) {
			t[node].mx = t[lc].mx;
			t[node].idx = t[lc].idx;
		} else {
			t[node].mx = t[rc].mx;
			t[node].idx = t[rc].idx;
		}
	}
	void upd(int node, int L, int R, int l, int r, double v) {
		if(r < L || R < l) return;
		if(l <= L && R <= r) {
			t[node].lazy += v;
			t[node].mx += v;
			return;
		} if(fabs(t[node].lazy) > eps) shift(node);
		int mid = (L+R)>>1, lc = node<<1, rc = lc|1;
		upd(lc, L, mid, l, r, v);
		upd(rc, mid+1, R, l, r, v);
		if(t[lc].mx - t[rc].mx > eps) {
			t[node].mx = t[lc].mx;
			t[node].idx = t[lc].idx;
		} else {
			t[node].mx = t[rc].mx;
			t[node].idx = t[rc].idx;
		}
	}
	int get() { return t[1].idx; }
}opt;

struct SGT2{
	ll t[N<<2], lazy[N<<2];
	void build(int node, int L, int R) {
		lazy[node] = 1;
		if(L == R) return void(t[node] = mulz[L]);
		int mid = (L+R)>>1, lc = node<<1, rc = lc|1;
		build(lc, L, mid); build(rc, mid+1, R);
		t[node] = t[lc] * t[rc] % MOD;
	}
	void shift(int node) {
		int lc = node<<1, rc = lc|1;
		t[lc] = t[lc] * lazy[node] % MOD;
		t[rc] = t[rc] * lazy[node] % MOD;
		lazy[lc] = lazy[lc] * lazy[node] % MOD;
		lazy[rc] = lazy[rc] * lazy[node] % MOD;
		lazy[node] = 1;
	}
	void upd(int node, int L, int R, int l, int r, ll v) {
		if(r < L || R < l) return;
		if(l <= L && R <= r) {
			t[node] = t[node] * v % MOD;
			lazy[node] = lazy[node] * v % MOD;
			return;
		} if(lazy[node] != 1) shift(node);
		int mid = (L+R)>>1, lc = node<<1, rc = lc|1;
		upd(lc, L, mid, l, r, v); upd(rc, mid+1, R, l, r, v);
		t[node] = t[lc] * t[rc] % MOD;
	}	
	ll get(int node, int L, int R, int pos) {
		if(L == R) return t[node];
		if(lazy[node] != 1) shift(node);
		int mid = (L+R)>>1, lc = node<<1, rc = lc|1;
		if(pos <= mid) return get(lc, L, mid, pos);
		return get(rc, mid+1, R, pos);
	}
}mul;

int init(int _N, int _X[], int _Y[]) {
	n = _N;
	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]);
	}

	for(int i = 1; i <= n; i++)
		tmp[i] = tmp[i-1] + lgx[i];
	for(int i = 1; i <= n; i++)
		tmp[i] += lgy[i];

	mulz[0] = 1;
	for(int i = 1; i <= n; i++)
		mulz[i] = mulz[i-1] * (ll)X[i] % MOD; 
	for(int i = 1; i <= n; i++)
		mulz[i] = mulz[i] * (ll)Y[i] % MOD;


	opt.build(1,1,n);
	mul.build(1,1,n);
	int idx = opt.get();
	return mul.get(1,1,n,idx);
}

ll powmod(ll a, ll b) {
	ll r = 1;
	while(b) {
		if(b & 1) r = r * a % MOD;
		a = a * a % MOD;
		b>>=1;
	} return r;
}
ll modinv(ll x) { return powmod(x,MOD-2); }

int updateX(int pos, int val) {
	pos++;
	double lg = log((double)val);
	double del = lg - lgx[pos]; 
	opt.upd(1,1,n,pos,n,del);

	ll det = (ll)val * modinv((ll)X[pos]) % MOD;
	mul.upd(1,1,n,pos,n,det);

	X[pos] = val;
	lgx[pos] = lg;
	int idx = opt.get();
	return mul.get(1,1,n,idx);
}

int updateY(int pos, int val) {
	pos++;
	double lg = log((double)val);
	double del = lg - lgy[pos];
	opt.upd(1,1,n,pos,pos,del);

	ll det = (ll)val * modinv((ll)Y[pos]) % MOD;
	mul.upd(1,1,n,pos,pos,det);

	Y[pos] = val;
	lgy[pos] = lg;
	int idx = opt.get();
	return mul.get(1,1,n,idx);
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:134:16: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return mul.get(1,1,n,idx);
         ~~~~~~~^~~~~~~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:159:16: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return mul.get(1,1,n,idx);
         ~~~~~~~^~~~~~~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:174:16: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return mul.get(1,1,n,idx);
         ~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 2 ms 428 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 4 ms 640 KB Output is correct
24 Correct 5 ms 640 KB Output is correct
25 Correct 5 ms 640 KB Output is correct
26 Correct 4 ms 640 KB Output is correct
27 Correct 6 ms 768 KB Output is correct
28 Correct 3 ms 640 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 4 ms 640 KB Output is correct
31 Correct 4 ms 640 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 280 ms 114180 KB Output is correct
2 Correct 643 ms 114504 KB Output is correct
3 Correct 520 ms 114200 KB Output is correct
4 Correct 525 ms 114168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 5 ms 640 KB Output is correct
24 Correct 5 ms 640 KB Output is correct
25 Correct 4 ms 640 KB Output is correct
26 Correct 4 ms 640 KB Output is correct
27 Correct 4 ms 640 KB Output is correct
28 Correct 4 ms 640 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 4 ms 640 KB Output is correct
31 Correct 4 ms 640 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
33 Correct 258 ms 113272 KB Output is correct
34 Correct 208 ms 113272 KB Output is correct
35 Correct 187 ms 113272 KB Output is correct
36 Correct 199 ms 113220 KB Output is correct
37 Correct 199 ms 113244 KB Output is correct
38 Correct 183 ms 113308 KB Output is correct
39 Correct 186 ms 113220 KB Output is correct
40 Correct 199 ms 113272 KB Output is correct
41 Correct 193 ms 113400 KB Output is correct
42 Correct 200 ms 113256 KB Output is correct
43 Correct 185 ms 113144 KB Output is correct
44 Correct 177 ms 113144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 5 ms 640 KB Output is correct
24 Correct 4 ms 640 KB Output is correct
25 Correct 4 ms 640 KB Output is correct
26 Correct 4 ms 640 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 4 ms 640 KB Output is correct
29 Correct 3 ms 640 KB Output is correct
30 Correct 5 ms 640 KB Output is correct
31 Correct 4 ms 768 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
33 Correct 264 ms 114172 KB Output is correct
34 Correct 582 ms 114040 KB Output is correct
35 Correct 578 ms 114168 KB Output is correct
36 Correct 473 ms 114140 KB Output is correct
37 Correct 204 ms 113144 KB Output is correct
38 Correct 229 ms 113144 KB Output is correct
39 Correct 207 ms 113272 KB Output is correct
40 Correct 180 ms 113152 KB Output is correct
41 Correct 201 ms 113144 KB Output is correct
42 Correct 166 ms 113144 KB Output is correct
43 Correct 181 ms 113192 KB Output is correct
44 Correct 194 ms 113272 KB Output is correct
45 Correct 172 ms 113144 KB Output is correct
46 Correct 179 ms 113272 KB Output is correct
47 Correct 180 ms 113116 KB Output is correct
48 Correct 183 ms 113148 KB Output is correct
49 Correct 562 ms 119032 KB Output is correct
50 Correct 588 ms 119160 KB Output is correct
51 Correct 268 ms 125816 KB Output is correct
52 Correct 281 ms 125304 KB Output is correct
53 Correct 460 ms 117432 KB Output is correct
54 Correct 323 ms 118008 KB Output is correct
55 Correct 310 ms 116228 KB Output is correct
56 Correct 340 ms 120820 KB Output is correct
57 Correct 335 ms 116788 KB Output is correct
58 Correct 279 ms 117260 KB Output is correct
59 Correct 184 ms 119416 KB Output is correct