Submission #997158

# Submission time Handle Problem Language Result Execution time Memory
997158 2024-06-11T18:25:50 Z SN0WM4N Bridges (APIO19_bridges) C++14
0 / 100
1 ms 1368 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sort undefined_function // To use stable_sort instead sort 
#define bpc __builtin_popcount
#define ull unsigned long long
#define ld double
#define ll long long
#define mp make_pair
#define F first
#define S second

#pragma GCC optimize("O3")

#ifdef LOCAL 
	#include "debug.h"
#else 
	#define dbg(...) 0
#endif

using namespace __gnu_pbds;
using namespace std;

typedef tree<long long, null_type, less_equal<long long>,
    rb_tree_tag, tree_order_statistics_node_update> Tree;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll INF = 9223372036854775807LL;
const ll inf = 2147483647;
const ll MOD = 1e9 + 7; //[998244353, 1e9 + 7, 1e9 + 13]
const ld PI = acos(-1);
const ll NROOT = 500;

ll binpow(ll a, ll b, ll _MOD = -1) {
	if (_MOD == -1)
		_MOD = MOD;
	ll res = 1;
	for (; b; b /= 2, a *= a, a %= _MOD)
		if (b & 1) res *= a, res %= _MOD;
	return res;
}

void set_IO(string s) {
#ifndef LOCAL
	string in  = s +  ".in";
	string out = s + ".out";
	freopen(in.c_str(),  "r",  stdin);
	freopen(out.c_str(), "w", stdout);
#endif
}

bool dataOverflow(ll a, ll b) {return (log10(a) + log10(b) >= 18);}
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
ll ceil(ll a, ll b) {return (a + b - 1) / b;}
ll invmod(ll a) {return binpow(a, MOD - 2);}

class ST {
	private:
		int n;
		vector<int> st;

		void update(int nod, int l, int r, int pos, int val) { 
			if (l == r) {
				st[nod] = val;
				return;
			}

			int mid = (l + r) / 2;

			if (pos <= mid)
				update(nod * 2, l, mid, pos, val);
			else 
				update(nod * 2 + 1, mid + 1, r, pos, val);
			st[nod] = min(st[nod* 2], st[nod * 2 + 1]);
		}

		int query(int nod, int l, int r, int L, int R) {
			if (R < l || r < L)
				return inf;
			if (L <= l && r <= R)
				return st[nod];

			int mid = (l + r) / 2;
			return min(query(nod * 2, l, mid, L, R), query(nod * 2 + 1, mid + 1, r, L, R));
		}
	public:
		ST(int _n) {
			n = _n;
			st.resize(n + 1, inf);
		}

		void update(int pos, int val) {
			update(1, 1, n, pos, val);
		}
		int query(int L, int R) {
			return query(1, 1, n, L, R);
		}
};

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int n, m;
	cin >> n >> m;

	ST fw(n + 2), bw(n + 2);

	for (int i = 1; i <= m; i ++) {
		int a, b, c;
		cin >> a >> b >> c;

		fw.update(a, c);
		bw.update(b, c);
	}

	int q;
	cin >> q;

	while (q --) {
		int tq, a, b;
		cin >> tq >> a >> b;

		if (tq == 1) {
			fw.update(a, b);
			bw.update(a + 1, b);			
		} else {
			int L = a, R = a;

			int l = 1, r = a;
			while (l <= r) {
				int mid = (l + r) / 2;
				if (bw.query(mid, a) < b) {
					l = mid + 1;
				} else {
					r = mid - 1;
					L = mid - 1;
				}
			}

			l = a, r = n;
			while (l <= r) {
				int mid = (l + r) / 2;

				if (fw.query(a, mid) < b) {
					r = mid - 1;
				} else {
					l = mid + 1;
					R = mid;
				}
			}

			cout << R - L + 1 << "\n";
		}
	}

	return 0;
}

Compilation message

bridges.cpp: In function 'void set_IO(std::string)':
bridges.cpp:47:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  freopen(in.c_str(),  "r",  stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:48:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  freopen(out.c_str(), "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1116 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -