QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#751700 | #9738. Make It Divisible | yeVegeTable | WA | 0ms | 3812kb | C++20 | 4.6kb | 2024-11-15 20:12:28 | 2024-11-15 20:12:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
typedef pair<ll, ll> P;
#define x first
#define y second
#define int long long
const int mod = 1e9 + 7;
const int pp = 998244353;
const int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1}, dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const int ddx[8] = {1, 1, 2, 2, -1, -1, -2, -2}, ddy[8] = {2, -2, 1, -1, 2, -2, 1, -1};
ll ksm(ll a, ll b, ll p) {
ll ans = 1;
a %= p;
while(b) {
if(b & 1) ans = (ans * a) % p;
b >>= 1;
a = (a * a) % p;
}
return ans % p;
}
std::mt19937 rng; // 随机数生成器
int rand(int l, int r) {
std::uniform_int_distribution<int> distribution(l, r);
return distribution(rng);
}
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n + 2);
int idx = -1;
for(int i = 1; i <= n; i++) {
cin >> a[i];
if(i > 1 && a[i] != a[i - 1]) {
idx = i;
}
}
if(n == 1 || idx == -1) {
cout << k << " " << k * (k + 1) / 2 << endl;
return ;
}
vector<int> s1, s2;
vector<int> L(n + 1, -1), L2(n + 1, -1);
for(int i = 1; i <= n; i++) {
while(s1.size() && a[s1.back()] <= a[i]) {
s1.pop_back();
}
while(s2.size() && a[s2.back()] >= a[i]) {
s2.pop_back();
}
if(s1.size()) {
L[i] = s1.back();
}
if(s2.size()) {
L2[i] = s2.back();
}
s1.emplace_back(i);
s2.emplace_back(i);
}
s1.clear();
s2.clear();
vector<int> R(n + 1, -1), R2(n + 1, -1);
for(int i = n; i > 0; i--) {
while(s1.size() && a[s1.back()] <= a[i]) {
s1.pop_back();
}
while(s2.size() && a[s2.back()] >= a[i]) {
s2.pop_back();
}
if(s1.size()) {
R[i] = s1.back();
}
if(s2.size()) {
R2[i] = s2.back();
}
s1.emplace_back(i);
s2.emplace_back(i);
}
int A = a[1], B = a[R[1]], C = B - A;
if(R[1] == -1) {
A = a[R2[1]];
B = a[1];
C = B - A;
}
// (B + x) = k * (A + x) -> B = k*A + (k-1)*x -> B - A = (A + x) * (k - 1)
set<int> st;
for(int i = 1; i * i <= C; i++) {
if(C % i) continue;
int f1 = i, f2 = C / i;
for(auto & j : {f1, f2}) {
if(j > A && j - A <= k) {
st.emplace(j - A);
}
}
}
int m = st.size();
vector<int> v;
for(auto & x : st) {
v.emplace_back(x);
}
vector<int> vis(m);
for(int i = 1; i <= n; i++) {
for(auto & j : {L[i], R[i]}) {
if(j == -1) continue;
for(int u = 0; u < m; u++) {
if(vis[u]) continue;
if((a[j] + v[u]) % (a[i] + v[u])) {
vis[u] = 1;
}
}
}
for(auto & j : {L2[i], R2[i]}) {
if(j == -1) continue;
for(int u = 0; u < m; u++) {
if(vis[u]) continue;
if((a[i] + v[u]) % (a[j] + v[u])) {
// cerr << "i : " << i << ", j : " << j << ", v : " << v[u] << endl;
vis[u] = 1;
}
}
}
if(L[i] != -1 && R[i] != -1) {
int X = a[L[i]], Y = a[R[i]];
if(X < Y) swap(X, Y);
// cerr << "X : " << X << ", Y : " << Y << endl;
for(int u = 0; u < m; u++) {
if(vis[u]) continue;
if((X + v[u]) % (Y + v[u])) {
vis[u] = 1;
}
}
}
if(L2[i] != -1 && R2[i] != -1) {
int X = a[L2[i]], Y = a[R2[i]];
if(X < Y) swap(X, Y);
// cerr << "X : " << X << ", Y : " << Y << endl;
for(int u = 0; u < m; u++) {
if(vis[u]) continue;
if((X + v[u]) % (Y + v[u])) {
vis[u] = 1;
}
}
}
}
int cnt = 0, sum = 0;
for(int i = 0; i < m; i++) {
if(vis[i]) continue;
// cerr << v[i] << " ";
cnt ++ ;
sum += v[i];
}
cout << cnt << " " << sum << endl;
}
/*
*/
signed main () {
// init(minp, primes, m); // primes
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
// init();
int _ = 1;
cin >> _;
while(_ -- ) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
3 5 10 7 79 1 7 1 2 1000000000 1 2 1 100 1000000000
output:
3 8 0 0 100 5050
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
4 201 1000000000 1 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5...
output:
0 0 0 0 0 0 0 0
result:
ok 4 lines
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3812kb
input:
500 4 1000000000 8 14 24 18 4 1000000000 17 10 18 14 4 1000000000 6 17 19 19 4 1000000000 15 14 15 25 4 1000000000 16 16 5 25 4 1000000000 4 30 20 5 4 1000000000 11 4 23 9 4 1000000000 14 25 13 2 4 1000000000 18 18 1 15 4 1000000000 22 22 22 28 4 1000000000 15 17 17 10 4 1000000000 22 14 13 25 4 100...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 178th lines differ - expected: '1 2', found: '0 0'