Submission #615384

# Submission time Handle Problem Language Result Execution time Memory
615384 2022-07-31T08:45:49 Z 8e7 Horses (IOI15_horses) C++17
17 / 100
573 ms 51196 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 500005
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#include "horses.h"

struct segtree{
	int seg[4*maxn];	
	void init(int cur, int l, int r, int a[]) {
		if (r <= l) return;
		if (r - l == 1){
			seg[cur] = a[l];
			return;
		}
		int m = (l + r) / 2;
		init(cur*2, l, m, a), init(cur*2+1, m, r, a);
		seg[cur] = max(seg[cur*2], seg[cur*2+1]);
	}
	void modify(int cur, int l, int r, int ind, int x){
		if (r <= l) return;
		if (r - l == 1){
			seg[cur] = x;
			return;
		}
		int m = (l + r) / 2;
		if (ind < m) modify(cur*2, l, m, ind, x);
		else modify(cur*2+1, m, r, ind, x);
		seg[cur] = max(seg[cur*2], seg[cur*2+1]);
	}
	int query(int cur, int l, int r, int ql, int qr){
		if (r <= l || ql >= r || qr <= l) return 0;
		if (ql <= l && qr >= r) return seg[cur];
		int m = (l + r) / 2;
		return max(query(cur*2, l, m, ql, qr), query(cur*2+1, m, r, ql, qr));
	}
} tr;
struct BIT{
	ll bit[maxn];
	void init(int n){
		for (int i = 0;i <= n;i++) bit[i] = 1;
	}
	void modify(int ind, ll val) {
		ind++;
		for (;ind < maxn;ind += ind & (-ind)) bit[ind] = bit[ind] * val % mod;
	}
	ll query(int ind) {
		ind++;
		ll ret = 1;
		for (;ind > 0;ind -= ind & (-ind)) ret = ret * bit[ind] % mod;
		return ret;
	}
} bit;
ll modpow(ll x, ll p){
	ll ret = 1;
	while (p) {
		if (p & 1) ret = ret * x % mod;
		p >>= 1, x = x * x % mod;
	}
	return ret;
}
const ll inf = 1e9;
int n;
int a[maxn];
set<int> se;

int query() {
	pary(se.begin(), se.end());
	ll ret = 0;	
	ll suf = 1;
	auto it = prev(se.end());
	vector<ll> v, mul;
	while (true) {
		bool fi = it == se.begin();
		int lef = (fi ? 0 : *prev(it)), rig = *it; //[lef, rig)	
		ll val = max(suf, (ll)tr.query(1, 0, n, lef, rig));
		v.push_back(val);
		ll m = fi ? 1 : a[*prev(it)];
		mul.push_back(m);
		suf *= m;
		if (fi || suf >= inf) {
			reverse(v.begin(), v.end());
			reverse(mul.begin(), mul.end());
			pary(v.begin(), v.end());
			pary(mul.begin(), mul.end());
			ll pref = fi ? 1: bit.query(*prev(it) - 1);
			ll best = 0, p = 1;
			for	(int i = 0;i < v.size();i++) {
				p *= mul[i];
				best = max(best, p * v[i]);	
			}
			ret = (best % mod) * pref % mod;
			return ret;
		}
		it = prev(it);
	}
}
int init(int N, int X[], int Y[]) {
	n = N;
	bit.init(n);	
	for (int i = 0;i < n;i++) {
		a[i] = X[i];
		if (a[i] > 1) se.insert(i);
		bit.modify(i, X[i]);
	}
	se.insert(n);
	tr.init(1, 0, n, Y);
	return query();
}

int updateX(int pos, int val) {	
	bit.modify(pos, modpow(a[pos], mod - 2));
	if (a[pos] > 1) {
		se.erase(se.find(pos));
	}
	a[pos] = val;
	if (a[pos] > 1) {
		se.insert(pos);
	}
	bit.modify(pos, val);
	return query();
}

int updateY(int pos, int val) {
	tr.modify(1, 0, n, pos, val);
	return query();
}

Compilation message

horses.cpp: In function 'int query()':
horses.cpp:13:19: warning: statement has no effect [-Wunused-value]
   13 | #define pary(...) 0
      |                   ^
horses.cpp:83:2: note: in expansion of macro 'pary'
   83 |  pary(se.begin(), se.end());
      |  ^~~~
horses.cpp:13:19: warning: statement has no effect [-Wunused-value]
   13 | #define pary(...) 0
      |                   ^
horses.cpp:99:4: note: in expansion of macro 'pary'
   99 |    pary(v.begin(), v.end());
      |    ^~~~
horses.cpp:13:19: warning: statement has no effect [-Wunused-value]
   13 | #define pary(...) 0
      |                   ^
horses.cpp:100:4: note: in expansion of macro 'pary'
  100 |    pary(mul.begin(), mul.end());
      |    ^~~~
horses.cpp:103:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |    for (int i = 0;i < v.size();i++) {
      |                   ~~^~~~~~~~~~
horses.cpp:108:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  108 |    return ret;
      |           ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Incorrect 1 ms 340 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 573 ms 42368 KB Output is correct
2 Correct 309 ms 51196 KB Output is correct
3 Correct 354 ms 42460 KB Output is correct
4 Incorrect 415 ms 46300 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Incorrect 1 ms 340 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Incorrect 1 ms 416 KB Output isn't correct
24 Halted 0 ms 0 KB -