답안 #988819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988819 2024-05-26T10:52:22 Z bigo 말 (IOI15_horses) C++14
0 / 100
581 ms 122056 KB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <utility>
using namespace std;
#define all(a) a.begin(), a.end()
#define rep(i,s,e) for(ll i=s;i<e;i++)
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const ll INF = 1e18;
typedef complex<double> cd;
const double pi = acos(-1);
const ll mod = 1e9 + 7;
const ll mod1 = 1e9 + 9;
const ll mod2 = 998244353;
const ll mac = 31;
const ll MAXN = 4e5 + 2;
typedef vector<int> vi;
typedef vector<vi> vvi;



ll cef(ll a, ll b) {
	ll val;
	if (ll(a) * ll(b) >= 1e9)
		val = 0;
	else
		val = a*b;
	return val;
}

struct seg {
	ll l, r, mid, val=1,vm=1;
	seg* lp, * rp;
	seg(ll l, ll r): l(l), r(r), mid((l + r) / 2) {
		if (l < r) {
			lp = new seg(l, mid);
			rp = new seg(mid+1,r);
		}
	}
	void pull() {
		val = cef(lp->val, rp->val);
		vm = (lp->vm * rp->vm) % mod;
	}
	void upd(ll i,ll x) {
		if (l == r) {
			val = x;
			vm = x % mod;
			return;
		}
		if (i <= mid) lp->upd(i, x);
		else rp->upd(i, x);
		pull();
	}
	ll que(ll a, ll b) {
		if (a <= l and r <= b) return val;
		if (a > r or l > b) return 1;
		return cef(lp->que(a, b),rp->que(a, b));
	}
	ll qm(ll a, ll b) {
		if (a <= l and r <= b) return val;
		if (a > r or l > b) return 1;
		return (lp->que(a, b) * rp->que(a, b)) % mod;
	}
};

seg *segx;

struct smax {
	int val = 0;
	int l, r, mid;
	smax* lp, * rp;
	smax(int l, int r) : l(l), r(r), mid((l + r) / 2) {
		if (l < r) {
			lp = new smax(l, mid);
			rp = new smax(mid+1, r);
		}
	}
	void pull() {
		val = max(lp->val, rp->val);
	}
	void upd(int i, int x) {
		if (l == r) {
			val = x;
			return;
		}
		if (i <= mid) lp->upd(i, x);
		else rp->upd(i, x);
		pull();
	}
	int que(int a, int b) {
		if (a > r || b < l) return 0;
		if (a <= l && r <= b) return val;
		return max(lp->que(a, b), rp->que(a, b));
	}
};

smax *segy;

int n;
vi x, y;
set<int> wx;
int init(int N, int X[], int Y[]) {
	n = N;
	x.resize(n);
	y.resize(n);
	segx = new seg(0, n - 1);
	segy = new smax(0, n - 1);
	wx.insert(-1);
	wx.insert(n);
	rep(i, 0, n) {
		x[i] = X[i], y[i] = Y[i];
		segx->upd(i, x[i]);
		segy->upd(i, y[i]);
		if (x[i] > 1) {
			wx.insert(i);
			if (wx.size() > 31)
				wx.erase(wx.begin());
		}
	}
	pair<ll, ll>ans = {0,(x[0]*y[0])%mod};
	int pr = -1;
	for (int i : wx) {
		if (i != -1 and i != n) {
			ll t = cef(segx->que(ans.first + 1, i), y[i]);
			if (t == 0 or t >= y[ans.first])
				ans = { i,(segx->qm(0,i) * y[i]) % mod };
		}
		if (pr != -1 and pr<=(i-1)) {
			ll y1 = segy->que(pr, i - 1);
			ll t = cef(y1, segx->que(ans.first + 1, i - 1));
			if (t == 0 or t >= y[ans.first])
				ans = { i,(segx->qm(0,i-1) * y1) % mod };
		}
		pr = i + 1;
	}
	return ans.second;
}

