QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#759089 | #9738. Make It Divisible | False0099 | Compile Error | / | / | C++20 | 4.1kb | 2024-11-17 21:34:23 | 2024-11-17 21:34:24 |
Judging History
你现在查看的是最新测评结果
- [2024-11-27 18:44:44]
- hack成功,自动添加数据
- (/hack/1263)
- [2024-11-17 21:34:24]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2024-11-17 21:34:23]
- 提交
answer
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
int INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
typedef pair<int, int> PII;
void init() {}
const int N = 1e5 + 10;
int a[N];
class SegmentTree
{
public:
struct Node
{
int l, r;
int sum;
} tr[N << 2];
Node merge(Node x, Node y)
{
if (x.l == -1)
return y;
if (y.l == -1)
return x;
Node z;
z.l = min(x.l, y.l);
z.r = max(x.r, y.r);
z.sum = __gcd(x.sum, y.sum);
return z;
}
void pushup(int u)
{
tr[u] = merge(tr[u << 1], tr[u << 1 | 1]);
}
void build(int u, int l, int r)
{
tr[u] = {l, r, 0};
if (l == r)
return;
int mid = l + r >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
pushup(u);
}
void update(int u, int p, int x)
{
if (tr[u].l == tr[u].r)
{
tr[u].sum = x;
return;
}
int mid = tr[u].l + tr[u].r >> 1;
if (p <= mid)
update(u << 1, p, x);
else
update(u << 1 | 1, p, x);
pushup(u);
}
Node query(int u, int l, int r)
{
if (tr[u].l >= l && tr[u].r <= r)
return tr[u];
int mid = tr[u].l + tr[u].r >> 1;
Node ret;
ret.l = -1;
if (l <= mid)
ret = query(u << 1, l, r);
if (r > mid)
ret = merge(ret, query(u << 1 | 1, l, r));
return ret;
}
} t;
void solve()
{
int n, l;
cin >> n >> l;
vector<int> d(n + 1);
int global_gcd = 0;
int min_value = INF;
t.build(1, 1, n);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
min_value = min(min_value, a[i]);
d[i] = abs(a[i] - a[i - 1]);
t.update(1, i, d[i]);
if (i != 1)
global_gcd = __gcd(global_gcd, d[i]);
}
vector<int> left_bound(n + 1);
vector<int> right_bound(n + 1);
stack<int> stk, stk2;
for (int i = 1; i <= n; i++)
{
while (!stk.empty() && a[stk.top()] >= a[i])
stk.pop();
left_bound[i] = stk.empty() ? 1 : stk.top() + 1;
stk.push(i);
}
for (int i = n; i >= 1; i--)
{
while (!stk2.empty() && a[stk2.top()] >= a[i])
stk2.pop();
right_bound[i] = stk2.empty() ? n : stk2.top() - 1;
stk2.push(i);
}
unorderes_set<int> valid_k;
if (global_gcd == 0)
{
cout << l << " " << (1 + l) * l / 2 << endl;
return;
}
int sum = 0;
for (int i = 1; i * i <= global_gcd; i++)
{
if (global_gcd % i == 0)
{
int u = i;
int k = u - min_value;
if (k > 0 && k <= l && __gcd(a[1] + k, global_gcd) == u)
{
valid_k.insert(k);
sum += k;
}
int v = global_gcd / i;
k = v - min_value;
if (k > 0 && k <= l && __gcd(a[1] + k, global_gcd) == v)
{
valid_k.insert(k);
sum += k;
}
}
}
for (int i = 1; i <= n; i++)
{
if (left_bound[i] != right_bound[i])
{
int ggcd = t.query(1, left_bound[i] + 1, right_bound[i]).sum;
int max_left = a[left_bound[i]];
int min_num = a[i];
unordered_set<int> new_valid_k = valid_k;
for (auto k : valid_k)
{
if (__gcd(ggcd, max_left + k) != min_num + k)
{
new_valid_k.erase(k);
}
}
valid_k = new_valid_k;
}
}
cout << valid_k.size() << " ";
int total_sum = 0;
for (auto k : valid_k)
total_sum += k;
cout << total_sum << endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0);
int t = 1;
cin >> t;
init();
while (t--)
solve();
}
Details
answer.code: In function ‘void solve()’: answer.code:120:5: error: ‘unorderes_set’ was not declared in this scope 120 | unorderes_set<int> valid_k; | ^~~~~~~~~~~~~ answer.code:2:13: error: expected primary-expression before ‘long’ 2 | #define int long long | ^~~~ answer.code:120:19: note: in expansion of macro ‘int’ 120 | unorderes_set<int> valid_k; | ^~~ answer.code:136:17: error: ‘valid_k’ was not declared in this scope 136 | valid_k.insert(k); | ^~~~~~~ answer.code:143:17: error: ‘valid_k’ was not declared in this scope 143 | valid_k.insert(k); | ^~~~~~~ answer.code:156:46: error: ‘valid_k’ was not declared in this scope; did you mean ‘new_valid_k’? 156 | unordered_set<int> new_valid_k = valid_k; | ^~~~~~~ | new_valid_k answer.code:168:13: error: ‘valid_k’ was not declared in this scope 168 | cout << valid_k.size() << " "; | ^~~~~~~