Submission #925991

# Submission time Handle Problem Language Result Execution time Memory
925991 2024-02-12T12:33:08 Z vjudge1 Joker (BOI20_joker) C++17
0 / 100
7 ms 26972 KB
#pragma GCC optimize("O3", "unroll-loops") // "Ofast" 	
#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt") 

#include <bits/stdc++.h>

//#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
#define dbg(x) cerr << #x << " = " << x << '\n'
#define bit(x, i) ((x) >> (i) & 1)

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 1e6 + 5, mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const ld eps = 1e-6;

ll add (ll a, ll b) {
	a += b;
	if (a < 0) a += mod;
	if (a >= mod) a -= mod;
	return a;
}

ll mul (ll a, ll b) {
	a *= b;
	if (a >= mod) a %= mod;
	return a;
}

int n, m, Q;
vt<int> g[N];
int used[N];

struct Data {
	int x, y, id;
}edge[N];

string get (int l, int r) {
    for (int i = 1; i <= n; i++) used[i] = 0, g[i].clear();
	for (int i = 1; i <= m; i++) {
		int x = edge[i].x, y = edge[i].y, id = edge[i].id;
		if (!(id >= l && id <= r)) g[x].pb(y), g[y].pb(x);
	}
	bool ok = 1;
	queue<int> q;
	for (int i = 1; i <= n; i++) {
		if (!used[i]) {
			q.push(i);
			used[i] = 1;
			while (!q.empty()) {
				int v = q.front();
				q.pop();
				for (auto to: g[v]) {
					if (!used[to]) {
						used[to] = 3 - used[v];
						q.push(to);
					}
					else if (used[to] == used[v]) ok = 0;
				}
			}
		}
	}
	return (!ok ? "YES" : "NO");
}

void solve () {
	cin >> n >> m >> Q;
	for (int i = 1; i <= m; i++) {
		int x, y;
		cin >> x >> y;
		edge[i] = {x, y, i};
	}
	string s[m + 1];
	int L = 1, R = m, pos = -1;
	while (L <= R) {
		int mid = L + R >> 1;
		if (get(1, mid - 1) == "YES") pos = mid, L = mid + 1;
		else R = mid - 1;
	}
	for (int i = 1; i <= pos; i++) s[i] = "YES";
	while (Q--) {
		int l, r;
		cin >> l >> r;
		if (l == 1) cout << s[r + 1] << '\n';
		else cout << get(l, r) << '\n';
	}
	cout << '\n';
}

bool testcases = 0;

signed main() {
#ifdef AMIR
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#endif
	cin.tie(0) -> sync_with_stdio(0);
	int test = 1;
	if (testcases) cin >> test;
	for (int cs = 1; cs <= test; cs++) {
		solve();
	}
}

Compilation message

Joker.cpp: In function 'void solve()':
Joker.cpp:84:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   84 |   int mid = L + R >> 1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 26972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 26972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 26972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 26972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 26972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 26972 KB Output isn't correct
2 Halted 0 ms 0 KB -