답안 #988755

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988755 2024-05-25T23:40:08 Z bigo 말 (IOI15_horses) C++14
컴파일 오류
0 ms 0 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 main()':
horses.cpp:113:6: warning: declaration of 'n' shadows a global declaration [-Wshadow]
  113 |  int n, q;
      |      ^
horses.cpp:59:5: note: shadowed declaration is here
   59 | int n;
      |     ^
horses.cpp:115:6: warning: declaration of 'x' shadows a global declaration [-Wshadow]
  115 |  int x[3],y[3];
      |      ^
horses.cpp:20:4: note: shadowed declaration is here
   20 | vi x, y;
      |    ^
horses.cpp:115:11: warning: declaration of 'y' shadows a global declaration [-Wshadow]
  115 |  int x[3],y[3];
      |           ^
horses.cpp:20:7: note: shadowed declaration is here
   20 | vi x, y;
      |       ^
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);
      |      ^~~~
/usr/bin/ld: /tmp/ccKnvhgi.o: in function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'; /tmp/ccd31ewi.o:horses.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status