제출 #1102291

#제출 시각아이디문제언어결과실행 시간메모리
1102291kustizusSwap Swap Sort (CCO21_day1problem1)C++17
6 / 25
5066 ms40092 KiB
#pragma GCC optimize("O3","unroll-loops") #include <bits/stdc++.h> using namespace std; // #define int long long #define fi first #define se second #define yes cout << "YES\n" #define no cout << "NO\n" #define all(v) v.begin(),v.end() #define gcd(a, b) __gcd(a, b) #define lcm(a, b) a * b / gcd(a, b) mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}, dy[] = {0, 1, 0, -1, -1, 1, 1, -1}; bool is_square(long long n){long long k = sqrt(n);return k * k == n;} bool is_prime(long long n){if (n <= 3) return n > 1;if (n % 2 == 0 || n % 3 == 0) return false;for (int i = 5; i <= sqrt(n); i += 6)if (n % i == 0 || n % (i + 2) == 0) return false;return true;} long long bin_pow(long long a, long long b, long long MOD){long long ans = 1;if (a >= MOD) a %= MOD;while (b){if (b & 1) ans = ans * a % MOD;a = a * a % MOD;b /= 2;}return ans;} long long bin_mul(long long a, long long b, long long MOD){long long ans = 0;if (a >= MOD) a %= MOD;while (b){if (b & 1) ans = (ans + a) % MOD;a = (a + a) % MOD;b /= 2;}return ans;} // build(n, mod) struct math{int N, MOD;vector <int> gt, rl;void build(int n, int mod){N = n;MOD = mod;gt.resize(N + 5);rl.resize(N + 5);gt[0] = rl[0] = 1;for (int i = 1; i <= N; ++i){gt[i] = 1LL * gt[i - 1] * i % MOD;rl[i] = bin_pow(gt[i], MOD - 2, MOD);}}int C(int a, int b){return 1LL * gt[b] * rl[a] % MOD * rl[b - a] % MOD;}}; //build(mod) struct fibonacci{int MOD;map <long long,int> fibo;void build(int mod){MOD = mod;fibo[1] = fibo[2] = 1;}int fb(long long n){if (fibo.count(n)) return fibo[n];if (n & 1) return fibo[n] = (1LL * fb(n / 2) * fb(n / 2) + 1LL * fb(n / 2 + 1) * fb(n / 2 + 1)) % MOD;return fibo[n] = (1LL * 2 * fb(n / 2 - 1) * fb(n / 2) + 1LL * fb(n / 2) * fb(n / 2)) % MOD;}}; // init(n) struct fenwick_tree{int N;vector <int> FT;void init(int n){N = n;FT.resize(n + 5);}void clear(){for (int i = 1; i <= N; ++i) FT[i] = 0;}void update(int idx, int val){for (; idx <= N; idx += idx & (-idx)) FT[idx] += val;}int get(int idx){int val = 0;for (; idx; idx -= idx & (-idx)) val += FT[idx];return val;}int sum(int l, int r){return get(r) - get(l - 1);}}; const int N = 1e5, Q = 1e6; long long p[Q * 2 + 5]; int n, k, q, a[N + 5], x[N + 5], cnt[N + 5], qry[Q + 5]; vector <pair <int,int>> g[N + 5]; fenwick_tree ft; void Solve() { cin >> n >> k >> q; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= k; ++i) x[i] = i; for (int i = 1; i <= q; ++i) { cin >> qry[i]; int pos = qry[i]; swap(x[pos], x[pos + 1]); g[x[pos]].push_back({x[pos + 1], i * 2 - 1}); g[x[pos + 1]].push_back({x[pos], i * 2}); } long long nt = 0; ft.init(k); for (int i = 1; i <= n; ++i) { ++cnt[a[i]]; ft.update(a[i], 1); nt += i - ft.get(a[i]); for (pair <int,int> j : g[a[i]]) p[j.se] += cnt[j.fi]; } for (int i = 1; i <= q; ++i) { nt += p[i * 2 - 1]; nt -= p[i * 2]; cout << nt << "\n"; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); if (fopen("file.inp", "r")) { freopen ("file.inp", "r", stdin); freopen ("file.out", "w", stdout); } int TEST = 1; // cin >> TEST; while (TEST--) Solve(); cerr << "\nTIME: " << 1000 * clock() / CLOCKS_PER_SEC << "ms."; }

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

Main.cpp: In function 'int main()':
Main.cpp:73:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen ("file.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:74:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         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...