Submission #571874

# Submission time Handle Problem Language Result Execution time Memory
571874 2022-06-03T02:57:22 Z kwongweng Horses (IOI15_horses) C++17
17 / 100
436 ms 123660 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define ROF(i,a,b) for(int i = a; i >= b; i--)
#define fi first
#define se second
#define pb push_back

ll MOD = 1000000007;

ll power(ll base, ll n){
	if (n == 0) return 1;
	if (n == 1) return base;
	ll halfn = power(base, n/2);
	if (n % 2 == 0) return (halfn * halfn) % MOD;
	return (((halfn * halfn) % MOD) * base) % MOD;
}
 
ll inverse(ll n){
	return power(n, MOD-2);
}

vector<ll> x, y;
int n;

struct lol{
	ld val;
	int ind;
	ld add;
};
// range addition and maximum
struct segtree{
	vector<lol> mx;
	int sz;
	void init(int m){
		sz = m;
		mx.assign(4*m, {0,0,0});
	}
	void update(int v, int tl, int tr, int l, int r, ld val){
		if (tl==tr) mx[v].ind = tl;
		if (tl == l && tr == r){
			mx[v].add += val;
			mx[v].val += val;
			return;
		}
		if (l > r) return;
		int tm = (tl + tr)/2;
		update(2*v, tl, tm, l, min(r,tm), val);
		update(2*v+1, tm+1, tr, max(l,tm+1), r, val);
		if (mx[2*v].val + 1e-11 > mx[2*v+1].val){
			mx[v].val = mx[2*v].val + mx[v].add;
			mx[v].ind = mx[2*v].ind;
		}else{
			mx[v].val = mx[2*v+1].val + mx[v].add;
			mx[v].ind = mx[2*v+1].ind;
		}
	}
	void update(int l, int r, ld val){
		update(1,0,sz-1,l,r,val);
	}
	int get(){
		return mx[1].ind;
	}
} st;

// range update point value
struct segtree2{
	vector<ll> prod;
	int sz;
	void init(int m){
		sz = m;
		prod.assign(4*m, 1);
	}
	void update(int v, int tl, int tr, int l, int r, ll val){
		if (l>r) return;
		if (tl==l && tr==r){
			prod[v] *= val;
			return;
		}
		int tm = (tl+tr)/2;
		update(2*v, tl, tm, l, min(r,tm), val);
		update(2*v+1, tm+1, tr, max(l,tm+1), r, val);
	}
	void update(int l, int r, ll val){
		update(1,0,sz-1,l,r,val);
	}
	ll get(int v, int tl, int tr, int pos){
		if (tl==tr) return prod[v];
		int tm = (tl+tr)/2;
		if (pos <= tm){
			return (get(2*v,tl,tm,pos)*prod[v]) % MOD;
		}else{
			return (get(2*v+1,tm+1,tr,pos)*prod[v]) % MOD;
		}
	}
	ll get(int pos){
		return get(1,0,sz-1,pos);
	}
} st2;

vector<ld> a, b;

int init(int N, int X[], int Y[]) {
	cout << setprecision(12);
	n = N;
	FOR(i,0,n){
		x.pb(X[i]);
		y.pb(Y[i]);
	}
	st.init(N);
	st2.init(N);
	FOR(i,0,N){
		st.update(i,n-1,log(x[i]));
		st.update(i,i,log(y[i]));
		st2.update(i,n-1,x[i]);
	}
	int ans = st.get();
	return (st2.get(ans) * y[ans]) % MOD;
}

int updateX(int pos, int val) {
	st.update(pos,n-1,log(val)-log(x[pos]));
	st2.update(pos,n-1,(inverse(x[pos])*(ll)val) % MOD);
	x[pos] = val;
	int ans = st.get();
	return (st2.get(ans) * y[ans]) % MOD;
}

int updateY(int pos, int val) {
	st.update(pos,pos,log(val)-log(y[pos]));
	y[pos] = val;
	int ans = st.get();
	return (st2.get(ans) * y[ans]) % MOD;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:124:33: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  124 |  return (st2.get(ans) * y[ans]) % MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:132:33: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  132 |  return (st2.get(ans) * y[ans]) % MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:139:33: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  139 |  return (st2.get(ans) * y[ans]) % MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 0 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 436 ms 123660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 240 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 0 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 0 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -