답안 #868079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868079 2023-10-30T11:36:56 Z waldi 말 (IOI15_horses) C++17
100 / 100
167 ms 65040 KB
#include "horses.h"
#include <bits/stdc++.h>
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define debug(a) cerr << #a << ": " << a << "\n";
#define maxc 1000000000ll
#define ssize(x) (int(x.size()))
#define mod 1000000007ll
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;



struct prz_ilo{
	int N;
	vector<ll> drz;
	void inicjalizuj(vector<ll> vec){
		int n = ssize(vec);
		for(N = 1; N < n;) N <<= 1;
		drz.resize(N<<1, 1ll);
		REP(i, n) drz[N+i] = vec[i];
		for(int i = N; --i;) drz[i] = (drz[i<<1]*drz[i<<1|1])%mod;
	}
	ll wart(int poz){
		return drz[N+poz];
	}
	void ustaw(int poz, ll wart){
		for(poz+=N, drz[poz]=wart; poz>>=1;) drz[poz] = (drz[poz<<1]*drz[poz<<1|1])%mod;
	}
	ll ilo(int p, int k){
		ll ret = 1ll;
		for(p+=N, k+=N+1; p<k; p>>=1, k>>=1){
			if(p&1) ret = (ret*drz[p++])%mod;
			if(k&1) ret = (ret*drz[--k])%mod;
		}
		return ret;
	}
} prz_ilo;// na ciagu x



struct prz_maks{
	int N;
	vector<ll> drz;
	void inicjalizuj(vector<ll> vec){
		int n = ssize(vec);
		for(N = 1; N < n;) N <<= 1;
		drz.resize(N<<1, 0ll);
		REP(i, n) drz[N+i] = vec[i];
		for(int i = N; --i;) drz[i] = max(drz[i<<1], drz[i<<1|1]);
	}
	ll wart(int poz){
		return drz[N+poz];
	}
	void ustaw(int poz, ll wart){
		for(poz+=N, drz[poz]=wart; poz>>=1;) drz[poz] = max(drz[poz<<1], drz[poz<<1|1]);
	}
	ll maks(int p, int k){
		ll ret = 0ll;
		for(p+=N, k+=N+1; p<k; p>>=1, k>>=1){
			if(p&1) ret = max(ret, drz[p++]);
			if(k&1) ret = max(ret, drz[--k]);
		}
		return ret;
	}
} prz_maks;// na ciagu y



int n;
set<int> nie1;// pozycje nie1 w ciagu x, ale pozycja 0 zawsze jest
int wynik(){
	ll wyn = -1ll, musze = -1ll;
	for(auto it = prev(nie1.end()); 1; it = prev(it)){
		if(musze > maxc) break;
		ll maks = prz_maks.maks(*it, n-1);
		if(maks > musze) wyn = (prz_ilo.ilo(0, *it)*maks)%mod, musze = maks;
		musze *= prz_ilo.wart(*it);
		if(it == nie1.begin()) break;
	}
	return wyn;
}



int init(int nn, int xint[], int yint[]){
	n = nn;
	vector<ll> x(n), y(n);
	REP(i, n) x[i] = xint[i], y[i] = yint[i];
	
	/*ll wyn = 0ll;
	REP(i, n){
		ll tmp = y[i];
		FOR(j, 0, i) tmp *= x[j];
		wyn = max(wyn, tmp);
	}
	return wyn;*/
	
	prz_ilo.inicjalizuj(x);
	prz_maks.inicjalizuj(y);
	vector<int> vecnie1;
	REP(i, n) if(!i || x[i] > 1ll) vecnie1.emplace_back(i);
	nie1 = set<int>(all(vecnie1));
	
	return wynik();
}



int updateX(int poz, int wart){	
	prz_ilo.ustaw(poz, wart);
	if(!poz || wart > 1) nie1.emplace(poz);
	else nie1.erase(poz);
	return wynik();
}



int updateY(int poz, int wart){
	prz_maks.ustaw(poz, wart);
	return wynik();
}

Compilation message

horses.cpp: In function 'int wynik()':
horses.cpp:82:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   82 |  return wyn;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 54028 KB Output is correct
2 Correct 166 ms 65040 KB Output is correct
3 Correct 127 ms 56244 KB Output is correct
4 Correct 164 ms 60024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 448 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 31 ms 36388 KB Output is correct
34 Correct 30 ms 36364 KB Output is correct
35 Correct 91 ms 64836 KB Output is correct
36 Correct 85 ms 64784 KB Output is correct
37 Correct 31 ms 34580 KB Output is correct
38 Correct 44 ms 44308 KB Output is correct
39 Correct 22 ms 34316 KB Output is correct
40 Correct 70 ms 59888 KB Output is correct
41 Correct 23 ms 34320 KB Output is correct
42 Correct 25 ms 34628 KB Output is correct
43 Correct 70 ms 60176 KB Output is correct
44 Correct 66 ms 60260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 444 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 116 ms 56016 KB Output is correct
34 Correct 162 ms 64836 KB Output is correct
35 Correct 129 ms 56132 KB Output is correct
36 Correct 167 ms 59876 KB Output is correct
37 Correct 30 ms 36360 KB Output is correct
38 Correct 32 ms 36204 KB Output is correct
39 Correct 85 ms 64780 KB Output is correct
40 Correct 83 ms 64784 KB Output is correct
41 Correct 30 ms 34584 KB Output is correct
42 Correct 41 ms 44312 KB Output is correct
43 Correct 26 ms 34584 KB Output is correct
44 Correct 71 ms 59920 KB Output is correct
45 Correct 22 ms 34572 KB Output is correct
46 Correct 25 ms 34576 KB Output is correct
47 Correct 67 ms 60176 KB Output is correct
48 Correct 67 ms 60176 KB Output is correct
49 Correct 68 ms 36368 KB Output is correct
50 Correct 66 ms 36368 KB Output is correct
51 Correct 127 ms 64896 KB Output is correct
52 Correct 127 ms 65040 KB Output is correct
53 Correct 112 ms 34584 KB Output is correct
54 Correct 83 ms 44416 KB Output is correct
55 Correct 57 ms 34576 KB Output is correct
56 Correct 120 ms 59920 KB Output is correct
57 Correct 61 ms 34576 KB Output is correct
58 Correct 83 ms 34604 KB Output is correct
59 Correct 69 ms 60364 KB Output is correct