답안 #795475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795475 2023-07-27T10:13:32 Z Cauchico 말 (IOI15_horses) C++14
100 / 100
964 ms 69196 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define long long int;

int n;
set<pair<int,int>> s;
vector<ll> x,y,tx,ty;
ll MOD = 1e9 + 7;

void Xupdate(int v, int tl, int tr, ll pos, ll val) {
	if (tl > pos or tr < pos) return;
	if (tl == tr) tx[v] = val;
	else {
		int tm = (tr+tl)/2;
		Xupdate(2*v,tl,tm,pos,val);
		Xupdate(2*v+1,tm+1,tr,pos,val);
		tx[v] = (tx[2*v]*tx[2*v+1])%MOD;
	}
}
void Yupdate(int v, int tl, int tr, ll pos, ll val) {
	if (tl > pos or tr < pos) return;
	if (tl == tr) ty[v] = val;
	else {
		int tm = (tr+tl)/2;
		Yupdate(2*v,tl,tm,pos,val);
		Yupdate(2*v+1,tm+1,tr,pos,val);
		ty[v] = max(ty[2*v],ty[2*v+1]);
	}
}
ll Xquery(int v, int tl, int tr, ll l, ll r) {
	if (tl > r or tr < l) return 1LL;
	else if (tl >= l and tr <= r) return tx[v];
	else {
		int tm = (tr+tl)/2;
		return (Xquery(2*v,tl,tm,l,r)*Xquery(2*v+1,tm+1,tr,l,r))%MOD;
	}
}
ll Yquery(int v, int tl, int tr, ll l, ll r) {
	if (tl > r or tr < l) return 0LL;
	else if (tl >= l and tr <= r) return ty[v];
	else {
		int tm = (tr+tl)/2;
		return max(Yquery(2*v,tl,tm,l,r), Yquery(2*v+1,tm+1,tr,l,r));
	}
}

int update() {
	auto can = s.end();
	for (int i=0;i<=32 and can != s.begin();i++) can--;
	bool in1 = !(can->first);
	while (can != s.end() and !can->first) can++;
	if (can == s.end()) return Yquery(1,0,n-1,0,n-1);
	//ll ans = can->second-1, mxy=(in1 ? Yquery(1,0,n-1,0,ans-1) : y[ans]);
	ll ans,mxy,px=1;
	if (!in1) ans = can->second, mxy = y[ans];
	else {
		ans = can->second-1;
		mxy = Yquery(1,0,n-1,0,ans);
	}
	//cout << Yquery(1,0,n-1,0,2) << " hmm \n";
	while (can != s.end()) {
		int i = can->second;
		//cout << i << " " << px << " " << Yquery(1,0,n-1,3,3) << "\n";
		auto nxt = can; nxt++;
		int nx;
		if (nxt == s.end()) {
			nx = n-1;
		} else {
			nx = nxt->second-1;
		}
		ll xi = x[i], yi = Yquery(1,0,n-1,i,nx); 
		//cout << "i, nx, mxy " << i << " " << nx << " " << yi << "\n";
		if (px*xi > MOD or mxy < px*xi*yi) {
			ans = i; px = 1; mxy = yi;
		} else {
			px *= xi;
		}
		can++;
	}
	//cout << ans << " " << s.size() << " ";
	return (int) ((1LL*mxy*Xquery(1,0,n-1,0,ans))%MOD);
}



int init(int N, int X[], int Y[]) {
	//return 42; 
	n = N; x.resize(n); y.resize(n);
	tx.resize(4*n,1); ty.resize(4*n,0);
	for (int i=0;i<n;i++) {
		x[i] = X[i]; y[i] = Y[i];
		s.insert({x[i]>1,i});
		Xupdate(1,0,n-1,i,x[i]);
		Yupdate(1,0,n-1,i,y[i]);
	}
	//cout << Xquery(1,0,n-1,0,1) <<" ";
	return update();
}

int updateX(int pos, int val) {	
	//return 43;
	s.erase({x[pos]>1,pos});
	s.insert({val>1,pos});
	x[pos] = val;
	Xupdate(1,0,n-1,pos,val);
	return update();
	
}

int updateY(int pos, int val) {
	//return 44;
	y[pos] = val;
	Yupdate(1,0,n-1,pos,val);
	return update();
}


/*signed main() {
	freopen("horses.in", "r+",stdin);
	freopen("horses.out", "w+",stdout);
	int n_; cin >> n_;
	int X[n_], Y[n_];
	for (int i=0;i<n_;i++) {
		cin >> X[i];
	}
	for (int i=0;i<n_;i++) {
		cin >> Y[i];
	}
	cout << init(n_,X,Y) << "\n";
	int m; cin >> m;
	while (m--) {
		int a,b,c; cin >> a >> b >> c;
		if (a==1) {
			cout << updateX(b,c) << "\n";
		} else {
			cout << updateY(b,c) << "\n"; 
		}
	}
}*/

Compilation message

horses.cpp: In function 'int update()':
horses.cpp:54:35: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   54 |  if (can == s.end()) return Yquery(1,0,n-1,0,n-1);
      |                             ~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 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 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 304 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
5 Correct 1 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 300 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 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 300 KB Output is correct
18 Correct 1 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 4 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 4 ms 444 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 787 ms 68564 KB Output is correct
2 Correct 846 ms 68136 KB Output is correct
3 Correct 805 ms 68168 KB Output is correct
4 Correct 863 ms 68100 KB Output is correct
# 결과 실행 시간 메모리 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 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 1 ms 252 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 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 296 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 5 ms 340 KB Output is correct
24 Correct 3 ms 436 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 2 ms 440 KB Output is correct
30 Correct 4 ms 568 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 5 ms 440 KB Output is correct
33 Correct 381 ms 67404 KB Output is correct
34 Correct 357 ms 67396 KB Output is correct
35 Correct 380 ms 67356 KB Output is correct
36 Correct 390 ms 67400 KB Output is correct
37 Correct 364 ms 67400 KB Output is correct
38 Correct 363 ms 67480 KB Output is correct
39 Correct 319 ms 67376 KB Output is correct
40 Correct 388 ms 67472 KB Output is correct
41 Correct 328 ms 67404 KB Output is correct
42 Correct 337 ms 67448 KB Output is correct
43 Correct 327 ms 67436 KB Output is correct
44 Correct 330 ms 67464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 1 ms 216 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 296 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 1 ms 212 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 304 KB Output is correct
13 Correct 1 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 1 ms 296 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 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 1 ms 212 KB Output is correct
22 Correct 0 ms 304 KB Output is correct
23 Correct 4 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 3 ms 440 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 5 ms 440 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 747 ms 69196 KB Output is correct
34 Correct 863 ms 68568 KB Output is correct
35 Correct 810 ms 68584 KB Output is correct
36 Correct 857 ms 68604 KB Output is correct
37 Correct 406 ms 67624 KB Output is correct
38 Correct 365 ms 67452 KB Output is correct
39 Correct 453 ms 67684 KB Output is correct
40 Correct 395 ms 67872 KB Output is correct
41 Correct 383 ms 67404 KB Output is correct
42 Correct 392 ms 67480 KB Output is correct
43 Correct 310 ms 67324 KB Output is correct
44 Correct 412 ms 67616 KB Output is correct
45 Correct 322 ms 67568 KB Output is correct
46 Correct 337 ms 67620 KB Output is correct
47 Correct 355 ms 67544 KB Output is correct
48 Correct 334 ms 67560 KB Output is correct
49 Correct 964 ms 68544 KB Output is correct
50 Correct 832 ms 68544 KB Output is correct
51 Correct 807 ms 68696 KB Output is correct
52 Correct 819 ms 68624 KB Output is correct
53 Correct 912 ms 68528 KB Output is correct
54 Correct 858 ms 68428 KB Output is correct
55 Correct 442 ms 67732 KB Output is correct
56 Correct 868 ms 68528 KB Output is correct
57 Correct 592 ms 68396 KB Output is correct
58 Correct 790 ms 68512 KB Output is correct
59 Correct 343 ms 67596 KB Output is correct