답안 #734355

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734355 2023-05-02T10:09:44 Z Magikarp4000 말 (IOI15_horses) C++17
0 / 100
23 ms 13700 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int64_t(1e9+7)
#define ln '\n' 
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;

const int MAXN = 1e5+1, LOG = 31;
const ll MAXX = 1e9;
int n;
ll x[MAXN], y[MAXN];
set<int> a;
ll st[MAXN*4], st1[MAXN];

void update(int s, int tl, int tr, int idx, ll val) {
	if (tl == tr) st[s] = val;
	else {
		int tm = (tl+tr)/2;
		if (idx <= tm) update(s*2,tl,tm,idx,val);
		else update(s*2+1,tm+1,tr,idx,val);
		st[s] = max(st[s*2], st[s*2+1]);
	}
}

ll query(int s, int tl, int tr, int l, int r) {
	if (tl == tr) return st[s];
	else {
		int tm = (tl+tr)/2;
		ll cur = -INF;
		if (l <= tm) cur = max(cur, query(s*2,tl,tm,l,r));
		if (r > tm) cur = max(cur, query(s*2+1,tm+1,tr,l,r));
		return cur;
	}
}

void update1(int s, int tl, int tr, int idx, ll val) {
	if (tl == tr) st1[s] = val;
	else {
		int tm = (tl+tr)/2;
		if (idx <= tm) update1(s*2,tl,tm,idx,val);
		else update1(s*2+1,tm+1,tr,idx,val);
		st1[s] = (st1[s*2]*st1[s*2+1])%INF;
	}
}

ll query1(int s, int tl, int tr, int l, int r) {
	if (tl == tr) return st1[s];
	else {
		int tm = (tl+tr)/2;
		ll cur = 1ll;
		if (l <= tm) cur = (cur*query1(s*2,tl,tm,l,r))%INF;
		if (r > tm) cur = (cur*query1(s*2+1,tm+1,tr,l,r))%INF;
		return cur;
	}
}

int calc() {
	if (a.size() == 0) return query(1,0,n-1,0,n-1);
	vector<int> v;
	int cnt = 0;
	for (auto it = a.rbegin(); it != a.rend(); it++) {
		v.PB(*it);
		cnt++;
		if (cnt >= LOG) break;
	}
	reverse(ALL(v));
	int vn = v.size();
	ll res = 0, xval = 1, pos = 0, yval = 0, ygood = 0;
	FOR(i,0,vn) {
		int en = i == vn-1 ? n-1 : v[i+1]-1;
		xval *= x[v[i]];
		yval = query(1,0,n-1,v[i],en);
		if (xval > MAXX) {
			xval = x[v[i]];
			res = xval*yval;
			pos = v[i];
			ygood = yval;
		}
		else {
			ll cur = xval*yval;
			if (cur > res) {
				res = cur;
				pos = v[i];
				ygood = yval;
			}
		}
	}
	ll ans = ygood;
	if (pos > 0) ans = (ans*query1(1,0,n-1,0,pos))%INF;
	return ans;
}

int init(int N, int X[], int Y[]) {
	n = N;
	FOR(i,0,n) {
		x[i] = X[i];
		y[i] = Y[i];
	}
	FOR(i,0,n) {
		update(1,0,n-1,i,y[i]);
		update1(1,0,n-1,i,x[i]);
		if (x[i] > 1) a.insert(i);
	}
	return calc();
}

int updateX(int pos, int val) {	
	update1(1,0,n-1,pos,val);
	x[pos] = val;
	if (val == 1 && a.count(pos)) a.erase(pos);
	if (val > 1) a.insert(pos);
	return calc();
}

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

Compilation message

horses.cpp: In function 'int calc()':
horses.cpp:76:33: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   76 |  if (a.size() == 0) return query(1,0,n-1,0,n-1);
      |                            ~~~~~^~~~~~~~~~~~~~~
horses.cpp:85:17: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   85 |  int vn = v.size();
      |           ~~~~~~^~
horses.cpp:107:43: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  107 |  if (pos > 0) ans = (ans*query1(1,0,n-1,0,pos))%INF;
      |                                           ^~~
horses.cpp:108:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  108 |  return ans;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 13700 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -