QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#168867 | #5047. Permutation | pooty | RE | 0ms | 3484kb | C++14 | 2.8kb | 2023-09-09 00:43:01 | 2023-09-09 00:43:01 |
Judging History
answer
#ifdef MY_LOCAL
#include "D://competitive_programming/debug/debug.h"
#define debug(x) cerr << "[" << #x<< "]:"<<x<<"\n"
#else
#define debug(x)
#endif
#define REP(i, n) for(int i = 0; i < (n); i ++)
#define REPL(i,m, n) for(int i = (m); i < (n); i ++)
#define SORT(arr) sort(arr.begin(), arr.end())
#define LSOne(S) ((S)&-(S))
#define sz(X) ((int)X.size())
#define READ(arr) for(auto &a: arr){cin>>a;}
#define SUM(arr) accumulate((arr).begin(), (arr).end(), 0LL)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef tree<int,null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;
const ll INF = 1e18;
const int MOD = 998244353;
int solve() {
int n,c;cin>>n>>c;
vi parr(n);
READ(parr);
vi places(n);
REP(i, n) {
parr[i]--;
places[parr[i]] = i;
}
set<int> fixedpoint = {-1, n};
auto ptr_to_left = [&](int idx) {
return *prev(fixedpoint.upper_bound(idx));
};
auto ptr_to_right = [&](int idx) {
return *fixedpoint.upper_bound(idx);
};
map<int, ii> ranges;
auto get_range = [&](int who) {
auto it = ranges.upper_bound(who);
if (it == ranges.begin()) {
return -1LL;
}
it = prev(it);
if ((it->second).first < who) {
return -1LL;
}
return it->first;
};
int ans = 1;
auto add_range = [&](int l, int r) {
//debug("adding");debug(l);debug(r);
int vl = get_range(l);
int vr = get_range(r);
if (vl == -1LL && vr == -1LL) {
//debug("none!");
ranges[l] = {r, 0};return;
}
if (vl == vr) return;
if (vl != -1) {
assert(vr == -1);
auto it = ranges.find(vl);
auto [L, pr] = *it;
auto [R, amt] = pr;
ranges.erase(it);
ranges.insert({L, {r, amt}});
}
if (vr != -1) {
assert(vl == -1);
auto it = ranges.find(vr);
auto [L, pr] = *it;
auto [R, amt] = pr;
ranges.erase(it);
ranges.insert({l, {R, amt}});
}
};
REP(i, n) {
auto idx = places[i];
//debug(idx);debug(ranges);
auto where = get_range(idx);
if (where != -1) {
auto [r, occ] = ranges[where];
int rem = r - where + 1 - occ;
ranges[where].second++;
assert(rem > 0);
ans *= rem;
ans %= MOD;
}
// try to add pt...
int lfixed = ptr_to_left(idx);
if (idx - c > lfixed) {
add_range(idx - c, idx -1);
}
int rfixed = ptr_to_right(idx);
if (idx + c < rfixed) {
add_range(idx + 1, idx + c);
}
if (where == -1) {
fixedpoint.insert(idx);
}
}
return ans;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc;
cin>>tc;
REP(i, tc) {
cout<<solve()<<"\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3484kb
input:
5 5 3 3 4 2 1 5 5 4 4 2 1 3 5 5 2 4 5 3 1 2 5 3 4 3 2 1 5 5 2 2 3 1 5 4
output:
6 1 4 6 4
result:
ok 5 number(s): "6 1 4 6 4"
Test #2:
score: -100
Dangerous Syscalls
input:
100000 5 4 1 3 2 5 4 5 3 5 1 4 2 3 5 2 1 4 5 3 2 5 4 5 2 4 3 1 5 4 2 5 4 1 3 5 4 1 2 3 5 4 5 4 4 3 2 5 1 5 3 1 5 4 3 2 5 3 3 2 5 4 1 5 4 4 3 1 5 2 5 4 4 3 5 2 1 5 2 3 2 1 4 5 5 3 2 4 5 1 3 5 3 2 1 4 3 5 5 3 2 1 5 4 3 5 2 2 1 3 4 5 5 4 2 3 1 4 5 5 2 1 2 4 5 3 5 3 2 4 1 5 3 5 3 2 4 3 5 1 5 3 4 1 3 5 2...