Submission #1031886

# Submission time Handle Problem Language Result Execution time Memory
1031886 2024-07-23T08:26:44 Z Halym2007 Street Lamps (APIO19_street_lamps) C++17
0 / 100
5000 ms 40532 KB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define sz size()
#define ll long long
#define pii pair <int, int> 
const int N = 1e5 + 5;

int l[N], r[N], n, m, jog, w[N];
bool vis[N];
vector <pii> v[N];

int st[3 * N];

void dfs (int x, int y) {
	jog++;
	vis[x] = 1;
	for (pii i : v[x]) {
		if (vis[i.ff] or y > i.ss) continue;
		dfs (i.ff, y);
	}
}





void update (int idx, int x, int y, int val) {
	if (x == y) {
		st[idx] = w[x];
		return;
	}
	int mid = (x + y) / 2;
	if (val <= mid) update (idx * 2, x, mid, val);
	else update (idx * 2 + 1, mid + 1, y, val);
	st[idx] = min (st[idx * 2], st[idx * 2 + 1]);
}

int jogap (int idx, int x, int y, int l1, int r1) {
//	cout << "--> " << x << " " << y << " " << l1  << " " << r1 << " " << idx << " " << st[idx] << "\n";
	if (l1 <= x and y <= r1) return st[idx];
	if (l1 > y or x > r1) {
//		cout << "gaytdy\n";
		return 1e9;
	}
	int mid = (x + y) / 2;
	return min (jogap (idx * 2, x, mid, l1, r1), jogap (idx * 2 + 1, mid + 1, y, l1, r1));	
}


int main () {
//	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//	freopen ("input.txt", "r", stdin);
	cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		cin >> l[i] >> r[i] >> w[i];
	}
	
	int q;
	cin >> q;
	// q== 3 if-i ayyr
	if (n <= 1000 and m <= 1000 and q <= 10000) {
		while ( q-- ) {
			int typ, l1, r1;
			cin >> typ >> l1 >> r1;
			if (typ == 2) {
				for (int i = 1; i <= m; ++i) {
					v[l[i]].pb ({r[i], w[i]});
					v[r[i]].pb ({l[i], w[i]});
				}
				jog = 0;
				dfs (l1, r1);
				for (int i = 1; i <= n; ++i) {
					vis[i] = 0;
					v[i].clear();
				}
				cout << jog << "\n";
			}
			else {
				w[l1] = r1;
			}
		}
	}
	else {
		for (int i = 1; i < n; ++i) {
			update (1, 1, n - 1, i);
		}
//		cout << "men";
//		return 0;
		while ( q-- ) {
			int typ, l1, r1;
			cin >> typ >> l1 >> r1;
//			cout << typ << " " << l1 << " " << r1 << endl;
			if (typ == 1) {
				w[l1] = r1;
				update (1, 1, n - 1, l1);
			}
			else {
				int x = 1, y = l1 - 1, jog1 = 0, jog2 = 0;
				while (x <= y) {
					int md = (x + y) / 2;
					int kk = jogap (1, 1, n - 1, l1 - md, l1 - 1);
//					cout << x << " " << y << " " << kk << " " << l1 - md << " " << l1 - 1 << " " << r1 << "\n";
					if (kk < r1) {
						y = md - 1;
					}
					else {
						jog1 = md;
						x = md + 1;
					}
				}
//				return cout << jog1, 0;
				x = 1, y = n - l1;
				
				while (x <= y) {
					int md = (x + y) / 2;
					if (jogap (1, 1, n - 1, l1, l1 + md - 1) < r1) {
						y = md - 1;
					}
					else {
						jog2 = md;
						x = md + 1;
					}
				}
				
				cout << jog1 + jog2 + 1 << "\n";
			}
		}
	}
}
# Verdict Execution time Memory Grader output
1 Execution timed out 5063 ms 2652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5069 ms 40532 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5038 ms 23648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5066 ms 22868 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5063 ms 2652 KB Time limit exceeded
2 Halted 0 ms 0 KB -