Submission #795301

# Submission time Handle Problem Language Result Execution time Memory
795301 2023-07-27T08:14:46 Z Josia Horses (IOI15_horses) C++17
34 / 100
1500 ms 85544 KB
#include "horses.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define int long long

const ll mod = 1e9+7;

struct seg {
	vector<int> tree;

	void init(int n) {
		tree.assign(n*4, 0);
	}

	void update(int v, int rl, int rr, int pos, int x) {
		if (rl == rr) {
			tree[v] = x;
			return;
		}

		int rm = (rl + rr)/2;

		if (pos <= rm) update(v*2, rl, rm, pos, x);
		else update(v*2+1, rm+1, rr, pos, x);

		tree[v] = max(tree[v*2], tree[v*2+1]);
	}

	int query(int v, int rl, int rr, int ql, int qr) {
		if (ql > qr) return 0;

		if (rl == ql && rr == qr) return tree[v];

		int rm = (rl + rr)/2;

		return max(query(v*2, rl, rm, ql, min(qr, rm)), query(v*2+1, rm+1, rr, max(ql, rm+1), qr));
	}
};


struct segY {
	vector<pair<int, int>> tree;

	void init(int n) {
		tree.assign(n*4, {0, 0});
	}

	void update(int v, int rl, int rr, int pos, int x) {
		if (rl == rr) {
			tree[v] = {x, pos};
			return;
		}

		int rm = (rl + rr)/2;

		if (pos <= rm) update(v*2, rl, rm, pos, x);
		else update(v*2+1, rm+1, rr, pos, x);

		tree[v] = max(tree[v*2], tree[v*2+1]);
	}

	pair<int, int> query(int v, int rl, int rr, int ql, int qr) {
		if (ql > qr) return {0, -1};

		if (rl == ql && rr == qr) return tree[v];

		int rm = (rl + rr)/2;

		return max(query(v*2, rl, rm, ql, min(qr, rm)), query(v*2+1, rm+1, rr, max(ql, rm+1), qr));
	}
};


ll mult(ll a, ll b) {
	return (a*b)%mod;
}

struct seg2 {
	vector<ll> tree;

	void init(int n) {
		tree.assign(n*4, 0);
	}

	void update(int v, int rl, int rr, int pos, int x) {
		if (rl == rr) {
			tree[v] = x;
			return;
		}

		int rm = (rl + rr)/2;

		if (pos <= rm) update(v*2, rl, rm, pos, x);
		else update(v*2+1, rm+1, rr, pos, x);

		tree[v] = mult(tree[v*2], tree[v*2+1]);
	}

	ll query(int v, int rl, int rr, int ql, int qr) {
		if (ql > qr) return 1;

		if (rl == ql && rr == qr) return tree[v];

		int rm = (rl + rr)/2;

		return mult(query(v*2, rl, rm, ql, min(qr, rm)), query(v*2+1, rm+1, rr, max(ql, rm+1), qr));
	}
};


seg tree;
segY treeY;
seg2 tree2;
int N;
vector<ll> X, Y;

struct getSol {
	int sol = 0;

	int BS(int pos) {
		if (pos == 0) return -1;
		int l = 0, r = pos-1;
		while (l<r) {
			int m = (l+r+1)/2;
			// cerr << m << " " << pos-1 << " " << tree.query(1, 0, N-1, m, pos-1) << "\n";
			if (tree.query(1, 0, N-1, m, pos-1) > 1) {
				l = m;
			} else {
				r = m-1;
			}
		}

		// if (tree.query(1, 0, N-1, l, pos-1) <= 1) return -1;

		return l;
	}

	int BSinv(int pos) {
		if (pos == N-1) return N-1;
		int l = pos+1, r = N-1;
		while (l<r) {
			int m = (l+r+1)/2;
			// cerr << m << " " << pos-1 << " " << tree.query(1, 0, N-1, m, pos-1) << "\n";
			if (tree.query(1, 0, N-1, pos+1, m) > 1) {
				r = m-1;
			} else {
				l = m;
			}
		}

		return l;
	}


