Submission #158605

# Submission time Handle Problem Language Result Execution time Memory
158605 2019-10-18T06:27:02 Z oolimry Horses (IOI15_horses) C++14
100 / 100
423 ms 112624 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long x[500005];
long long y[500005];

long double lnx[500005];
long double lny[500005];

typedef pair<long double, int> ii;
class Segtree{
public:
	int n;
	vector<ii> tree;
	vector<long double> lazy;
	void create(int nn){
		n = nn;
		for(int i = 0;i < 2*n+5;i++){
			tree.push_back(ii(0.0,0));
			lazy.push_back(0.0);
		}
		long double acc = 0.0;
		for(int i = 0;i < n;i++){
			acc += lnx[i];
			tree[i+n] = ii(acc+lny[i],i);
		}
		for(int i = n-1;i >= 1;i--){
			tree[i] = max(tree[i<<1],tree[i<<1|1]);
		}
	}
	
	int query(){
		return tree[1].second;
	}
	
	void update(int l, int r, long double v){
		int ll = l + n; int rr = r + n - 1;
		for(l += n, r += n;l < r;l >>= 1, r >>= 1){
			if(l&1){
				lazy[l] += v;
				tree[l].first += v;
				l++;
			}
			if(r&1){
				r--;
				lazy[r] += v;
				tree[r].first += v;
			}
		}
		while(ll > 1){
			ll >>= 1;
			ii x = max(tree[ll<<1],tree[ll<<1|1]);
			tree[ll] = ii(x.first + lazy[ll], x.second);
		}
		while(rr > 1){
			rr >>= 1;
			ii x = max(tree[rr<<1],tree[rr<<1|1]);
			tree[rr] = ii(x.first + lazy[rr], x.second);
		}
	}
	
};
int n;
long long tree[1000005];
long long queryd(int l, int r){
	long long ans = 1;
	for(l += n, r += n;l < r;l >>= 1, r >>= 1){
		if(l&1){
			ans *= tree[l];
			ans %= mod;
			l++;
		}
		if(r&1){
			r--;
			ans *= tree[r];
			ans %= mod;
		}
	}
	return ans;
}
Segtree seg;
long long answer(){
	int pos = seg.query();
	long long value =  queryd(0,pos+1);
	value *= y[pos];
	value %= mod;
	return value;
}
int init(int N, int X[], int Y[]) {
	n = N;
	for(int i = 0;i < N;i++){
		x[i] = X[i];
		y[i] = Y[i];
		lnx[i] = (double)log2((double)X[i]);
		lny[i] = (double)log2((double)Y[i]);
		//printf("%f %f\n",lnx[i],lny[i]);
		tree[i+n] = x[i];
	}
	
	for(int i = n-1;i >= 1;i--){
		tree[i] = tree[i<<1] * tree[i<<1|1];
		tree[i] %= mod;
	}
	seg.create(n);
	
	return answer();
}

int updateX(int pos, int val) {	
	x[pos] = val;
	long double oln = lnx[pos];
	lnx[pos] = (double)log2((double)x[pos]);
	oln = lnx[pos] - oln;
	seg.update(pos,n,oln);
	
	tree[pos+n] = val;
	int i = (pos + n) >> 1;
	while(i > 0){
		tree[i] = tree[i<<1] * tree[i<<1|1];
		tree[i] %= mod;
		i >>= 1;
	}
	return answer();
}

int updateY(int pos, int val) {
	y[pos] = val;
	long double oln = lny[pos];
	lny[pos] = (double)log2((double)y[pos]);
	oln = lny[pos] - oln;
	seg.update(pos,pos+1,oln);
	return answer();
}

Compilation message

horses.cpp: In member function 'void Segtree::update(int, int, long double)':
horses.cpp:53:7: warning: declaration of 'x' shadows a global declaration [-Wshadow]
    ii x = max(tree[ll<<1],tree[ll<<1|1]);
       ^
horses.cpp:5:11: note: shadowed declaration is here
 long long x[500005];
           ^
horses.cpp:58:7: warning: declaration of 'x' shadows a global declaration [-Wshadow]
    ii x = max(tree[rr<<1],tree[rr<<1|1]);
       ^
horses.cpp:5:11: note: shadowed declaration is here
 long long x[500005];
           ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:107:15: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return answer();
         ~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:124:15: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return answer();
         ~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:133:15: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return answer();
         ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 296 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 296 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 ms 632 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 3 ms 632 KB Output is correct
28 Correct 3 ms 632 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 244 ms 99900 KB Output is correct
2 Correct 363 ms 112492 KB Output is correct
3 Correct 323 ms 103808 KB Output is correct
4 Correct 390 ms 107740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 632 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 185 ms 99072 KB Output is correct
34 Correct 187 ms 103004 KB Output is correct
35 Correct 207 ms 109980 KB Output is correct
36 Correct 204 ms 109848 KB Output is correct
37 Correct 200 ms 101096 KB Output is correct
38 Correct 180 ms 102048 KB Output is correct
39 Correct 165 ms 101088 KB Output is correct
40 Correct 184 ms 104988 KB Output is correct
41 Correct 158 ms 101020 KB Output is correct
42 Correct 162 ms 101276 KB Output is correct
43 Correct 174 ms 105372 KB Output is correct
44 Correct 177 ms 105372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 3 ms 632 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 632 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 244 ms 101760 KB Output is correct
34 Correct 368 ms 112624 KB Output is correct
35 Correct 328 ms 103840 KB Output is correct
36 Correct 423 ms 107716 KB Output is correct
37 Correct 193 ms 103144 KB Output is correct
38 Correct 217 ms 102928 KB Output is correct
39 Correct 208 ms 110056 KB Output is correct
40 Correct 230 ms 109884 KB Output is correct
41 Correct 169 ms 101148 KB Output is correct
42 Correct 185 ms 102208 KB Output is correct
43 Correct 163 ms 100992 KB Output is correct
44 Correct 186 ms 104992 KB Output is correct
45 Correct 177 ms 101020 KB Output is correct
46 Correct 168 ms 101284 KB Output is correct
47 Correct 174 ms 105344 KB Output is correct
48 Correct 174 ms 105364 KB Output is correct
49 Correct 344 ms 104988 KB Output is correct
50 Correct 341 ms 105024 KB Output is correct
51 Correct 303 ms 111916 KB Output is correct
52 Correct 296 ms 111292 KB Output is correct
53 Correct 329 ms 103324 KB Output is correct
54 Correct 324 ms 103964 KB Output is correct
55 Correct 276 ms 102068 KB Output is correct
56 Correct 314 ms 106780 KB Output is correct
57 Correct 224 ms 102748 KB Output is correct
58 Correct 244 ms 103196 KB Output is correct
59 Correct 196 ms 105300 KB Output is correct