Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #include <ext/pb_ds/assoc_container.hpp> // Common file
- #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
- using namespace __gnu_pbds;
- template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
- #define int long long
- #define vi vector<int>
- #define ii pair<int,int>
- #define fi first
- #define sc second
- #define stoi stoll
- #define popcnt __builtin_popcount
- #define getbit(x, k) ((x >> k) & 1)
- #define all(x) (x).begin(),(x).end()
- #define FOR(i,j,k) for(int i=j; i<k; i++)
- #define look(a) cerr <<#a<<": "<<a<<endl;
- #define look2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
- void solve()
- {
- int n;
- cin >> n;
- int a[n];
- int ans = 0;
- ordered_set<int> s;
- FOR(i,0,n) {
- cin >> a[i];
- ans += s.size() - s.order_of_key(a[i]);
- s.insert(a[i]);
- }
- cout << ans << '\n';
- FOR(i,0,n-1){
- ans -= a[i];
- ans += n - a[i] - 1;
- cout << ans << '\n';
- }
- }
- signed main()
- {
- cin.tie(0)->sync_with_stdio(0);
- freopen("in", "r", stdin);
- freopen("out", "w", stdout);
- int T = 1;
- // cin >> T;
- while (T--) {
- solve();
- cout << '\n';
- }
- cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement