Submission #988756

# Submission time Handle Problem Language Result Execution time Memory
988756 2024-05-25T23:40:39 Z bigo Horses (IOI15_horses) C++14
17 / 100
1478 ms 524288 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 int MAXN = 4e5 + 2;
typedef vector<int> vi;
typedef vector<vi> vvi;
vi x, y;

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

struct seg {
	int l, r, mid, val=1;
	seg* lp, * rp;
	seg(int l, int 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);
	}
	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 <= l and r <= b) return val;
		if (a > r or l > b) return 1;
		return cef(lp->que(a, b),rp->que(a, b));
	}
};

int n;
int init(int N, int X[], int Y[]) {
	n = N;
	x.resize(n);
	y.resize(n);
	rep(i, 0, n) x[i] = X[i], y[i] = Y[i];
	pair<int, int>ans = {0,(x[0]*y[0])%mod};
	int c = x[0];
	seg segx(0, n - 1);
	rep(i, 1, n) {
		segx.upd(i, x[i]);
		c *= x[i];
		c %= mod;
		int t = cef(segx.que(ans.first + 1, i), y[i]);
		if (t == 0 or t >= y[ans.first])
			ans = { i,(c * y[i]) % mod };
	}
	return ans.second;
}

int updateX(int pos, int val) {
	x[pos] = val;
	pair<int, int>ans = { 0,(x[0] * y[0]) % mod };
	int c = x[0];
	seg segx(0, n - 1);
	rep(i, 1, n) {
		segx.upd(i, x[i]);
		c *= x[i];
		c %= mod;
		int t = cef(segx.que(ans.first + 1, i), y[i]);
		if (t == 0 or t >= y[ans.first])
			ans = { i,(c * y[i]) % mod };
	}
	return ans.second;
}

int updateY(int pos, int val) {
	y[pos] = val;
	pair<int, int>ans = { 0,(x[0] * y[0]) % mod };
	int c = x[0];
	seg segx(0, n - 1);
	rep(i, 1, n) {
		segx.upd(i, x[i]);
		c *= x[i];
		c %= mod;
		int t = cef(segx.que(ans.first + 1, i), y[i]);
		if (t == 0 or t >= y[ans.first])
			ans = { i,(c * y[i]) % mod };
	}
	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--) {
		int t, pos, val;
		cin >> t >> pos >> val;
		if (t == 1)
			cout << updateX(pos, val);
		else
			cout << updateY(pos, val);
	}
}*/

Compilation message

horses.cpp: In constructor 'seg::seg(int, int)':
horses.cpp:34:17: warning: declaration of 'r' shadows a member of 'seg' [-Wshadow]
   34 |  seg(int l, int r): l(l), r(r), mid((l + r) / 2) {
      |             ~~~~^
horses.cpp:32:9: note: shadowed declaration is here
   32 |  int l, r, mid, val=1;
      |         ^
horses.cpp:34:10: warning: declaration of 'l' shadows a member of 'seg' [-Wshadow]
   34 |  seg(int l, int r): l(l), r(r), mid((l + r) / 2) {
      |      ~~~~^
horses.cpp:32:6: note: shadowed declaration is here
   32 |  int l, r, mid, val=1;
      |      ^
horses.cpp: In constructor 'seg::seg(int, int)':
horses.cpp:34:17: warning: declaration of 'r' shadows a member of 'seg' [-Wshadow]
   34 |  seg(int l, int r): l(l), r(r), mid((l + r) / 2) {
      |             ~~~~^
horses.cpp:32:9: note: shadowed declaration is here
   32 |  int l, r, mid, val=1;
      |         ^
horses.cpp:34:10: warning: declaration of 'l' shadows a member of 'seg' [-Wshadow]
   34 |  seg(int l, int r): l(l), r(r), mid((l + r) / 2) {
      |      ~~~~^
horses.cpp:32:6: note: shadowed declaration is here
   32 |  int l, r, mid, val=1;
      |      ^
horses.cpp: In constructor 'seg::seg(int, int)':
horses.cpp:34:17: warning: declaration of 'r' shadows a member of 'seg' [-Wshadow]
   34 |  seg(int l, int r): l(l), r(r), mid((l + r) / 2) {
      |             ~~~~^
horses.cpp:32:9: note: shadowed declaration is here
   32 |  int l, r, mid, val=1;
      |         ^
horses.cpp:34:10: warning: declaration of 'l' shadows a member of 'seg' [-Wshadow]
   34 |  seg(int l, int r): l(l), r(r), mid((l + r) / 2) {
      |      ~~~~^
horses.cpp:32:6: note: shadowed declaration is here
   32 |  int l, r, mid, val=1;
      |      ^
horses.cpp: In member function 'void seg::upd(int, int)':
horses.cpp:43:21: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   43 |  void upd(int i,int x) {
      |                 ~~~~^
horses.cpp:20:4: note: shadowed declaration is here
   20 | vi x, y;
      |    ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:69:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   69 |   segx.upd(i, x[i]);
      |            ^
horses.cpp:72:39: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   72 |   int t = cef(segx.que(ans.first + 1, i), y[i]);
      |                                       ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:85:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   85 |   segx.upd(i, x[i]);
      |            ^
horses.cpp:88:39: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   88 |   int t = cef(segx.que(ans.first + 1, i), y[i]);
      |                                       ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:101:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  101 |   segx.upd(i, x[i]);
      |            ^
horses.cpp:104:39: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  104 |   int t = cef(segx.que(ans.first + 1, i), y[i]);
      |                                       ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:53:18: warning: 'segx.seg::rp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |   if (a <= l and r <= b) return val;
      |                  ^
horses.cpp:83:6: note: 'segx.seg::rp' was declared here
   83 |  seg segx(0, n - 1);
      |      ^~~~
horses.cpp:53:33: warning: 'segx.seg::lp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |   if (a <= l and r <= b) return val;
      |                                 ^~~
horses.cpp:83:6: note: 'segx.seg::lp' was declared here
   83 |  seg segx(0, n - 1);
      |      ^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:53:18: warning: 'segx.seg::rp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |   if (a <= l and r <= b) return val;
      |                  ^
horses.cpp:99:6: note: 'segx.seg::rp' was declared here
   99 |  seg segx(0, n - 1);
      |      ^~~~
horses.cpp:53:33: warning: 'segx.seg::lp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |   if (a <= l and r <= b) return val;
      |                                 ^~~
horses.cpp:99:6: note: 'segx.seg::lp' was declared here
   99 |  seg segx(0, n - 1);
      |      ^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:53:18: warning: 'segx.seg::rp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |   if (a <= l and r <= b) return val;
      |                  ^
horses.cpp:67:6: note: 'segx.seg::rp' was declared here
   67 |  seg segx(0, n - 1);
      |      ^~~~
horses.cpp:53:33: warning: 'segx.seg::lp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |   if (a <= l and r <= b) return val;
      |                                 ^~~
horses.cpp:67:6: note: 'segx.seg::lp' was declared here
   67 |  seg segx(0, n - 1);
      |      ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 352 KB Output is correct
18 Correct 1 ms 352 KB Output is correct
19 Correct 1 ms 352 KB Output is correct
20 Correct 1 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 356 KB Output is correct
2 Correct 1 ms 432 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 392 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Incorrect 1 ms 344 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1478 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 352 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 1 ms 356 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Incorrect 1 ms 344 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Incorrect 1 ms 348 KB Output isn't correct
22 Halted 0 ms 0 KB -