답안 #590781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590781 2022-07-06T11:05:52 Z FatihSolak 말 (IOI15_horses) C++17
57 / 100
1500 ms 66016 KB
#include "horses.h"
#include <bits/stdc++.h>
#define N 500005
using namespace std;
const int mod = 1e9 + 7;
struct node{
	pair<int,int> maxi;
	int prod = 1;
	node(pair<int,int> a,int b){
		maxi = a;
		prod = b;
	}
};
node merge(node a,node b){
	a.prod = (long long)a.prod * b.prod %mod;
	a.maxi = max(a.maxi,b.maxi);
	return a;
}
struct SegTree{
	vector<node> t;
	int n;
	void init(int size){
		n = size;
		t.assign(4*n,node(make_pair(0,0),1));
	}
	void upd1(int v,int tl,int tr,int pos,int val){
		if(tl == tr){
			t[v].prod = val;
			return;
		}
		int tm = (tl + tr)/2;
		if(pos <= tm){
			upd1(v*2,tl,tm,pos,val);
		}
		else upd1(v*2+1,tm+1,tr,pos,val);
		t[v] = merge(t[v*2],t[v*2+1]);
	}
	void upd2(int v,int tl,int tr,int pos,int val){
		if(tl == tr){
			t[v].maxi = {val,pos};
			return;
		}
		int tm = (tl + tr)/2;
		if(pos <= tm){
			upd2(v*2,tl,tm,pos,val);
		}
		else upd2(v*2+1,tm+1,tr,pos,val);
		t[v] = merge(t[v*2],t[v*2+1]);
	}
	node get(int v,int tl,int tr,int l,int r){
		if(tr < l || r < tl){
			return node(make_pair(0,0),1);
		}
		if(l <= tl && tr <= r){
			return t[v];
		}
		int tm = (tl + tr)/2;
		return merge(get(v*2,tl,tm,l,r),get(v*2+1,tm+1,tr,l,r));
	}
	void upd1(int pos,int val){
		upd1(1,0,n-1,pos,val);
	}
	void upd2(int pos,int val){
		upd2(1,0,n-1,pos,val);
	}
	node get(int l,int r){
		return get(1,0,n-1,l,r);
	}
}tree;
const int BOUND = 1e9;
set<int> s;
int x[N],y[N];
int n;
int get_ans(){
	int l = 0;
	long long prod = 1;
	if(s.size()){
		auto it = prev(s.end());
		while(prod < BOUND){
			prod *= x[*it];
			if(prod >= BOUND){
				l = *it;
			}
			if(it == s.begin())break;
			it = prev(it);
		}
	}
	int tmp = l;
	int opt = l;
	long long val = 0;
	prod = 1;
	while(1){
		if(l != tmp){
			prod *= x[l];
		}
		if(prod * tree.get(l,n).maxi.first > val){
			val = prod * tree.get(l,n).maxi.first;
			opt = tree.get(l,n).maxi.second;
		}
		if(s.upper_bound(l) == s.end())break;
		l = *s.upper_bound(l);
	}
	return (long long)y[opt] * tree.get(0,opt).prod % mod;
}
int init(int n_, int X[], int Y[]) {
	n = n_;
	tree.init(n);
	for(int i = 0;i<n;i++){
		x[i] = X[i];
		y[i] = Y[i];
		tree.upd1(i,x[i]);
		tree.upd2(i,y[i]);
		if(x[i] > 1){
			s.insert(i);
		}
	}
	return get_ans();
}

int updateX(int pos, int val) {	
	if(x[pos] > 1){
		s.erase(pos);
	}
	x[pos] = val;
	tree.upd1(pos,x[pos]);
	if(x[pos] > 1){
		s.insert(pos);
	}
	return get_ans();
}

int updateY(int pos, int val) {
	y[pos] = val;
	tree.upd2(pos,y[pos]);
	return get_ans();
}

Compilation message

horses.cpp: In function 'node merge(node, node)':
horses.cpp:15:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   15 |  a.prod = (long long)a.prod * b.prod %mod;
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int get_ans()':
horses.cpp:103:50: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  103 |  return (long long)y[opt] * tree.get(0,opt).prod % mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 224 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 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 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 312 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 312 KB Output is correct
14 Correct 0 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 312 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 312 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 412 KB Output is correct
25 Correct 2 ms 448 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 9 ms 340 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 2 ms 320 KB Output is correct
30 Correct 2 ms 448 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 6 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1585 ms 59520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 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 0 ms 308 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 0 ms 308 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 308 KB Output is correct
21 Correct 1 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 2 ms 340 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 11 ms 468 KB Output is correct
28 Correct 5 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 6 ms 400 KB Output is correct
33 Correct 286 ms 35668 KB Output is correct
34 Correct 285 ms 35716 KB Output is correct
35 Correct 431 ms 65976 KB Output is correct
36 Correct 406 ms 66016 KB Output is correct
37 Correct 445 ms 33860 KB Output is correct
38 Correct 406 ms 46676 KB Output is correct
39 Correct 288 ms 33576 KB Output is correct
40 Correct 395 ms 61172 KB Output is correct
41 Correct 311 ms 33820 KB Output is correct
42 Correct 354 ms 33788 KB Output is correct
43 Correct 378 ms 61356 KB Output is correct
44 Correct 367 ms 61512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 312 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 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 312 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 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 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 3 ms 460 KB Output is correct
26 Correct 2 ms 452 KB Output is correct
27 Correct 11 ms 320 KB Output is correct
28 Correct 5 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 3 ms 452 KB Output is correct
31 Correct 4 ms 328 KB Output is correct
32 Correct 5 ms 340 KB Output is correct
33 Execution timed out 1578 ms 59592 KB Time limit exceeded
34 Halted 0 ms 0 KB -