QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#744828#9738. Make It Divisiblecurtain_cppWA 0ms3816kbC++235.5kb2024-11-13 23:42:352024-11-13 23:42:35

Judging History

你现在查看的是最新测评结果

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-14 09:10:13]
  • hack成功,自动添加数据
  • (/hack/1178)
  • [2024-11-13 23:42:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3816kb
  • [2024-11-13 23:42:35]
  • 提交

answer

//Not all efforts result in success, but giving up is sure to result in failure.
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <numeric>
#include <bitset>
#include <functional>
#include <iomanip>
#include <cassert>
using namespace std;
typedef long long  LL;
typedef unsigned long long uLL;
typedef pair<LL,LL> PII;
//typedef tuple<LL,LL,LL> tup;
#define make_pair() mk
#define int long long
const int N = 5e4+5;
const double pi = acos(-1);
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3fLL;
#define debug(x) cout<<"[debug]"#x<<"="<<x<<'\n';
#define pdebug(a,b) cout<<(#a)<<':'<<a<<' '<<(#b)<<':'<<b<<'\n'
#define tdebug(a,b,c) cout<<(#a)<<':'<<a<<' '<<(#b)<<':'<<b<<' '<<(#c)<<':'<<c<<'\n'
#define videbug(a) cout<<(#a)<<':';for(int i=0;i<a.size();i++)cout<<' '<<a[i];cout<<'\n';
//   Make bold hypotheses and verify carefully
// - You REALLY need some key observations...
// - Don't trust seemaxgly trival conclusions
// - Do something instead of nothing and stay organized
// - Don't get stuck on one approach
// - Formalization is the death of intuition
template <int T>
struct ModInt {
    const static int MD = T;
    int x;
    ModInt(LL x = 0)
        : x(x % MD) {}
    int get() { return x; }
    ModInt operator+(const ModInt& that) const {
        int x0 = x + that.x;
        return ModInt(x0 < MD ? x0 : x0 - MD);
    }
    ModInt operator-(const ModInt& that) const {
        int x0 = x - that.x;
        return ModInt(x0 < MD ? x0 + MD : x0);
    }
    ModInt operator*(const ModInt& that) const {
        return ModInt((long long)x * that.x % MD);
    }
    ModInt operator/(const ModInt& that) const {
        return *this * that.inverse();
    }
    void operator+=(const ModInt& that) {
        x += that.x;
        if (x >= MD)
            x -= MD;
    }
    void operator-=(const ModInt& that) {
        x -= that.x;
        if (x < 0)
            x += MD;
    }
    void operator*=(const ModInt& that) { x = (long long)x * that.x % MD; }
    void operator/=(const ModInt& that) { *this = *this / that; }
    ModInt inverse() const {
        int a = x, b = MD, u = 1, v = 0;
        while (b) {
            int t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        if (u < 0)
            u += MD;
        return u;
    }
    friend ostream& operator<<(ostream& os, ModInt x) {
        os << x.get();
        return os;
    }
};
const int mod=998244353;
typedef ModInt<mod> mint;
const LL mod1=2147483648;
LL gcd(LL a, LL b)
{
   return b ? gcd(b, a % b) : a;
}
inline __int128 read() {
    __int128 x = 0, f = 1; char ch = getchar();
    while (ch > '9' || ch < '0') { if (ch == '-')f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
inline void write(__int128 x) {
    if (x < 0) { putchar('-'); x = -x; }
    if (x > 9)write(x / 10);
    putchar(x % 10 + '0');
}
const int INF = 1e9;
int a[N];
int stk[N];
void solve() {
    int n, k; cin >> n >> k;
    int top = 1;
    vector< int > ls(n + 1, 0);
    vector< int > rs(n + 1, 0);
    stk[1] = 1;
    int Mn = INF;
    int Mx = 0;
    int root = -1;
    for(int i = 1; i <= n; i++) {
        int x; cin >> x; a[i] = x;
        if(Mn > x) {
            Mn = x;
            root = i;
        }
        Mx = max(Mx, x);
    }
    if(n == 1 || Mx == Mn) {
        cout << k << ' ' << 1LL * k * (k + 1) / 2 << '\n';
        return;
    }

    for(int i = 2; i <= n; i++) {
        while(a[stk[top]] > a[i] && top) top--;
        if(!top) ls[i] = stk[top + 1];
        else ls[i] = rs[stk[top]], rs[stk[top]] = i;
        stk[++top] = i;
    }
    int o = 0;
    for(int i = 1; i <= n; i++) {
        o = gcd(o, a[i] - Mn);
    }
    vector< int > vec;
    for(int i = 1; i * i <= o; i++) {
        if(o % i == 0) {
            int c = i;
            if(c - Mn > 0 && c - Mn <= k) {
                vec.push_back(c - Mn);
            }
            if(i * i == o) continue;
            c = o / i;
            if(c - Mn > 0 && c - Mn <= k) {
                vec.push_back(c - Mn);
            }
        }
    }

    auto check = [&](int x) -> bool {
        int ok = 1;
        /*
       function<void(int)>dfs = [&](int x)-> void{
            if(ls[x]) {
                if(a[ls[x]] % a[x] != 0) {
                    ok = 0;
                }
                dfs(ls[x]);
            }
            if(rs[x]) {
                if(a[rs[x]] % a[x] != 0) {
                    ok = 0;
                }
                dfs(rs[x]);
            }
        };
        dfs(root);
        */
        for(int i=1;i<=n;i++){
             if((a[i]%(x+Mn))!=0) {
                 ok=0;
                 break;
             }
        }
        return ok;
    };
    int ansl = 0, ansr = 0;
    for(auto item : vec) {
        for(int i = 1; i <= n; i++) {
            a[i] += item;
        }
        if(check(item)) {
            ansl++;
            ansr += item;
        }
        for(int i = 1; i <= n; i++) {
            a[i] -= item;
        }
    }
    cout << ansl << ' ' << ansr << '\n';
}
signed main()
{
  ios::sync_with_stdio(0); cin.tie(0),cout.tie(0);
  int t;t=1;
  cin>>t;
  while(t--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3816kb

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: -100
Wrong Answer
time: 0ms
memory: 3604kb

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
1 1
0 0
0 0

result:

wrong answer 2nd lines differ - expected: '0 0', found: '1 1'