Submission #121909

# Submission time Handle Problem Language Result Execution time Memory
121909 2019-06-27T07:52:58 Z CaroLinda Horses (IOI15_horses) C++14
100 / 100
501 ms 54520 KB
#include <bits/stdc++.h>
#include "horses.h"

#define ll long long
#define lp(i,a,b) for(int i=a;i<b;i++)

const int MAXN=5e5+5 ;
const int MOD=1e9+7 ;

using namespace std ;

// -------------x-------------

int n, x[MAXN],y[MAXN] ;

struct node
{
	double v , l ;
	int best ;
	ll real ;
} ;

node tree[MAXN*4] ;

// -------------x-------------

int m(int l, int r) {return (l+r)/2 ;}

void refresh(int pos, int l, int r)
{
	double k = tree[pos].l ;
	tree[pos].l = 0 ;
	tree[pos].v += k ;
	if(l==r) return ;
	lp(i,0,2) tree[pos*2+i].l += k ;
}

void merge(int pos)
{
	tree[pos] = (tree[pos*2].v > tree[pos*2+1].v) ? tree[pos*2] : tree[pos*2+1] ;
	tree[pos].real = tree[pos*2].real * tree[pos*2+1].real % MOD ;
}

void build(int pos, int l, int r)
{
	if(l==r)
	{
		tree[pos].v = log2(y[l]) ;
		tree[pos].real = x[l] ;
		tree[pos].best = l ;
		tree[pos].l = 0 ;
		return ;
	}
	build(pos*2,l,m(l,r)) ;
	build(pos*2+1, m(l,r)+1,r) ;
	merge(pos) ;
}

void pointUpd(int pos, int l, int r, int x, int val)
{
	refresh(pos,l,r) ;
	if(l>x || r<x) return ;
	if(l==r)
	{
		tree[pos].real = val ;
		return ;
	}
	pointUpd(pos*2,l,m(l,r),x,val) ;
	pointUpd(pos*2+1,m(l,r)+1,r,x,val) ;
	merge(pos) ;
}

void intervalUpd(int pos, int l, int r, int beg, int en, double val )
{
	refresh(pos,l,r) ;
	if(l>en || r<beg) return ;
	if(l>=beg && r<=en)
	{
		tree[pos].l += val ;
		refresh(pos,l,r) ;
		return ;
	}
	intervalUpd(pos*2,l,m(l,r),beg,en,val) ;
	intervalUpd(pos*2+1,m(l,r)+1,r,beg,en,val) ;
	merge(pos) ;
}

ll query(int pos, int l, int r, int beg, int en)
{
	if(l>en || r<beg) return 1 ;
	if(l>=beg && r<=en) return tree[pos].real ;
	ll rl = query(pos*2,l,m(l,r),beg,en) ;
	ll rr=query(pos*2+1,m(l,r)+1,r,beg,en) ;
	return rl*rr%MOD ;
}

int ans()
{
	refresh(1,0,n-1) ;
	int myBest = tree[1].best ;
	return query(1,0,n-1,0,myBest)*y[myBest]%MOD ;
}

int init(int N, int X[] ,  int Y[])
{
	n=N;
	lp(i,0,n) x[i]=X[i],y[i]=Y[i] ;
	
	build(1,0,n-1) ;
	lp(i,0,n) intervalUpd(1,0,n-1,i,n-1,log2(x[i])) ;
	return ans() ;
	
}

int updateY(int pos, int val)
{
	intervalUpd(1,0,n-1,pos,pos,-log2(y[pos]) + log2(val)) ;
	y[pos]=val ;
	return ans() ;
}

int updateX(int pos, int val)
{
	pointUpd(1,0,n-1,pos,val) ;
	intervalUpd(1,0,n-1,pos,n-1,-log2(x[pos])+log2(val) ) ;
	x[pos]=val ;
	return ans() ;
}

Compilation message

horses.cpp: In function 'void pointUpd(int, int, int, int, int)':
horses.cpp:59:52: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 void pointUpd(int pos, int l, int r, int x, int val)
                                                    ^
horses.cpp:14:8: note: shadowed declaration is here
 int n, x[MAXN],y[MAXN] ;
        ^
horses.cpp: In function 'int ans()':
horses.cpp:101:42: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return query(1,0,n-1,0,myBest)*y[myBest]%MOD ;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory 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 8 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 2 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
# Verdict Execution time Memory 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 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 2 ms 384 KB Output is correct
20 Correct 2 ms 428 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 307 ms 45688 KB Output is correct
2 Correct 406 ms 54492 KB Output is correct
3 Correct 384 ms 45816 KB Output is correct
4 Correct 418 ms 49528 KB Output is correct
# Verdict Execution time Memory 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 2 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 2 ms 384 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 508 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 239 ms 45048 KB Output is correct
34 Correct 240 ms 45048 KB Output is correct
35 Correct 279 ms 51964 KB Output is correct
36 Correct 284 ms 51960 KB Output is correct
37 Correct 244 ms 43328 KB Output is correct
38 Correct 248 ms 44152 KB Output is correct
39 Correct 240 ms 43128 KB Output is correct
40 Correct 254 ms 46968 KB Output is correct
41 Correct 232 ms 43128 KB Output is correct
42 Correct 230 ms 43128 KB Output is correct
43 Correct 243 ms 47352 KB Output is correct
44 Correct 249 ms 47480 KB Output is correct
# Verdict Execution time Memory 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 300 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 2 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 3 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 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 307 ms 45816 KB Output is correct
34 Correct 414 ms 54520 KB Output is correct
35 Correct 364 ms 45816 KB Output is correct
36 Correct 435 ms 49584 KB Output is correct
37 Correct 248 ms 45048 KB Output is correct
38 Correct 253 ms 45048 KB Output is correct
39 Correct 284 ms 51960 KB Output is correct
40 Correct 292 ms 51980 KB Output is correct
41 Correct 237 ms 43256 KB Output is correct
42 Correct 251 ms 44024 KB Output is correct
43 Correct 237 ms 43100 KB Output is correct
44 Correct 257 ms 47044 KB Output is correct
45 Correct 239 ms 43128 KB Output is correct
46 Correct 233 ms 43128 KB Output is correct
47 Correct 251 ms 47504 KB Output is correct
48 Correct 501 ms 47484 KB Output is correct
49 Correct 382 ms 46968 KB Output is correct
50 Correct 369 ms 47152 KB Output is correct
51 Correct 354 ms 54064 KB Output is correct
52 Correct 338 ms 53260 KB Output is correct
53 Correct 366 ms 45372 KB Output is correct
54 Correct 352 ms 45948 KB Output is correct
55 Correct 311 ms 44136 KB Output is correct
56 Correct 357 ms 48856 KB Output is correct
57 Correct 295 ms 44776 KB Output is correct
58 Correct 329 ms 45176 KB Output is correct
59 Correct 258 ms 47480 KB Output is correct