답안 #404138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404138 2021-05-13T21:26:51 Z SavicS 말 (IOI15_horses) C++14
100 / 100
875 ms 89836 KB
#include "horses.h"

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)

using namespace std;
using namespace __gnu_pbds;
typedef __int128 ll;
typedef pair<ll,ll> pii;
const int maxn = 500005;
const int inf = 1e9 + 5;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

int n;
pii niz[maxn];

struct MXSegTree{
	ll bor[4 * maxn];
	void update(int v, int tl, int tr, int pos, ll val){
		if(tl == tr){
			bor[v] = val;
			return;
		}
		int mid = (tl + tr) / 2;
		if(pos <= mid)update(v * 2, tl, mid, pos, val);
		else update(v * 2 + 1, mid + 1, tr, pos, val);
		bor[v] = max(bor[v * 2], bor[v * 2 + 1]);
	}
	
	ll kveri(int v, int tl, int tr, int l, int r){
		if(tl > r || l > tr)return 0;
		if(tl >= l && tr <= r)return bor[v];
		int mid = (tl + tr) / 2;
		return max(kveri(v * 2, tl, mid, l, r), kveri(v * 2 + 1, mid + 1, tr, l, r));
	}	
	
}MX;

const ll mod = 1e9 + 7;
struct MulSegTree{
	ll bor[4 * maxn];
	void update(int v, int tl, int tr, int pos, ll val){
		if(tl == tr){
			bor[v] = val;
			return;
		}
		int mid = (tl + tr) / 2;
		if(pos <= mid)update(v * 2, tl, mid, pos, val);
		else update(v * 2 + 1, mid + 1, tr, pos, val);
		bor[v] = (bor[v * 2] * bor[v * 2 + 1]) % mod;
	}
	
	ll kveri(int v, int tl, int tr, int l, int r){
		if(tl > r || l > tr)return 1;
		if(tl >= l && tr <= r)return bor[v];
		int mid = (tl + tr) / 2;
		return (kveri(v * 2, tl, mid, l, r) * kveri(v * 2 + 1, mid + 1, tr, l, r)) % mod;
	}	
}P;

set<int> s;

ll get(){
	ll cur = 1;
	
	auto it = s.rbegin();
	// u S su mi indeski gde nije 1
	
	vector<int> seg; seg.pb(n + 1);
	while(cur < mod && sz(seg) <= sz(s)){
		cur *= niz[*it].fi, seg.pb(*it);
		it++;
		if(cur >= (ll)mod)break;
	}
	
	reverse(all(seg));
	int len = sz(seg);
	
	ll ans = 0; cur = 1;
	ff(i,0,len - 2){
		int A = seg[i]; cur *= (ll)niz[A].fi;
		
		ans = max(ans, (cur * MX.kveri(1,1,n,A, seg[i + 1] - 1)));
		
	}
	
	if(sz(seg) > sz(s))return max(ans, (ll)MX.bor[1]) % mod;
	else return (ans % (ll)mod * P.kveri(1,1,n,1,seg[0] - 1)) % mod;
	
}

int init(int N, int X[], int Y[]) {
	n = N;
	ff(i,1,n)niz[i] = {X[i - 1], Y[i - 1]};
	
	ff(i,1,n){
		MX.update(1,1,n,i,niz[i].se);
		
		if(niz[i].fi != 1)s.insert(i);
		P.update(1,1,n,i,niz[i].fi);
		
	}
	
	return get();
}

int updateX(int pos, int val) {	
	pos++;
	
	if(niz[pos].fi != 1)s.erase(pos);
	niz[pos].fi = val, P.update(1,1,n,pos,niz[pos].fi);
	if(niz[pos].fi != 1)s.insert(pos);
	
	return get();
}

int updateY(int pos, int val) {
	pos++, niz[pos].se = val, MX.update(1,1,n,pos,val);
	return get();
}

//int main()
//{
//    ios::sync_with_stdio(false);
//    cout.tie(nullptr);
//    cin.tie(nullptr);
//	
//	
//    return 0;
//}
/**

3
2 1 3 
3 2 1

3
2 1 3
3 4 1

// probati bojenje sahovski ili slicno

**/

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:119:12: warning: conversion from 'll' {aka '__int128'} to 'int' may change value [-Wconversion]
  119 |  return get();
      |         ~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:129:12: warning: conversion from 'll' {aka '__int128'} to 'int' may change value [-Wconversion]
  129 |  return get();
      |         ~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:134:12: warning: conversion from 'll' {aka '__int128'} to 'int' may change value [-Wconversion]
  134 |  return get();
      |         ~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 3 ms 460 KB Output is correct
26 Correct 2 ms 440 KB Output is correct
27 Correct 4 ms 460 KB Output is correct
28 Correct 3 ms 460 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 824 ms 77344 KB Output is correct
2 Correct 570 ms 77340 KB Output is correct
3 Correct 581 ms 80872 KB Output is correct
4 Correct 670 ms 84804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 3 ms 460 KB Output is correct
25 Correct 3 ms 460 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 5 ms 460 KB Output is correct
28 Correct 3 ms 460 KB Output is correct
29 Correct 2 ms 444 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 4 ms 460 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
33 Correct 221 ms 56768 KB Output is correct
34 Correct 222 ms 56772 KB Output is correct
35 Correct 383 ms 87152 KB Output is correct
36 Correct 387 ms 87088 KB Output is correct
37 Correct 255 ms 54968 KB Output is correct
38 Correct 287 ms 67776 KB Output is correct
39 Correct 207 ms 54776 KB Output is correct
40 Correct 382 ms 82208 KB Output is correct
41 Correct 228 ms 54928 KB Output is correct
42 Correct 240 ms 54860 KB Output is correct
43 Correct 347 ms 82596 KB Output is correct
44 Correct 354 ms 82504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 3 ms 460 KB Output is correct
26 Correct 2 ms 444 KB Output is correct
27 Correct 4 ms 460 KB Output is correct
28 Correct 3 ms 444 KB Output is correct
29 Correct 2 ms 440 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
33 Correct 821 ms 81020 KB Output is correct
34 Correct 588 ms 89836 KB Output is correct
35 Correct 586 ms 80904 KB Output is correct
36 Correct 689 ms 84808 KB Output is correct
37 Correct 218 ms 56772 KB Output is correct
38 Correct 216 ms 56796 KB Output is correct
39 Correct 384 ms 87144 KB Output is correct
40 Correct 417 ms 87100 KB Output is correct
41 Correct 262 ms 54996 KB Output is correct
42 Correct 287 ms 67740 KB Output is correct
43 Correct 204 ms 54788 KB Output is correct
44 Correct 356 ms 82252 KB Output is correct
45 Correct 224 ms 54852 KB Output is correct
46 Correct 250 ms 54960 KB Output is correct
47 Correct 347 ms 82520 KB Output is correct
48 Correct 393 ms 82656 KB Output is correct
49 Correct 375 ms 59832 KB Output is correct
50 Correct 430 ms 59940 KB Output is correct
51 Correct 551 ms 88944 KB Output is correct
52 Correct 476 ms 88512 KB Output is correct
53 Correct 875 ms 58280 KB Output is correct
54 Correct 579 ms 71640 KB Output is correct
55 Correct 296 ms 55868 KB Output is correct
56 Correct 484 ms 84040 KB Output is correct
57 Correct 536 ms 56640 KB Output is correct
58 Correct 685 ms 56948 KB Output is correct
59 Correct 346 ms 82560 KB Output is correct