Submission #341222

# Submission time Handle Problem Language Result Execution time Memory
341222 2020-12-29T08:57:21 Z Kerim Horses (IOI15_horses) C++17
100 / 100
371 ms 83564 KB
#include "horses.h"
#include "bits/stdc++.h"
#define MAXN 500009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<long double,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
PII a[MAXN],b[MAXN],s[MAXN<<2];
double par[MAXN],lazy[MAXN<<2];
int F[MAXN],n;
int mod(ll x){
	return (x%INF);
}
void build(int nd,int x,int y){
	if(x==y){
		s[nd]=mp(par[x]+b[x].ff,x);
		return;
	}
	int mid=(x+y)>>1;
	build(nd<<1,x,mid);
	build(nd<<1|1,mid+1,y);
	s[nd]=max(s[nd<<1],s[nd<<1|1]);
}
void upd(int x,int val){
	for(;x<=n;x+=x&(-x))
		F[x]=mod(F[x]*1LL*val);	
}
void shift(int nd){
	double &ret=lazy[nd];
	lazy[nd<<1]+=ret;s[nd<<1].ff+=ret;
	lazy[nd<<1|1]+=ret;s[nd<<1|1].ff+=ret;	
	ret=0;
}
void inc(int l,int r,double v,int nd,int x,int y){
	if(l>y or x>r)
		return;
	if(l<=x and y<=r){
		s[nd].ff+=v;
		lazy[nd]+=v;
		return;	
	}
	shift(nd);
	int mid=(x+y)>>1;
	inc(l,r,v,nd<<1,x,mid);
	inc(l,r,v,nd<<1|1,mid+1,y);
	s[nd]=max(s[nd<<1],s[nd<<1|1]);
}
int get(){
	int x=s[1].ss;
	int res=b[x].ss;
	for(;x;x-=x&(-x))res=mod(res*1LL*F[x]);
	return res;
}
int init(int N, int X[], int Y[]) {n=N;
	for(int i=1;i<=n;i++)
		b[i]=mp(log(Y[i-1]),Y[i-1]),a[i]=mp(log(X[i-1]),X[i-1]),par[i]=(a[i].ff+par[i-1]),F[i]=1;
	for(int i=1;i<=n;i++)upd(i,a[i].ss);
	build(1,1,n);
	return get();
}
int Fe(int x,int y){
	if(!y)return 1;
	int h=Fe(x,y/2);
	h=mod(h*1LL*h);
	if(y&1)h=mod(h*1LL*x);
	return h;	
}
int updateX(int pos, int val) {	
	inc(pos+1,n,log(val)-a[pos+1].ff,1,1,n);
	upd(pos+1,mod(val*1LL*Fe(a[pos+1].ss,INF-2)));
	a[pos+1]=mp(log(val),val);
	return get();
}

int updateY(int pos, int val) {
	inc(pos+1,pos+1,log(val)-b[pos+1].ff,1,1,n);
	b[pos+1]=mp(log(val),val);
	return get();
}

Compilation message

horses.cpp: In function 'int mod(ll)':
horses.cpp:25:11: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   25 |  return (x%INF);
      |         ~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:69:74: warning: conversion from 'long double' to 'double' may change value [-Wfloat-conversion]
   69 |   b[i]=mp(log(Y[i-1]),Y[i-1]),a[i]=mp(log(X[i-1]),X[i-1]),par[i]=(a[i].ff+par[i-1]),F[i]=1;
      |                                                                  ~~~~~~~~^~~~~~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:82:22: warning: conversion from 'long double' to 'double' may change value [-Wfloat-conversion]
   82 |  inc(pos+1,n,log(val)-a[pos+1].ff,1,1,n);
      |                      ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:89:26: warning: conversion from 'long double' to 'double' may change value [-Wfloat-conversion]
   89 |  inc(pos+1,pos+1,log(val)-b[pos+1].ff,1,1,n);
      |                          ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 194 ms 75372 KB Output is correct
2 Correct 358 ms 83436 KB Output is correct
3 Correct 327 ms 83564 KB Output is correct
4 Correct 360 ms 83564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 140 ms 82668 KB Output is correct
34 Correct 145 ms 82540 KB Output is correct
35 Correct 152 ms 74476 KB Output is correct
36 Correct 154 ms 74476 KB Output is correct
37 Correct 118 ms 82540 KB Output is correct
38 Correct 127 ms 74604 KB Output is correct
39 Correct 97 ms 74604 KB Output is correct
40 Correct 130 ms 74604 KB Output is correct
41 Correct 95 ms 75244 KB Output is correct
42 Correct 103 ms 74604 KB Output is correct
43 Correct 118 ms 74328 KB Output is correct
44 Correct 116 ms 74348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 3 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 620 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 192 ms 75632 KB Output is correct
34 Correct 369 ms 83436 KB Output is correct
35 Correct 319 ms 83436 KB Output is correct
36 Correct 371 ms 83564 KB Output is correct
37 Correct 141 ms 82668 KB Output is correct
38 Correct 142 ms 82624 KB Output is correct
39 Correct 152 ms 74476 KB Output is correct
40 Correct 151 ms 74476 KB Output is correct
41 Correct 112 ms 82540 KB Output is correct
42 Correct 124 ms 74608 KB Output is correct
43 Correct 97 ms 74476 KB Output is correct
44 Correct 148 ms 74604 KB Output is correct
45 Correct 93 ms 75244 KB Output is correct
46 Correct 94 ms 74476 KB Output is correct
47 Correct 116 ms 74348 KB Output is correct
48 Correct 131 ms 74348 KB Output is correct
49 Correct 342 ms 83564 KB Output is correct
50 Correct 336 ms 83520 KB Output is correct
51 Correct 244 ms 75372 KB Output is correct
52 Correct 255 ms 75372 KB Output is correct
53 Correct 313 ms 83564 KB Output is correct
54 Correct 248 ms 76908 KB Output is correct
55 Correct 215 ms 74860 KB Output is correct
56 Correct 254 ms 77036 KB Output is correct
57 Correct 174 ms 76268 KB Output is correct
58 Correct 232 ms 75372 KB Output is correct
59 Correct 115 ms 74348 KB Output is correct