Submission #948840

#TimeUsernameProblemLanguageResultExecution timeMemory
948840Nhoksocqt1Permutation (APIO22_perm)C++17
10 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define sz(x) int((x).size()) #define fi first #define se second typedef long long ll; typedef pair<int, int> ii; template<class X, class Y> inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);} template<class X, class Y> inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int Random(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } const int MAXN = 6003; vector<int> construct_permutation(ll k) { if(k <= 90) { vector<int> p; for (int i = k - 2; i >= 0; --i) p.push_back(i); return p; } return {1}; } #ifdef Nhoksocqt1 ll fen[MAXN]; int nTree; void modify(int i, ll v) { for (++i; i <= nTree; i += i & -i) fen[i] += v; } ll get(int i) { ll res(0); for (++i; i > 0; i -= i & -i) res += fen[i]; return res; } int main(void) { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define TASK "perm" if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } ll k; cin >> k; vector<int> a = construct_permutation(k); cout << "ANSWER PERM: "; for (int it = 0; it < sz(a); ++it) cout << a[it] << ' '; cout << '\n'; ll res(1); nTree = sz(a) + 1; for (int it = 0; it < sz(a); ++it) { ll way = 1 + get(a[it]); modify(a[it], way); res += way; } cout << "NUM WAY: " << res << '\n'; return 0; } #endif // Nhoksocqt1
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...