This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int maxa = 5e6 + 1;
int a[maxn][2];
int d[maxa];
int vis[maxn];
int vis1[maxa];
int n;
long long suma[maxa];
vector<int> valid;
vector<int> ba[maxa];
int T;
long long get(long long x) {
if (vis1[x] == T) return 0;
vis1[x] = T;
long long sum = 0;
for (int id : ba[x]) {
if (vis[id] < T) {
vis[id] = T;
sum += a[id][0];
}
}
return sum;
}
bool check(long long l, long long r) {
for (int i=0; i<n; ++i) {
if (vis[i] == T) continue;
vis[i] = T;
if (r < l) swap(l, r);
if (l < 0) return 0;
if (a[i][0] == r) {
l -= a[i][1];
} else if (a[i][0] == l) {
r -= a[i][1];
} else if (a[i][1] == l) {
r -= a[i][0];
} else {
if (l < a[i][1] || r < a[i][0]) return 0;
long long er = r - a[i][0];
if (l >= maxa) return 0;
if (suma[l] + a[i][0] + a[i+1][0] < r) return 0;
long long len = get(l);
if (len > er) return 0;
if (len < er) {
if (l < er - len) return 0;
int need_id = d[l];
if (need_id == -1) return 0;
if (a[need_id][1] != er - len) return 0;
if (vis[need_id] == T) return 0;
vis[need_id] = T;
}
l -= a[i][1];
r = a[i][0];
}
}
if (r < 0 || l < 0) return 0;
return l == 0 || r == 0;
}
void solve(long long area) {
for (int i = 1; i*1ll*i <= area; ++i) {
if (i >= maxa) continue;
if (area % i) continue;
if (suma[i] + 2 * a[0][0] < area / i) continue;
T++;
if (check(i, area / i)) {
valid.push_back(i);
}
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin>>n;
long long area = 0;
memset(d, -1, sizeof d);
for (int i=0; i<n; ++i) {
cin>>a[n-i-1][0]>>a[n-i-1][1];
}
d[0] = n;
for (int i=0; i<n; ++i) {
d[a[i][0]] = i;
ba[a[i][1]].push_back(i);
suma[a[i][1]] += a[i][0];
area += a[i][0]*1ll*a[i][1];
}
solve(area);
cout << valid.size() << '\n';
for (auto e : valid) {
cout << e << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |