Submission #819916

# Submission time Handle Problem Language Result Execution time Memory
819916 2023-08-10T15:30:54 Z Kerim Horses (IOI15_horses) C++17
34 / 100
1500 ms 21232 KB
#include "horses.h"
#include "bits/stdc++.h"
#define ff first
#define ss second
using namespace std;
typedef pair<int,int> pii;
const int MAXN = 5e5+5;
const int INF = 1e9+7;
int a[MAXN], b[MAXN], n;

pii s[MAXN<<2];
int ans[MAXN<<2];

pii merge(pii x, pii y){
	pii z;
	z.ff = min(x.ff * 1LL * y.ff, INF * 1LL);
	z.ss = (x.ss * 1LL * y.ss) % INF;
	return z;
}

pii get(int l, int r, int nd, int x, int y){
	if (l > y or x > r)
		return {1, 1};
	if (l <= x and y <= r)
		return s[nd];
	int mid = (x+y) >> 1;
	return merge(get(l, r, nd<<1, x, mid), get(l, r, nd<<1|1, mid+1, y));
}

int cmp(int x, int y){
	if (x == y)
		return 0;
	if (x > y)
		swap(x, y);
	return b[x] < b[y] * 1LL * get(x+1, y, 1, 0, n-1).ff;
}

void upd(int p, int nd, int x, int y){
	if (x == y){
		ans[nd] = x;
		s[nd].ff = s[nd].ss = a[p];
		return;
	}
	int mid = (x+y) >> 1;
	if (p <= mid)
		upd(p, nd<<1, x, mid);
	else	
		upd(p, nd<<1|1, mid+1, y);
	s[nd] = merge(s[nd<<1], s[nd<<1|1]);
	if (cmp(ans[nd<<1], ans[nd<<1|1]))
		ans[nd] = ans[nd<<1|1];
	else
		ans[nd] = ans[nd<<1];
}


int ask(int pos){
	return (get(0, pos, 1, 0, n-1).ss *1LL* b[pos]) % INF;
}

int init(int N, int X[], int Y[]) {
	n = N;
	for (int i = 0; i < n; i++){
		a[i] = X[i], b[i] = Y[i];
		upd(i, 1, 0, n-1);
	}
	return ask(ans[1]);
}

int updateX(int pos, int val) {	
	a[pos] = val;
	upd(pos, 1, 0, n-1);
	return ask(ans[1]);
}

int updateY(int pos, int val) {
	b[pos] = val;
	upd(pos, 1, 0, n-1);
	return ask(ans[1]);
}

Compilation message

horses.cpp: In function 'pii merge(pii, pii)':
horses.cpp:16:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   16 |  z.ff = min(x.ff * 1LL * y.ff, INF * 1LL);
      |         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:17:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   17 |  z.ss = (x.ss * 1LL * y.ss) % INF;
      |         ~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int ask(int)':
horses.cpp:58:50: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   58 |  return (get(0, pos, 1, 0, n-1).ss *1LL* b[pos]) % INF;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# 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 1 ms 292 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 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
# 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 1 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 1 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 1 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 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 3 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1574 ms 21232 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 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 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 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 3 ms 372 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 3 ms 340 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Execution timed out 1587 ms 19572 KB Time limit exceeded
34 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 1 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 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 1 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 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 3 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 368 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Execution timed out 1585 ms 21164 KB Time limit exceeded
34 Halted 0 ms 0 KB -