제출 #691271

#제출 시각아이디문제언어결과실행 시간메모리
691271ghostwriterCryptography (NOI20_crypto)C++17
0 / 100
2 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define st first #define nd second #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define ins insert #define ers erase #define lb lower_bound #define ub upper_bound #define bg begin #define ed end #define ft front #define bk back #define sz(x) (int)x.size() #define all(x) (x).bg(), (x).ed() #define mtp make_tuple #define ll long long #define ull unsigned long long #define db double #define ldb long double #define str string #define pi pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vll vector<ll> #define vpi vector<pi> #define vpll vector<pll> #define FOR(i, l, r) for (int i = (l); i <= (r); ++i) #define FOS(i, r, l) for (int i = (r); i >= (l); --i) #define FRN(i, n) for (int i = 0; i < (n); ++i) #define FSN(i, n) for (int i = (n) - 1; i >= 0; --i) #define EACH(i, x) for (auto &i : (x)) #define WHILE while template<typename T> T gcd(T a, T b) { WHILE(b) { a %= b; swap(a, b); } return a; } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } const int M = 1e9 + 7; const int N = 3e5 + 5; int n, p[N], s[N], f[N], f1[N]; int getp(int x) { return lb(s + 1, s + 1 + n, x) - s; } void upd(int pos, int v) { for (int i = pos; i <= n; i += (i & -i)) f[i] += v; } int get(int pos) { int rs = 0; for (int i = pos; i > 0; i -= (i & -i)) rs += f[i]; return rs; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout); cin >> n; FOR(i, 1, n) cin >> p[i]; FOR(i, 1, n) s[i] = p[i]; sort(s + 1, s + 1 + n); int rs = 1; f1[0] = 1; FOR(i, 1, n) f1[i] = 1LL * f1[i - 1] * i % M; FOR(i, 1, n) { int cur = getp(p[i]), sm = cur - 1 - get(cur - 1); (rs += 1LL * sm * f1[n - i] % M) %= M; upd(cur, 1); } cout << rs; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Crypto.cpp: In function 'int main()':
Crypto.cpp:50:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     freopen(file".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Crypto.cpp:51:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     freopen(file".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...