답안 #798728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
798728 2023-07-31T02:11:28 Z Username4132 말 (IOI15_horses) C++14
100 / 100
263 ms 52896 KB
#include "horses.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define dforn(i, n) for(int i=n-1; i>=0; --i)
#define dforsn(i, s, n) for(int i=n-1; i>=s; --i)
#define PB push_back
#define F first
#define S second


struct node{
	int pr;
	pii mx;
	node(int _pr=0, pii _mx={0, 0}) : pr(_pr), mx(_mx) {}
};

const int MAXN = 500010, MOD = 1000000007;
int n;
node tr[2*MAXN];
set<int> ones;

node combine(node a, node b){
	return node((a.pr*((ll)b.pr))%MOD, max(a.mx, b.mx));
}

void update(int p, node value){
	p+=n;
	tr[p]=value;
	while(p>1) p>>=1, tr[p]=combine(tr[p<<1], tr[p<<1|1]);
}
 
node query(int l, int r){
	node ret = node(1, {0, -1});
	for(l+=n, r+=n; l<r; l>>=1, r>>=1){
		if(l&1) ret = combine(ret, tr[l++]);
		if(r&1) ret = combine(ret, tr[--r]);
	}
	return ret;
} 
 
int solve(){
	ll prod=1;
	vector<int> lis;
	int sz = ones.size();
 
	auto itr = ones.end();
	forn(i, sz){
		itr = prev(itr);
		prod*=tr[n + *itr].pr;
		lis.PB(*itr);
		if(prod>1000000010) break;
	}
	reverse(lis.begin(), lis.end());
 
	pli basic = query(0, n).mx;
	if(lis.empty()) return basic.F;

	ll p=1;
	pli mx={-1, -1};
	for(int el:lis){
		if(el!=lis.front()) p*=tr[n + el].pr;
		pli opt = query(el, n).mx;
		opt.F*=p;
		mx = max(mx, opt);
	}
	if(mx.F > (basic.F / tr[n + lis.front()].pr)) return (tr[n+mx.S].mx.F*((ll)query(0, mx.S + 1).pr))%MOD;
	else return basic.F;
}
 
int init(int N, int X[], int Y[]) {
	n=N;
	forn(i, n){
		tr[n+i]=node(X[i], {Y[i], i});
		if(tr[n+i].pr!=1) ones.insert(i);
	}
	dforsn(i, 1, n) tr[i]=combine(tr[i<<1], tr[i<<1|1]);
	return solve();
}
 
int updateX(int pos, int val) {	
	if(tr[n+pos].pr==1 && val!=1) ones.insert(pos);
	if(tr[n+pos].pr!=1 && val==1) ones.erase(pos);
	update(pos, node(val, tr[n+pos].mx));
	return solve();
}
 
int updateY(int pos, int val) {
	update(pos, node(tr[n+pos].pr, {val, pos}));
	return solve();
}

Compilation message

horses.cpp: In function 'node combine(node, node)':
horses.cpp:31:31: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   31 |  return node((a.pr*((ll)b.pr))%MOD, max(a.mx, b.mx));
      |              ~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int solve()':
horses.cpp:52:20: warning: conversion from 'std::set<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   52 |  int sz = ones.size();
      |           ~~~~~~~~~^~
horses.cpp:15:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   15 | #define F first
      |           ^
horses.cpp:64:31: note: in expansion of macro 'F'
   64 |  if(lis.empty()) return basic.F;
      |                               ^
horses.cpp:74:100: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   74 |  if(mx.F > (basic.F / tr[n + lis.front()].pr)) return (tr[n+mx.S].mx.F*((ll)query(0, mx.S + 1).pr))%MOD;
      |                                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp:15:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   15 | #define F first
      |           ^
horses.cpp:75:20: note: in expansion of macro 'F'
   75 |  else return basic.F;
      |                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11988 KB Output is correct
2 Correct 5 ms 11976 KB Output is correct
3 Correct 5 ms 11988 KB Output is correct
4 Correct 5 ms 11988 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 5 ms 11988 KB Output is correct
8 Correct 5 ms 12048 KB Output is correct
9 Correct 5 ms 11988 KB Output is correct
10 Correct 5 ms 11988 KB Output is correct
11 Correct 5 ms 11988 KB Output is correct
12 Correct 5 ms 11988 KB Output is correct
13 Correct 6 ms 11988 KB Output is correct
14 Correct 5 ms 11988 KB Output is correct
15 Correct 5 ms 11988 KB Output is correct
16 Correct 5 ms 11988 KB Output is correct
17 Correct 5 ms 11988 KB Output is correct
18 Correct 5 ms 11988 KB Output is correct
19 Correct 5 ms 11988 KB Output is correct
20 Correct 7 ms 11988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11956 KB Output is correct
2 Correct 5 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 5 ms 11988 KB Output is correct
5 Correct 5 ms 11940 KB Output is correct
6 Correct 5 ms 11976 KB Output is correct
7 Correct 5 ms 11988 KB Output is correct
8 Correct 5 ms 11988 KB Output is correct
9 Correct 5 ms 11988 KB Output is correct
10 Correct 5 ms 11988 KB Output is correct
11 Correct 5 ms 11988 KB Output is correct
12 Correct 5 ms 11988 KB Output is correct
13 Correct 6 ms 11988 KB Output is correct
14 Correct 5 ms 11988 KB Output is correct
15 Correct 5 ms 12000 KB Output is correct
16 Correct 5 ms 11988 KB Output is correct
17 Correct 5 ms 12036 KB Output is correct
18 Correct 5 ms 11988 KB Output is correct
19 Correct 5 ms 12040 KB Output is correct
20 Correct 5 ms 11988 KB Output is correct
21 Correct 5 ms 11988 KB Output is correct
22 Correct 6 ms 11988 KB Output is correct
23 Correct 6 ms 11988 KB Output is correct
24 Correct 6 ms 11984 KB Output is correct
25 Correct 6 ms 12056 KB Output is correct
26 Correct 8 ms 12116 KB Output is correct
27 Correct 7 ms 11988 KB Output is correct
28 Correct 6 ms 12116 KB Output is correct
29 Correct 6 ms 11988 KB Output is correct
30 Correct 6 ms 12168 KB Output is correct
31 Correct 8 ms 12044 KB Output is correct
32 Correct 6 ms 11988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 40460 KB Output is correct
2 Correct 199 ms 52896 KB Output is correct
3 Correct 181 ms 44192 KB Output is correct
4 Correct 213 ms 47968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11988 KB Output is correct
2 Correct 5 ms 11988 KB Output is correct
3 Correct 5 ms 11988 KB Output is correct
4 Correct 4 ms 11988 KB Output is correct
5 Correct 5 ms 11988 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 7 ms 11988 KB Output is correct
8 Correct 5 ms 11988 KB Output is correct
9 Correct 7 ms 11988 KB Output is correct
10 Correct 7 ms 11988 KB Output is correct
11 Correct 5 ms 12044 KB Output is correct
12 Correct 5 ms 11988 KB Output is correct
13 Correct 5 ms 11988 KB Output is correct
14 Correct 5 ms 11992 KB Output is correct
15 Correct 7 ms 11948 KB Output is correct
16 Correct 5 ms 11988 KB Output is correct
17 Correct 5 ms 11988 KB Output is correct
18 Correct 5 ms 11988 KB Output is correct
19 Correct 6 ms 11988 KB Output is correct
20 Correct 5 ms 11988 KB Output is correct
21 Correct 5 ms 12020 KB Output is correct
22 Correct 6 ms 12040 KB Output is correct
23 Correct 7 ms 11972 KB Output is correct
24 Correct 6 ms 11988 KB Output is correct
25 Correct 6 ms 12056 KB Output is correct
26 Correct 6 ms 12056 KB Output is correct
27 Correct 7 ms 11984 KB Output is correct
28 Correct 6 ms 12064 KB Output is correct
29 Correct 6 ms 12048 KB Output is correct
30 Correct 6 ms 12116 KB Output is correct
31 Correct 6 ms 12056 KB Output is correct
32 Correct 7 ms 12060 KB Output is correct
33 Correct 40 ms 18840 KB Output is correct
34 Correct 35 ms 19992 KB Output is correct
35 Correct 145 ms 50308 KB Output is correct
36 Correct 147 ms 50252 KB Output is correct
37 Correct 38 ms 18244 KB Output is correct
38 Correct 73 ms 30992 KB Output is correct
39 Correct 24 ms 18124 KB Output is correct
40 Correct 139 ms 45356 KB Output is correct
41 Correct 26 ms 18084 KB Output is correct
42 Correct 28 ms 18048 KB Output is correct
43 Correct 124 ms 45812 KB Output is correct
44 Correct 127 ms 45852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11988 KB Output is correct
2 Correct 5 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 6 ms 11988 KB Output is correct
5 Correct 5 ms 11988 KB Output is correct
6 Correct 6 ms 12008 KB Output is correct
7 Correct 5 ms 11996 KB Output is correct
8 Correct 5 ms 11988 KB Output is correct
9 Correct 5 ms 11956 KB Output is correct
10 Correct 6 ms 11988 KB Output is correct
11 Correct 5 ms 11988 KB Output is correct
12 Correct 5 ms 11988 KB Output is correct
13 Correct 5 ms 11988 KB Output is correct
14 Correct 5 ms 11988 KB Output is correct
15 Correct 5 ms 12116 KB Output is correct
16 Correct 5 ms 11988 KB Output is correct
17 Correct 5 ms 11988 KB Output is correct
18 Correct 5 ms 11988 KB Output is correct
19 Correct 5 ms 11988 KB Output is correct
20 Correct 5 ms 11928 KB Output is correct
21 Correct 5 ms 12004 KB Output is correct
22 Correct 5 ms 12048 KB Output is correct
23 Correct 6 ms 12056 KB Output is correct
24 Correct 6 ms 12052 KB Output is correct
25 Correct 6 ms 12056 KB Output is correct
26 Correct 6 ms 12116 KB Output is correct
27 Correct 7 ms 11988 KB Output is correct
28 Correct 6 ms 12116 KB Output is correct
29 Correct 6 ms 12048 KB Output is correct
30 Correct 6 ms 12052 KB Output is correct
31 Correct 8 ms 12052 KB Output is correct
32 Correct 7 ms 11988 KB Output is correct
33 Correct 263 ms 44112 KB Output is correct
34 Correct 219 ms 52880 KB Output is correct
35 Correct 185 ms 44140 KB Output is correct
36 Correct 200 ms 48028 KB Output is correct
37 Correct 37 ms 20052 KB Output is correct
38 Correct 34 ms 19988 KB Output is correct
39 Correct 147 ms 50308 KB Output is correct
40 Correct 146 ms 50340 KB Output is correct
41 Correct 41 ms 18252 KB Output is correct
42 Correct 74 ms 30992 KB Output is correct
43 Correct 24 ms 18004 KB Output is correct
44 Correct 126 ms 45388 KB Output is correct
45 Correct 27 ms 18016 KB Output is correct
46 Correct 32 ms 18140 KB Output is correct
47 Correct 120 ms 45700 KB Output is correct
48 Correct 129 ms 45756 KB Output is correct
49 Correct 111 ms 23056 KB Output is correct
50 Correct 105 ms 22988 KB Output is correct
51 Correct 212 ms 52172 KB Output is correct
52 Correct 208 ms 51700 KB Output is correct
53 Correct 201 ms 21288 KB Output is correct
54 Correct 158 ms 34956 KB Output is correct
55 Correct 87 ms 19184 KB Output is correct
56 Correct 221 ms 47224 KB Output is correct
57 Correct 109 ms 19616 KB Output is correct
58 Correct 140 ms 20172 KB Output is correct
59 Correct 153 ms 45812 KB Output is correct