Submission #1003970

# Submission time Handle Problem Language Result Execution time Memory
1003970 2024-06-20T21:01:59 Z vjudge1 Paint (COI20_paint) C++17
0 / 100
98 ms 4760 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
const int maxn = -1;
const int inf = 1e18+10;

vector<vector<int>> a, dscol;
vector<vector<pair<int,int>>> ds;
vector<vector<vector<pair<int,int>>>> dsedg;
vector<pair<int,int>> adj = {{0,1},{0,-1},{1,0},{-1,0}};

pair<int,int> find(pair<int,int> u) {
	if(u == ds[u.fr][u.sc]) return u;
	return ds[u.fr][u.sc] = find(ds[u.fr][u.sc]);
}

void join(pair<int,int> u, pair<int,int> v) {
	u = find(u);
	v = find(v);
	if(u == v) return;
	if(dsedg[u.fr][u.sc].size() < dsedg[v.fr][v.sc].size()) swap(u,v);
	ds[v.fr][v.sc] = u;
	for(auto x : dsedg[v.fr][v.sc]) {
		dsedg[u.fr][u.sc].pb(x);
	}
}

void upd(pair<int,int> u) {
	u = find(u);
	dscol[u.fr][u.sc]^= 1;
	vector<pair<int,int>> edgs = dsedg[u.fr][u.sc];
	dsedg[u.fr][u.sc].clear();
	for(auto v : edgs) {
		join(u,v);
	}
}

int32_t main() {
	// #ifndef ONLINE_JUDGE
	// freopen("in.in","r",stdin);
	// freopen("out.out","w",stdout);
	// #endif

	int n,m;
	cin >> n >> m;
	vector<int> a(m+1);
	set<pair<pair<int,int>,int>> lrs;

	for(int i = 1; i <= m; i++) {
		cin >> a[i];
		if(lrs.size() && prev(lrs.end())->sc == a[i]) {
			int l = prev(lrs.end())->fr.fr;
			lrs.erase(prev(lrs.end()));
			lrs.insert(mp(mp(l,i),a[i]));
		}
		else {
			lrs.insert(mp(mp(i,i),a[i]));
		}
	}
	int q; cin >> q;
	while(q--) {
		int i,j,c;
		cin >> i >> j >> c;
		auto it = prev(lrs.upper_bound(mp(mp(j,inf),inf)));
		int l = it->fr.fr;
		int r = it->fr.sc;
		vector<pair<pair<int,int>,int>> rem;
		rem.pb(mp(mp(l,r),it->sc));
		if(it != lrs.begin() && prev(it)->sc == c) {
			l = prev(it)->fr.fr;
			rem.pb(mp(mp(prev(it)->fr.fr,prev(it)->fr.sc),prev(it)->sc));
		}

		if(next(it) != lrs.end() && next(it)->sc == c) {
			r = next(it)->fr.sc;
			rem.pb(mp(mp(next(it)->fr.fr,next(it)->fr.sc),prev(it)->sc));
		}

		for(auto x : rem) lrs.erase(x);
		lrs.insert(mp(mp(l,r),c));
	}

	for(auto x : lrs) {
		int l = x.fr.fr;
		int r = x.fr.sc;
		int c = x.sc;

		for(int i = l; i <= r; i++) {
			cout << c << " ";
		}
	}



}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 4760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -