Submission #538555

#TimeUsernameProblemLanguageResultExecution timeMemory
538555Killer2501Pictionary (COCI18_pictionary)C++14
140 / 140
222 ms22788 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define pll pair<ll, ll> #define pii pair<int, int> #define fi first #define se second using namespace std; const int N = 2e5+5; const int M = 5e3+5; const int mod = 1e9+7; const ll base = 75; const int inf = 1e9+7; int t, a[N], b[N], ans, lab[N], q; int n, m, k, l[N], r[N]; vector<int> adj[N], g[N]; string s; ll pw(ll k, ll n) { ll total =1 ; for(; n; n >>= 1) { if(n&1)total = total * k % mod; k = k * k % mod; } return total; } struct IT { int n; vector<int> st; IT(){} void init(int _n) { n = _n; st.assign(n*4+4, 0); } void build(int id, int l, int r, int pos, int x) { if(l == r) { st[id] = x; return; } int mid = (l+r)>>1; if(pos <= mid)build(id<<1, l, mid, pos, x); else build(id<<1|1, mid+1, r, pos, x); st[id] = (st[id<<1|1] + st[id<<1]) % mod; } void build(int pos, int x) { build(1, 1, n, pos, x); } int get(int id, int l, int r, int u, int v) { if(u <= l && r <= v)return st[id]; if(u > r || l > v)return 0; int mid = (l+r)>>1; return (get(id<<1, l, mid, u, v) + get(id<<1|1, mid+1, r, u ,v)) % mod; } int get(int l, int r) { return get(1, 1, n, l, r); } }it; int findp(int u) { return lab[u] < 0 ? u : lab[u] = findp(lab[u]); } bool hop(int u, int v) { u = findp(u); v = findp(v); if(u == v)return false; if(lab[u] > lab[v])swap(u, v); lab[u] += lab[v]; lab[v] = u; return true; } void sol() { cin >> n >> m >> q; for(int i = 1; i <= q; i ++) { cin >> a[i] >> b[i]; l[i] = 1; r[i] = m; } bool ok = true; while(ok) { ok = false; for(int i = 1; i <= q; i ++) { if(l[i] <= r[i]) { ok = true; adj[(l[i]+r[i])>>1].pb(i); } } fill_n(lab, n+1, -1); for(int i = m; i > 0; i --) { for(int j = i*2; j <= n; j += i)hop(i, j); for(int j: adj[i]) { if(findp(a[j]) == findp(b[j]))l[j] = i+1; else r[j] = i-1; } adj[i].clear(); } } for(int i = 1; i <= q; i ++)cout << m-r[i]+1 << '\n'; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); #define task "test" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int test = 1; //cin >> test; while(test -- > 0)sol(); return 0; }

Compilation message (stderr)

pictionary.cpp: In function 'int main()':
pictionary.cpp:125:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  125 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pictionary.cpp:126:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  126 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...