	int findInd() {
		int currInd = N-1;
		ll currProd = 1;
		for (int i = N-1; i>=0; i = BS(i)) {
			// cerr << i << " " << currProd << " " << currInd << " " << BSinv(i) << "\n";
			if (currProd*Y[currInd] <= treeY.query(1, 0, N-1, i, BSinv(i)).first) {currInd = treeY.query(1, 0, N-1, i, BSinv(i)).second; currProd=1;}

			currProd *= X[i];
			if (currProd*Y[currInd] > 1e9) break;
		}
		return currInd;
	}


	getSol() {
		int ind = findInd();
		// cerr << ind << " " << tree2.query(1, 0, N-1, 0, ind) << " " << Y[ind] << "\n\n";

		sol = (tree2.query(1, 0, N-1, 0, ind) * Y[ind])%mod;
	}
};




signed init(signed _N, signed _X[], signed _Y[]) {
	N = _N;
	X.resize(N);
	Y.resize(N);
	for (int i = 0; i<N; i++) X[i] = _X[i];
	for (int i = 0; i<N; i++) Y[i] = _Y[i];

	tree.init(N);
	treeY.init(N);
	tree2.init(N);

	for (int i = 0; i<N; i++) {
		tree.update(1, 0, N-1, i, X[i]);
		treeY.update(1, 0, N-1, i, Y[i]);
		tree2.update(1, 0, N-1, i, X[i]);
	}
	return getSol().sol;
}

signed updateX(signed pos, signed val) {
	tree.update(1, 0, N-1, pos, val);
	tree2.update(1, 0, N-1, pos, val);
	X[pos] = val;

	return getSol().sol;
}

signed updateY(signed pos, signed val) {
	treeY.update(1, 0, N-1, pos, val);
	Y[pos] = val;

	return getSol().sol;
}

Compilation message

horses.cpp: In member function 'long long int getSol::findInd()':
horses.cpp:166:16: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
  166 |    if (currProd*Y[currInd] > 1e9) break;
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:199:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  199 |  return getSol().sol;
      |         ~~~~~~~~~^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:207:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  207 |  return getSol().sol;
      |         ~~~~~~~~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:214:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  214 |  return getSol().sol;
      |         ~~~~~~~~~^~~
# 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 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 1 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 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 1 ms 212 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 5 ms 436 KB Output is correct
26 Correct 1 ms 440 KB Output is correct
27 Correct 28 ms 468 KB Output is correct
28 Correct 6 ms 468 KB Output is correct
29 Correct 6 ms 456 KB Output is correct
30 Correct 5 ms 440 KB Output is correct
31 Correct 16 ms 472 KB Output is correct
32 Correct 26 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1576 ms 74984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
15 Correct 1 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 292 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 28 ms 468 KB Output is correct
28 Correct 6 ms 468 KB Output is correct
29 Correct 6 ms 340 KB Output is correct
30 Correct 4 ms 468 KB Output is correct
31 Correct 16 ms 468 KB Output is correct
32 Correct 27 ms 468 KB Output is correct
33 Correct 262 ms 78592 KB Output is correct
34 Correct 201 ms 78596 KB Output is correct
35 Correct 343 ms 85544 KB Output is correct
36 Correct 219 ms 85472 KB Output is correct
37 Execution timed out 1580 ms 76776 KB Time limit exceeded
38 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 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 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 1 ms 212 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 28 ms 468 KB Output is correct
28 Correct 9 ms 468 KB Output is correct
29 Correct 6 ms 340 KB Output is correct
30 Correct 5 ms 468 KB Output is correct
31 Correct 16 ms 460 KB Output is correct
32 Correct 26 ms 464 KB Output is correct
33 Execution timed out 1574 ms 77456 KB Time limit exceeded
34 Halted 0 ms 0 KB -