Language: C++

#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;

#define EPS 1e-12
//#define B 1000000

bool isPrime(ll n) {
	if (n == 1) return false;
	if (n == 2) return true;

	for (ll i = 2; i*i <= n; ++i) {
		if (n % i == 0) return false;
	}
	return true;
}

ll MOD = 4294967311LL, D;
ll mod(ll x) {
	return (x % MOD + MOD) % MOD;
}

ll mul(ll x, ll n) {
	ll ret = 0;

	if (x+n <= (1LL << 31)) {
		return x * n % MOD;
	}

	for (int i = 0; (1LL << i) <= n; ++i) {
		if (n & (1LL << i)) {
			ret = mod(ret + x);
		}
		x = mod(x + x);
	}
	return ret;
}
ll power(ll x, ll n) {
	ll ret = 1;
/*
	for (int i = 0; i < n; ++i) {
		ret = (ret * x) % MOD;
	}
	return ret;
*/
	for (int i = 0; (1LL << i) <= n; ++i) {
		if (n & (1LL << i)) {
			ret = mod( mul(ret, x) );
		}
		x = mod( mul(x, x) );
	}
	return ret;
}

ll abs(ll n) {
//	return n >= 0 ? n : MOD-n;
	return n > 0 ? n : -n;
}
ll div(ll x, ll n) {
	return mul(x, power(n, MOD-2));
}
ll cal(vector<ll> op, vector<ll> Y) {
	ll Z = 1;
	ll X = 0;
	int N = op.size();
	bool zf = false;
	for (int i = N-1; i >= 0; --i) {
		bool f = zf ^ (Y[i] < 0);
		ll y = abs(Y[i]);
		switch (op[i]) {
			case 2: f = !f;
			case 1:
				X = mod(X + (f ? -1 : 1) * mul(Z, y));
				break;

			case 3: Z = mod( mul(Z, y) ); zf = f; break;
			case 4: Z = mod( div(Z, y) ); zf = f; break;
		}
//		cout << Z << endl;
	}
	return X;
}

int main() {
//	while ( !isPrime(MOD) ) ++MOD;
//	cout << MOD << endl;
//	return 0;
	ll X = 0;

	int N; cin >> N;
	vector<ll> op(N), Y(N);
	for (int i = 0; i < N; ++i) {
		cin >> op[i] >> Y[i];
	}

	ll ans = cal(op, Y);

	if (ans >= (1LL << 31)) cout << ans-MOD << endl;
	else cout << ans << endl;
}

Compiler output:
a.cc: In function 'll cal(std::vector<long long int>, std::vector<long long int>)':
a.cc:73:27: error: call of overloaded 'abs(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)' is ambiguous
   73 |                 ll y = abs(Y[i]);
      |                        ~~~^~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/ext/string_conversions.h:43,
                 from /usr/include/c++/14/bits/basic_string.h:4154,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
a.cc:59:4: note: candidate: 'll abs(ll)'
   59 | ll abs(ll n) {
      |    ^~~
In file included from /usr/include/c++/14/cstdlib:81:
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc:81:45: error: call of overloaded 'div(ll&, ll&)' is ambiguous
   81 |                         case 4: Z = mod( div(Z, y) ); zf = f; break;
      |                                          ~~~^~~~~~
/usr/include/stdlib.h:992:14: note: candidate: 'div_t div(int, int)'
  992 | extern div_t div (int __numer, int __denom)
      |              ^~~
a.cc:63:4: note: candidate: 'll div(ll, ll)'
   63 | ll div(ll x, ll n) {
      |    ^~~
/usr/include/c++/14/cstdlib:219:3: note: candidate: 'lldiv_t __gnu_cxx::div(long long int, long long int)'
  219 |   div(long long __n, long long __d)
      |   ^~~
/usr/include/c++/14/cstdlib:181:3: note: candidate: 'ldiv_t std::div(long int, long int)'
  181 |   div(long __i, long __j) _GLIBCXX_NOTHROW { return ldiv(__i, __j); }
      |   ^~~