QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#673439#9353. Interesting PermutationShirasuAzusaCompile Error//C++201.5kb2024-10-24 22:23:022024-10-24 22:23:02

Judging History

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

  • [2024-10-24 22:23:02]
  • 评测
  • [2024-10-24 22:23:02]
  • 提交

answer

#include <bits/stdc++.h>

#define endl "\n"
#define int long long
using namespace std;

typedef pair<int, int> PII;
const int N = 2e5 + 5, MOD = 1e9 + 7;
int n;
int a[N];

int fac[N], inv[N];

int ksm(int a, int b) {
    int r = 1;
    while (b) {
        if (b & 1) r = r * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return r;
}

void init() {
    fac[0] = 1;
    for (int i = 1;i < N;i++) {
        fac[i] = fac[i - 1] * i % MOD;
    }
    inv[N - 1] = ksm(fac[N - 1], MOD - 2);
    for (int i = N - 2; i >= 0; i--) {
        inv[i] = inv[i + 1] * (i + 1) % MOD;
    }
}
int C(int n, int m) {
    if (m > n) return 0;
    if (m == 0) return 1;
    return fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}

int A(int n, int m) {
    if (m > n) return 0;
    if (m == 0) return 1;
    return fac[n] * inv[n - m] % MOD;
}

void solve() {
    cin >> n;
    bool ok = 1;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i - 1] > a[i] || a[i] >= n) ok = 0;
    }
    if (!ok) {
        cout << 0 << endl;
        continue;
    }
    ll ans = 1, sum = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] > a[i - 1]) {
            ans = ans * 2 % MOD;
            sum += a[i] - a[i - 1] - 1;
        }
        else {
            ans = ans * sum % MOD;
            sum--;
        }
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    init();
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
}




詳細信息

answer.code: In function ‘void solve()’:
answer.code:55:9: error: continue statement not within a loop
   55 |         continue;
      |         ^~~~~~~~
answer.code:57:5: error: ‘ll’ was not declared in this scope
   57 |     ll ans = 1, sum = 0;
      |     ^~
answer.code:60:13: error: ‘ans’ was not declared in this scope; did you mean ‘abs’?
   60 |             ans = ans * 2 % MOD;
      |             ^~~
      |             abs
answer.code:61:13: error: ‘sum’ was not declared in this scope
   61 |             sum += a[i] - a[i - 1] - 1;
      |             ^~~
answer.code:64:13: error: ‘ans’ was not declared in this scope; did you mean ‘abs’?
   64 |             ans = ans * sum % MOD;
      |             ^~~
      |             abs
answer.code:64:25: error: ‘sum’ was not declared in this scope
   64 |             ans = ans * sum % MOD;
      |                         ^~~
answer.code:68:13: error: ‘ans’ was not declared in this scope; did you mean ‘abs’?
   68 |     cout << ans << endl;
      |             ^~~
      |             abs