Submission #847383

# Submission time Handle Problem Language Result Execution time Memory
847383 2023-09-09T14:59:52 Z PenguinsAreCute Horses (IOI15_horses) C++17
100 / 100
254 ms 41296 KB
// As usual, don't miss a chance to make your code 69 lines...
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=b-1;i>=a;i--)
#define SZ 500069
#define MOD 1000000007
int n, v[SZ<<1], x[SZ];
void initTree(int Y[]) {
	REP(i,n,(n<<1)) v[i]=Y[i-n];
	RREP(i,1,n) v[i]=max(v[i<<1],v[i<<1 | 1]);
}
void up(int pos, int val) {for(v[pos+=n]=val;pos>1;pos>>=1) v[pos>>1]=max(v[pos],v[pos^1]);}
int qry(int l, int r) {
	int res=0;
	for(l+=n,r+=n;l<r;l>>=1,r>>=1) {
		if(l&1) res=max(res,v[l++]);
		if(r&1) res=max(res,v[--r]);
	}
	return res;
}
set<int> s;
int prod=1;
int mul(int a, int b) {return (1LL*a*b)%MOD;}
int exp(int a, int b) {
    int ans=1, basepow=a;
    REP(i,0,30) {
        if((1<<i)&b) ans=mul(ans,basepow);
        basepow=mul(basepow,basepow);
    }
    return ans;
}
int compute() {
	auto it=s.end(); it--;
	long long inProd=1; long double ans=0; int actAns=0;
	do {
		auto nd=it--;
		int qAns=qry(*it,*nd);
		if(qAns/(long double)inProd > ans) {
			ans = qAns/(long double)inProd;
			actAns=mul(prod,mul(qAns,exp(inProd,MOD-2)));
		}
		inProd *= x[*it];
	} while(it!=s.begin()&&inProd<1000000000);
	return actAns;
}
int init(int N, int X[], int Y[]) {
	n=N;
	initTree(Y);
	REP(i,0,N) {
		if(X[i]!=1) s.insert(i);
		x[i]=X[i]; prod=mul(prod,X[i]);
	}
	s.insert(N); s.insert(0);
	return compute();
}
int updateX(int pos, int val) {	
	if(val==1 && pos) s.erase(pos);
	else s.insert(pos);
	prod=mul(prod,mul(val,exp(x[pos],MOD-2)));
	x[pos]=val;
	return compute();
}
int updateY(int pos, int val) {
	up(pos,val);
	return compute();
}

Compilation message

horses.cpp: In function 'int mul(int, int)':
horses.cpp:26:40: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   26 | int mul(int a, int b) {return (1LL*a*b)%MOD;}
      |                                        ^
horses.cpp: In function 'int compute()':
horses.cpp:43:33: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   43 |    actAns=mul(prod,mul(qAns,exp(inProd,MOD-2)));
      |                                 ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 0 ms 2648 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2596 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 2 ms 2392 KB Output is correct
25 Correct 2 ms 2904 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 2 ms 2392 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 171 ms 38348 KB Output is correct
2 Correct 221 ms 41296 KB Output is correct
3 Correct 209 ms 36688 KB Output is correct
4 Correct 230 ms 38736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 2 ms 2392 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 2 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 26 ms 12620 KB Output is correct
34 Correct 26 ms 12972 KB Output is correct
35 Correct 164 ms 39252 KB Output is correct
36 Correct 151 ms 39388 KB Output is correct
37 Correct 23 ms 11608 KB Output is correct
38 Correct 63 ms 23888 KB Output is correct
39 Correct 19 ms 11344 KB Output is correct
40 Correct 151 ms 37292 KB Output is correct
41 Correct 19 ms 11352 KB Output is correct
42 Correct 21 ms 11520 KB Output is correct
43 Correct 141 ms 36944 KB Output is correct
44 Correct 143 ms 36944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2404 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 2 ms 2392 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 2 ms 2648 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 188 ms 36688 KB Output is correct
34 Correct 248 ms 41296 KB Output is correct
35 Correct 210 ms 36604 KB Output is correct
36 Correct 254 ms 38916 KB Output is correct
37 Correct 27 ms 12624 KB Output is correct
38 Correct 25 ms 12624 KB Output is correct
39 Correct 163 ms 39288 KB Output is correct
40 Correct 147 ms 39208 KB Output is correct
41 Correct 24 ms 11600 KB Output is correct
42 Correct 67 ms 24012 KB Output is correct
43 Correct 19 ms 11344 KB Output is correct
44 Correct 137 ms 37244 KB Output is correct
45 Correct 19 ms 11864 KB Output is correct
46 Correct 22 ms 11408 KB Output is correct
47 Correct 141 ms 37348 KB Output is correct
48 Correct 130 ms 36984 KB Output is correct
49 Correct 76 ms 15440 KB Output is correct
50 Correct 69 ms 14928 KB Output is correct
51 Correct 227 ms 40784 KB Output is correct
52 Correct 179 ms 40444 KB Output is correct
53 Correct 100 ms 14160 KB Output is correct
54 Correct 127 ms 27508 KB Output is correct
55 Correct 69 ms 12116 KB Output is correct
56 Correct 205 ms 38096 KB Output is correct
57 Correct 70 ms 12720 KB Output is correct
58 Correct 90 ms 13092 KB Output is correct
59 Correct 142 ms 36944 KB Output is correct