QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#664209#9477. Topological SortZvezdy#WA 2ms9500kbC++141.4kb2024-10-21 19:37:082024-10-21 19:37:08

Judging History

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

  • [2024-10-21 19:37:08]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9500kb
  • [2024-10-21 19:37:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 2e5 + 10;
vector<int> e[maxn];
const int inf = 1e18;
int idx = 1;
int a[maxn];
const int mod = 998244353;
int ksm(int a, int b) {
    if (b < 0) return 1;
    int ans = 1;
    while (b) {
        if (b & 1) {
            ans = ans * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<int> v[2];
    int ans = 1;
    for (int i = 1; i <= n; i++) {
        if (i == 1 || a[i] < a[i - 1]) {
            v[0].push_back(a[i]);
            ans = ans * ksm(2, (i - 2)) % mod;
        } else {
            if (a[i] > v[0][0]) {
                ans = ans * ksm(2, (i - 1)) % mod;
            } else {
                reverse(v[0].begin(), v[0].end());
                int p = upper_bound(v[0].begin(), v[0].end(), a[i]) - v[0].begin();
                ans = ans * ((ksm(2, (p + 1)) % mod - 1 + mod) % mod) % mod;
                int les = v[0].size();
                les -= (p + 1);
                ans = ans * (ksm(2, les)) % mod;
                v[0].clear();
                v[0].push_back(a[i]);
            }
        }
    }
    cout << ans << '\n';
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 8852kb

input:

3
1 3 2

output:

4

result:

ok "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 8892kb

input:

5
1 2 3 4 5

output:

1024

result:

ok "1024"

Test #3:

score: 0
Accepted
time: 2ms
memory: 9500kb

input:

6
4 2 1 5 6 3

output:

4096

result:

ok "4096"

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 8876kb

input:

492
397 486 227 395 58 452 172 216 130 181 268 482 85 209 365 104 373 90 260 326 252 96 267 106 102 398 441 41 292 314 12 78 242 353 153 424 179 86 299 228 54 390 73 465 396 349 4 10 451 99 342 250 391 6 323 197 159 47 136 473 392 77 125 362 418 255 291 13 238 339 8 28 413 121 384 157 152 23 221 305...

output:

614446818

result:

wrong answer 1st words differ - expected: '73428942', found: '614446818'