Submission #716502

# Submission time Handle Problem Language Result Execution time Memory
716502 2023-03-30T08:03:22 Z josanneo22 Joker (BOI20_joker) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 400005
 
const int modulo = 1e9 + 7;
int ans[N], u[N], v[N], l[N], r[N], n, sz[N];
vector<int> root;
vector<pii> block[N];
int res[N], s;
 
int find(vector<int> &b, int node, int flag)
{
	if (node < 0) return -(find(b, -node, flag));
	if (node == b[node]) return node;
	if (flag) return b[node] = find(b, b[node], flag);
	return find(b, b[node], flag);
}
 
 
int64_t main()
{
	fastio();
	int m, q;
	cin>>n>>m>>q;
	root.resize(n + 5, 0);
 
	while(s * s < m) s++;
	for (int i = 1; i <= m; i++)
	{
		cin>>u[i]>>v[i];
	}
 
	int maks = 0;
	for (int i = 1; i <= q; i++)
	{
		cin>>l[i]>>r[i];
		block[l[i] / s].pb({r[i], i});
	}
 
	int it = 0;
	for (int i = 0; i <= m / s + 1; i++)
	{
		for (int j = 1; j <= n; j++) root[j] = j, sz[j] = 1;
		sort(block[i].rbegin(), block[i].rend());
		stack<pii> sl, slz;
		int last = m;
		for (auto j : block[i])
		{
			while(!sl.empty())
			{
				root[sl.top().st] = sl.top().nd;
				sl.pop();
				sz[slz.top().st] = slz.top().nd;
				slz.pop();
			}
			//cout<<j.nd<<sp<<l[j.nd]<<sp<<r[j.nd]<<endl;
			while(last > r[j.nd])
			{
				int a = find(root, u[last], 1), b = find(root, v[last], 1);
				if (a == b) 
				{
					res[j.nd] = 1;
					break;
				}
				else
				{
					if (sz[abs(a)] > sz[abs(b)]) swap(a, b);
					if (a < 0) a *= -1, b *= -1;
					sz[abs(b)] += sz[a];
					root[a] = -b;
				}
				last--;
			}
			for (int k = 1; k < l[j.nd]; k++)
			{
				int a = find(root, u[k], 0), b = find(root, v[k], 0);
				if (a == b) 
				{
					res[j.nd] = 1;
					break;
				}
				else
				{
					if (sz[abs(a)] > sz[abs(b)]) swap(a, b);
					if (a < 0) a *= -1, b *= -1;
					slz.push({abs(b), sz[abs(b)]});
					sz[abs(b)] += sz[a];
					sl.push({a, root[a]});
					root[a] = -b;
				}
			}
		}
	}
	
 
	for (int i = 1; i <= q; i++)
	{
		if (res[i]) cout<<"YES\n";
		else cout<<"NO\n";
	}
		
	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}

Compilation message

Joker.cpp:28:1: error: '::main' must return 'int'
   28 | int64_t main()
      | ^~~~~~~
Joker.cpp: In function 'int main()':
Joker.cpp:41:6: warning: unused variable 'maks' [-Wunused-variable]
   41 |  int maks = 0;
      |      ^~~~
Joker.cpp:48:6: warning: unused variable 'it' [-Wunused-variable]
   48 |  int it = 0;
      |      ^~