int updateX(int pos, int val) {
	if (x[pos] > 1)
		wx.erase(pos);
	x[pos] = val;
	segx->upd(pos, val);
	if (x[pos] > 1) {
		wx.insert(pos);
		if (wx.size() > 31)
			wx.erase(wx.begin());
	}
	if (wx.size() < 31)
		wx.insert(-1);
	pair<ll, ll>ans = { 0,(x[0] * y[0]) % mod };
	int pr = -1;
	for (int i : wx) {
		if (i != -1 and i != n) {
			ll t = cef(segx->que(ans.first + 1, i), y[i]);
			if (t == 0 or t >= y[ans.first])
				ans = { i,(segx->qm(0,i) * y[i]) % mod };
		}
		if (pr != -1 and pr <= (i - 1)) {
			ll y1 = segy->que(pr, i - 1);
			ll t = cef(y1, segx->que(ans.first + 1, i - 1));
			if (t == 0 or t >= y[ans.first])
				ans = { i,(segx->qm(0,i - 1) * y1) % mod };
		}
		pr = i + 1;
	}
	return ans.second;
}

int updateY(int pos, int val) {
	y[pos] = val;
	segy->upd(pos, val);
	pair<ll, ll>ans = { 0,(x[0] * y[0]) % mod };
	int pr = -1;
	for (int i : wx) {
		if (i != -1 and i != n) {
			ll t = cef(segx->que(ans.first + 1, i), y[i]);
			if (t == 0 or t >= y[ans.first])
				ans = { i,(segx->qm(0,i) * y[i]) % mod };
		}
		if (pr != -1 and pr <= (i - 1)) {
			ll y1 = segy->que(pr, i - 1);
			ll t = cef(y1, segx->que(ans.first + 1, i - 1));
			if (t == 0 or t >= y[ans.first])
				ans = { i,(segx->qm(0,i - 1) * y1) % mod };
		}
		pr = i + 1;
	}
	return ans.second;
}

/*
int main() {
	int n, q;
	cin >> n >> q;
	int x[3],y[3];
	rep(i, 0, n)
		cin >> x[i];
	rep(i, 0, n)
		cin >> y[i];
	cout << init(n, x, y);
	while (q--) {
		ll t, pos, val;
		cin >> t >> pos >> val;
		if (t == 1)
			cout << updateX(pos, val);
		else
			cout << updateY(pos, val);
	}
}*/

Compilation message

horses.cpp: In function 'll cef(ll, ll)':
horses.cpp:25:12: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
   25 |  if (ll(a) * ll(b) >= 1e9)
      |      ~~~~~~^~~~~~~
horses.cpp: In constructor 'seg::seg(ll, ll)':
horses.cpp:35:15: warning: declaration of 'r' shadows a member of 'seg' [-Wshadow]
   35 |  seg(ll l, ll r): l(l), r(r), mid((l + r) / 2) {
      |            ~~~^
horses.cpp:33:8: note: shadowed declaration is here
   33 |  ll l, r, mid, val=1,vm=1;
      |        ^
horses.cpp:35:9: warning: declaration of 'l' shadows a member of 'seg' [-Wshadow]
   35 |  seg(ll l, ll r): l(l), r(r), mid((l + r) / 2) {
      |      ~~~^
horses.cpp:33:5: note: shadowed declaration is here
   33 |  ll l, r, mid, val=1,vm=1;
      |     ^
horses.cpp: In constructor 'seg::seg(ll, ll)':
horses.cpp:35:15: warning: declaration of 'r' shadows a member of 'seg' [-Wshadow]
   35 |  seg(ll l, ll r): l(l), r(r), mid((l + r) / 2) {
      |            ~~~^
horses.cpp:33:8: note: shadowed declaration is here
   33 |  ll l, r, mid, val=1,vm=1;
      |        ^
horses.cpp:35:9: warning: declaration of 'l' shadows a member of 'seg' [-Wshadow]
   35 |  seg(ll l, ll r): l(l), r(r), mid((l + r) / 2) {
      |      ~~~^
horses.cpp:33:5: note: shadowed declaration is here
   33 |  ll l, r, mid, val=1,vm=1;
      |     ^
horses.cpp: In constructor 'seg::seg(ll, ll)':
horses.cpp:35:15: warning: declaration of 'r' shadows a member of 'seg' [-Wshadow]
   35 |  seg(ll l, ll r): l(l), r(r), mid((l + r) / 2) {
      |            ~~~^
horses.cpp:33:8: note: shadowed declaration is here
   33 |  ll l, r, mid, val=1,vm=1;
      |        ^
horses.cpp:35:9: warning: declaration of 'l' shadows a member of 'seg' [-Wshadow]
   35 |  seg(ll l, ll r): l(l), r(r), mid((l + r) / 2) {
      |      ~~~^
horses.cpp:33:5: note: shadowed declaration is here
   33 |  ll l, r, mid, val=1,vm=1;
      |     ^
horses.cpp: In constructor 'smax::smax(int, int)':
horses.cpp:73:18: warning: declaration of 'r' shadows a member of 'smax' [-Wshadow]
   73 |  smax(int l, int r) : l(l), r(r), mid((l + r) / 2) {
      |              ~~~~^
horses.cpp:71:9: note: shadowed declaration is here
   71 |  int l, r, mid;
      |         ^
horses.cpp:73:11: warning: declaration of 'l' shadows a member of 'smax' [-Wshadow]
   73 |  smax(int l, int r) : l(l), r(r), mid((l + r) / 2) {
      |       ~~~~^
horses.cpp:71:6: note: shadowed declaration is here
   71 |  int l, r, mid;
      |      ^
horses.cpp: In constructor 'smax::smax(int, int)':
horses.cpp:73:18: warning: declaration of 'r' shadows a member of 'smax' [-Wshadow]
   73 |  smax(int l, int r) : l(l), r(r), mid((l + r) / 2) {
      |              ~~~~^
horses.cpp:71:9: note: shadowed declaration is here
   71 |  int l, r, mid;
      |         ^
horses.cpp:73:11: warning: declaration of 'l' shadows a member of 'smax' [-Wshadow]
   73 |  smax(int l, int r) : l(l), r(r), mid((l + r) / 2) {
      |       ~~~~^
horses.cpp:71:6: note: shadowed declaration is here
   71 |  int l, r, mid;
      |      ^
horses.cpp: In constructor 'smax::smax(int, int)':
horses.cpp:73:18: warning: declaration of 'r' shadows a member of 'smax' [-Wshadow]
   73 |  smax(int l, int r) : l(l), r(r), mid((l + r) / 2) {
      |              ~~~~^
horses.cpp:71:9: note: shadowed declaration is here
   71 |  int l, r, mid;
      |         ^
horses.cpp:73:11: warning: declaration of 'l' shadows a member of 'smax' [-Wshadow]
   73 |  smax(int l, int r) : l(l), r(r), mid((l + r) / 2) {
      |       ~~~~^
horses.cpp:71:6: note: shadowed declaration is here
   71 |  int l, r, mid;
      |      ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:114:13: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  114 |   segy->upd(i, y[i]);
      |             ^
horses.cpp:116:14: warning: conversion from 'll' {aka 'long long int'} to 'std::set<int>::value_type' {aka 'int'} may change value [-Wconversion]
  116 |    wx.insert(i);
      |              ^
horses.cpp:137:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  137 |  return ans.second;
      |         ~~~~^~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:168:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  168 |  return ans.second;
      |         ~~~~^~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:190:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  190 |  return ans.second;
      |         ~~~~^~~~~~
# 결과 실행 시간 메모리 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 436 KB Output is correct
7 Correct 0 ms 364 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 344 KB Output is correct
15 Incorrect 0 ms 344 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 0 ms 352 KB Output is correct
7 Correct 0 ms 352 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 436 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 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 581 ms 122056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 436 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 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 604 KB Output is correct
13 Correct 0 ms 436 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 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 432 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 Incorrect 1 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -