提出 #70800133
ソースコード 拡げる
/*
Compete against Yourself.
Author - Aryan (@aryanc403)
*/
/*
Credits -
Atcoder library - https://atcoder.github.io/ac-library/production/document_en/ (namespace atcoder)
Github source code of library - https://github.com/atcoder/ac-library/tree/master/atcoder
https://codeforces.com/contest/4/submission/150120627
*/
#include <bits/stdc++.h>
#include <atcoder/modint>
#include <atcoder/fenwicktree>
using mint = atcoder::modint998244353;
//using mint = atcoder::modint1000000007;
using vm = std::vector<mint>;
std::ostream& operator << (std::ostream& out, const mint& rhs) {
return out<<rhs.val();
}
#ifdef ARYANC403
#include <header.h>
#else
#pragma GCC optimize ("Ofast")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC target ("sse,sse2,mmx")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define dbg(args...) 42;
#define endl "\n"
#endif
// y_combinator from @neal template https://codeforces.com/contest/1553/submission/123849801
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
template<class Fun> class y_combinator_result {
Fun fun_;
public:
template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }
using namespace std;
#define fo(i,n) for(i=0;i<(n);++i)
#define repA(i,j,n) for(i=(j);i<=(n);++i)
#define repD(i,j,n) for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define eb emplace_back
#define X first
#define Y second
using lli = long long int;
using mytype = long double;
using ii = pair<lli,lli>;
using vii = vector<ii>;
using vi = vector<lli>;
template <class T>
using ordered_set = __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
// X.find_by_order(k) return kth element. 0 indexed.
// X.order_of_key(k) returns count of elements strictly less than k.
// namespace Re = std::ranges;
// namespace Ve = std::ranges::views;
const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
cerr<<"Time Taken : "<<diff.count()<<"\n";
}
const lli INF = 0xFFFFFFFFFFFFFFFLL;
const lli SEED=chrono::steady_clock::now().time_since_epoch().count();
mt19937_64 rng(SEED);
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}
class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{ return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y )); }};
void add( map<lli,lli> &m, lli x,lli cnt=1)
{
auto jt=m.find(x);
if(jt==m.end()) m.insert({x,cnt});
else jt->Y+=cnt;
}
void del( map<lli,lli> &m, lli x,lli cnt=1)
{
auto jt=m.find(x);
if(jt->Y<=cnt) m.erase(jt);
else jt->Y-=cnt;
}
bool cmp(const ii &a,const ii &b)
{
return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}
const lli MX = 1000000+5;
int main(void) {
ios_base::sync_with_stdio(false);cin.tie(NULL);
// freopen("txt.in", "r", stdin);
// freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// Ve::iota(1, 6) | Ve::transform([](int x) { return x * 2; }) | Ve::reverse | Ve::take(3)
lli T=1;
// cin>>T;
while(T--)
{
lli n,d;
cin>>n>>d;
atcoder::fenwick_tree<lli> fw(MX);
vi a(n);
for(auto &x:a)
cin>>x;
sort(all(a));
mint ans = 1;
for(const auto &x:a){
const lli l=max(0LL,x-d),r=x+1;
fw.add(x,1);
const lli c=fw.sum(l,r);
ans*=c;
ans/=fw.sum(x,x+1);
}
cout<<ans<<endl;
} aryanc403();
return 0;
}
提出情報
| 提出日時 |
|
| 問題 |
F - Almost Sorted 2 |
| ユーザ |
aryanc403 |
| 言語 |
C++23 (GCC 15.2.0) |
| 得点 |
500 |
| コード長 |
4241 Byte |
| 結果 |
AC |
| 実行時間 |
55 ms |
| メモリ |
12936 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
500 / 500 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
5 ms |
11148 KiB |
| 00_sample_01.txt |
AC |
5 ms |
11272 KiB |
| 00_sample_02.txt |
AC |
4 ms |
11148 KiB |
| 01_test_00.txt |
AC |
39 ms |
12352 KiB |
| 01_test_01.txt |
AC |
38 ms |
12256 KiB |
| 01_test_02.txt |
AC |
34 ms |
12172 KiB |
| 01_test_03.txt |
AC |
44 ms |
12428 KiB |
| 01_test_04.txt |
AC |
54 ms |
12776 KiB |
| 01_test_05.txt |
AC |
37 ms |
12296 KiB |
| 01_test_06.txt |
AC |
47 ms |
12680 KiB |
| 01_test_07.txt |
AC |
53 ms |
12860 KiB |
| 01_test_08.txt |
AC |
48 ms |
12628 KiB |
| 01_test_09.txt |
AC |
47 ms |
12520 KiB |
| 01_test_10.txt |
AC |
46 ms |
12804 KiB |
| 01_test_11.txt |
AC |
55 ms |
12768 KiB |
| 01_test_12.txt |
AC |
50 ms |
12880 KiB |
| 01_test_13.txt |
AC |
52 ms |
12824 KiB |
| 01_test_14.txt |
AC |
37 ms |
12936 KiB |
| 01_test_15.txt |
AC |
37 ms |
12880 KiB |
| 01_test_16.txt |
AC |
52 ms |
12776 KiB |
| 01_test_17.txt |
AC |
49 ms |
12896 KiB |
| 01_test_18.txt |
AC |
5 ms |
11112 KiB |
| 01_test_19.txt |
AC |
49 ms |
12924 KiB |
| 01_test_20.txt |
AC |
52 ms |
12768 KiB |
| 01_test_21.txt |
AC |
51 ms |
12904 KiB |
| 01_test_22.txt |
AC |
52 ms |
12880 KiB |
| 01_test_23.txt |
AC |
51 ms |
12768 KiB |
| 01_test_24.txt |
AC |
49 ms |
12936 KiB |
| 01_test_25.txt |
AC |
50 ms |
12812 KiB |
| 01_test_26.txt |
AC |
49 ms |
12936 KiB |
| 01_test_27.txt |
AC |
50 ms |
12896 KiB |
| 01_test_28.txt |
AC |
49 ms |
12936 KiB |
| 01_test_29.txt |
AC |
39 ms |
12768 KiB |
| 01_test_30.txt |
AC |
41 ms |
12860 KiB |
| 01_test_31.txt |
AC |
44 ms |
12880 KiB |
| 01_test_32.txt |
AC |
47 ms |
12884 KiB |
| 01_test_33.txt |
AC |
54 ms |
12904 KiB |